1
1
// Copyright (c) Microsoft Corporation. All rights reserved.
2
2
// Licensed under the MIT license.
3
+ using System ;
3
4
using System . Net . Http ;
5
+ using Microsoft . Git . CredentialManager ;
4
6
using Microsoft . Git . CredentialManager . Authentication . OAuth ;
5
7
using Microsoft . Git . CredentialManager . Authentication . OAuth . Json ;
6
8
using Newtonsoft . Json ;
@@ -13,14 +15,54 @@ public class BitbucketOAuth2Client : OAuth2Client
13
15
BitbucketConstants . OAuth2AuthorizationEndpoint ,
14
16
BitbucketConstants . OAuth2TokenEndpoint ) ;
15
17
16
- public BitbucketOAuth2Client ( HttpClient httpClient )
18
+ public BitbucketOAuth2Client ( HttpClient httpClient , ISettings settings )
17
19
: base ( httpClient , Endpoints ,
18
- BitbucketConstants . OAuth2ClientId ,
19
- BitbucketConstants . OAuth2RedirectUri ,
20
- BitbucketConstants . OAuth2ClientSecret )
20
+ GetClientId ( settings ) , GetRedirectUri ( settings ) , GetClientSecret ( settings ) )
21
21
{
22
22
}
23
23
24
+ private static string GetClientId ( ISettings settings )
25
+ {
26
+ // Check for developer override value
27
+ if ( settings . TryGetSetting (
28
+ BitbucketConstants . EnvironmentVariables . DevOAuthClientId ,
29
+ Constants . GitConfiguration . Credential . SectionName , BitbucketConstants . GitConfiguration . Credential . DevOAuthClientId ,
30
+ out string clientId ) )
31
+ {
32
+ return clientId ;
33
+ }
34
+
35
+ return BitbucketConstants . OAuth2ClientId ;
36
+ }
37
+
38
+ private static Uri GetRedirectUri ( ISettings settings )
39
+ {
40
+ // Check for developer override value
41
+ if ( settings . TryGetSetting (
42
+ BitbucketConstants . EnvironmentVariables . DevOAuthRedirectUri ,
43
+ Constants . GitConfiguration . Credential . SectionName , BitbucketConstants . GitConfiguration . Credential . DevOAuthRedirectUri ,
44
+ out string redirectUriStr ) && Uri . TryCreate ( redirectUriStr , UriKind . Absolute , out Uri redirectUri ) )
45
+ {
46
+ return redirectUri ;
47
+ }
48
+
49
+ return BitbucketConstants . OAuth2RedirectUri ;
50
+ }
51
+
52
+ private static string GetClientSecret ( ISettings settings )
53
+ {
54
+ // Check for developer override value
55
+ if ( settings . TryGetSetting (
56
+ BitbucketConstants . EnvironmentVariables . DevOAuthClientSecret ,
57
+ Constants . GitConfiguration . Credential . SectionName , BitbucketConstants . GitConfiguration . Credential . DevOAuthClientSecret ,
58
+ out string clientId ) )
59
+ {
60
+ return clientId ;
61
+ }
62
+
63
+ return BitbucketConstants . OAuth2ClientSecret ;
64
+ }
65
+
24
66
protected override bool TryCreateTokenEndpointResult ( string json , out OAuth2TokenResult result )
25
67
{
26
68
// We override the token endpoint response parsing because the Bitbucket authority returns
0 commit comments