Skip to content

Commit 0b0752d

Browse files
authored
Merge pull request #99 from mjcheetham/oauth2
Add an OAuth2 client implementation
2 parents f64d3e9 + 637a056 commit 0b0752d

34 files changed

+1988
-105
lines changed

.azure-pipelines/continuous-integration.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,22 @@ trigger:
33

44
variables:
55
configuration: Release
6+
winImage: vs2017-win2016
7+
osxImage: macos-latest
68

79
jobs:
810
- job: windows
911
displayName: Windows
1012
pool:
11-
vmImage: vs2017-win2016
13+
vmImage: $(winImage)
1214
steps:
1315
- template: templates/windows/compile.yml
1416
- template: templates/windows/pack.yml
1517

1618
- job: osx
1719
displayName: macOS
1820
pool:
19-
vmImage: macOS 10.13
21+
vmImage: $(osxImage)
2022
steps:
2123
- template: templates/osx/compile.yml
2224
- template: templates/osx/pack.unsigned.yml

.azure-pipelines/pull-request.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,22 @@ trigger: none
33

44
variables:
55
configuration: Release
6+
winImage: vs2017-win2016
7+
osxImage: macos-latest
68

79
jobs:
810
- job: windows
911
displayName: Windows
1012
pool:
11-
vmImage: vs2017-win2016
13+
vmImage: $(winImage)
1214
steps:
1315
- template: templates/windows/compile.yml
1416
- template: templates/windows/pack.yml
1517

1618
- job: osx
1719
displayName: macOS
1820
pool:
19-
vmImage: macOS 10.13
21+
vmImage: $(osxImage)
2022
steps:
2123
- template: templates/osx/compile.yml
2224
- template: templates/osx/pack.unsigned.yml

.azure-pipelines/release.yml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,23 @@ trigger:
33

44
variables:
55
configuration: Release
6+
signPool: VSEng-MicroBuildVS2017
7+
winImage: vs2017-win2016
8+
osxImage: macos-latest
69

710
jobs:
811
- job: windows
912
displayName: Windows
1013
pool:
11-
name: VSEng-MicroBuildVS2017
14+
name: $(signPool)
1215
steps:
1316
- template: templates/windows/compile.yml
1417
- template: templates/windows/pack.yml
1518

1619
- job: osx_step1
1720
displayName: macOS (Build & Layout)
1821
pool:
19-
vmImage: macOS 10.13
22+
vmImage: $(osxImage)
2023
steps:
2124
- template: templates/osx/compile.yml
2225
- template: templates/osx/pack.signed/step1-layout.yml
@@ -26,7 +29,7 @@ jobs:
2629
dependsOn: osx_step1
2730
condition: succeeded()
2831
pool:
29-
name: VSEng-MicroBuildVS2017
32+
name: $(signPool)
3033
steps:
3134
- template: templates/osx/pack.signed/step2-signpayload.yml
3235

@@ -35,7 +38,7 @@ jobs:
3538
dependsOn: osx_step2
3639
condition: succeeded()
3740
pool:
38-
vmImage: macOS 10.13
41+
vmImage: $(osxImage)
3942
steps:
4043
- template: templates/osx/pack.signed/step3-pack.yml
4144

@@ -44,7 +47,7 @@ jobs:
4447
dependsOn: osx_step3
4548
condition: succeeded()
4649
pool:
47-
name: VSEng-MicroBuildVS2017
50+
name: $(signPool)
4851
steps:
4952
- template: templates/osx/pack.signed/step4-signpack.yml
5053

@@ -53,6 +56,6 @@ jobs:
5356
dependsOn: osx_step4
5457
condition: succeeded()
5558
pool:
56-
vmImage: macOS 10.13
59+
vmImage: $(osxImage)
5760
steps:
5861
- template: templates/osx/pack.signed/step5-dist.yml

src/shared/GitHub.Tests/GitHubRestApiTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Net;
77
using System.Net.Http;
88
using System.Net.Http.Headers;
9+
using System.Text;
910
using System.Threading.Tasks;
1011
using Microsoft.Git.CredentialManager;
1112
using Microsoft.Git.CredentialManager.Tests.Objects;
@@ -380,7 +381,7 @@ public async Task GitHubRestApi_AcquireTokenAsync_UnknownResponse_ReturnsFailure
380381

381382
private static void AssertBasicAuth(HttpRequestMessage request, string userName, string password)
382383
{
383-
string expectedBasicValue = new GitCredential(userName, password).ToBase64String();
384+
string expectedBasicValue = Convert.ToBase64String(Encoding.UTF8.GetBytes($"{userName}:{password}"));
384385

385386
AuthenticationHeaderValue authHeader = request.Headers.Authorization;
386387
Assert.NotNull(authHeader);

src/shared/GitHub/GitHubRestApi.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ public async Task<AuthenticationResult> AcquireTokenAsync(Uri targetUri, string
4646
EnsureArgument.AbsoluteUri(targetUri, nameof(targetUri));
4747
EnsureArgument.NotNull(scopes, nameof(scopes));
4848

49-
string base64Cred = new GitCredential(username, password).ToBase64String();
50-
5149
Uri requestUri = GetAuthenticationRequestUri(targetUri);
5250

5351
_context.Trace.WriteLine($"HTTP: POST {requestUri}");
@@ -56,7 +54,7 @@ public async Task<AuthenticationResult> AcquireTokenAsync(Uri targetUri, string
5654
{
5755
// Set the request content as well as auth and 2FA headers
5856
request.Content = content;
59-
request.Headers.Authorization = new AuthenticationHeaderValue(Constants.Http.WwwAuthenticateBasicScheme, base64Cred);
57+
request.AddBasicAuthenticationHeader(username, password);
6058
if (!string.IsNullOrWhiteSpace(authenticationCode))
6159
{
6260
request.Headers.Add(GitHubConstants.GitHubOptHeader, authenticationCode);

src/shared/Microsoft.AzureRepos.Tests/AzureDevOpsApiTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,13 +329,13 @@ public async Task AzureDevOpsRestApi_CreatePersonalAccessTokenAsync_IdentSvcRetu
329329
var identSvcError = CreateIdentityServiceErrorResponse(serverErrorMessage);
330330

331331
var httpHandler = new TestHttpMessageHandler {ThrowOnUnexpectedRequest = true};
332-
httpHandler.Setup(HttpMethod.Get, locSvcRequestUri, x =>
332+
httpHandler.Setup(HttpMethod.Get, locSvcRequestUri, x =>
333333
{
334334
AssertAcceptJson(x);
335335
AssertBearerToken(x, accessToken);
336336
return locSvcResponse;
337337
});
338-
httpHandler.Setup(HttpMethod.Post, identSvcRequestUri, _ => identSvcError);
338+
httpHandler.Setup(HttpMethod.Post, identSvcRequestUri, identSvcError);
339339

340340
context.HttpClientFactory.MessageHandler = httpHandler;
341341
var api = new AzureDevOpsRestApi(context);

0 commit comments

Comments
 (0)