-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Expand file tree
/
Copy pathBitbucketOAuth2Client.cs
More file actions
56 lines (48 loc) · 2.06 KB
/
BitbucketOAuth2Client.cs
File metadata and controls
56 lines (48 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Text.Json.Serialization;
using System.Threading;
using System.Threading.Tasks;
using GitCredentialManager;
using GitCredentialManager.Authentication.OAuth;
namespace Atlassian.Bitbucket
{
public abstract class BitbucketOAuth2Client : OAuth2Client
{
public BitbucketOAuth2Client(HttpClient httpClient,
OAuth2ServerEndpoints endpoints,
string clientId,
Uri redirectUri,
string clientSecret,
ITrace2 trace2) : base(httpClient, endpoints, clientId, trace2, redirectUri, clientSecret, false)
{
}
public abstract IEnumerable<string> Scopes { get; }
public string GetRefreshTokenServiceName(InputArguments input)
{
Uri baseUri = input.GetRemoteUri(includeUser: false);
// The refresh token key never includes the path component.
// Instead we use the path component to specify this is the "refresh_token".
Uri uri = new UriBuilder(baseUri) { Path = "/refresh_token" }.Uri;
return uri.AbsoluteUri.TrimEnd('/');
}
public Task<OAuth2AuthorizationCodeResult> GetAuthorizationCodeAsync(IOAuth2WebBrowser browser, CancellationToken ct)
{
return this.GetAuthorizationCodeAsync(Scopes, browser, ct);
}
protected override bool TryCreateTokenEndpointResult(string json, out OAuth2TokenResult result)
{
// We override the token endpoint response parsing because the Bitbucket authority returns
// the non-standard 'scopes' property for the list of scopes, rather than the (optional)
// 'scope' (note the singular vs plural) property as outlined in the standard.
if (TryDeserializeJson(json, BitbucketJsonSerializerContext.Default, out BitbucketTokenEndpointResponseJson jsonObj))
{
result = jsonObj.ToResult();
return true;
}
result = null;
return false;
}
}
}