Skip to content

Commit

Permalink
Merge pull request #99 from mjcheetham/oauth2
Browse files Browse the repository at this point in the history
Add an OAuth2 client implementation
  • Loading branch information
mjcheetham authored Apr 16, 2020
2 parents f64d3e9 + 637a056 commit 0b0752d
Show file tree
Hide file tree
Showing 34 changed files with 1,988 additions and 105 deletions.
6 changes: 4 additions & 2 deletions .azure-pipelines/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,22 @@ trigger:

variables:
configuration: Release
winImage: vs2017-win2016
osxImage: macos-latest

jobs:
- job: windows
displayName: Windows
pool:
vmImage: vs2017-win2016
vmImage: $(winImage)
steps:
- template: templates/windows/compile.yml
- template: templates/windows/pack.yml

- job: osx
displayName: macOS
pool:
vmImage: macOS 10.13
vmImage: $(osxImage)
steps:
- template: templates/osx/compile.yml
- template: templates/osx/pack.unsigned.yml
6 changes: 4 additions & 2 deletions .azure-pipelines/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,22 @@ trigger: none

variables:
configuration: Release
winImage: vs2017-win2016
osxImage: macos-latest

jobs:
- job: windows
displayName: Windows
pool:
vmImage: vs2017-win2016
vmImage: $(winImage)
steps:
- template: templates/windows/compile.yml
- template: templates/windows/pack.yml

- job: osx
displayName: macOS
pool:
vmImage: macOS 10.13
vmImage: $(osxImage)
steps:
- template: templates/osx/compile.yml
- template: templates/osx/pack.unsigned.yml
15 changes: 9 additions & 6 deletions .azure-pipelines/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,23 @@ trigger:

variables:
configuration: Release
signPool: VSEng-MicroBuildVS2017
winImage: vs2017-win2016
osxImage: macos-latest

jobs:
- job: windows
displayName: Windows
pool:
name: VSEng-MicroBuildVS2017
name: $(signPool)
steps:
- template: templates/windows/compile.yml
- template: templates/windows/pack.yml

- job: osx_step1
displayName: macOS (Build & Layout)
pool:
vmImage: macOS 10.13
vmImage: $(osxImage)
steps:
- template: templates/osx/compile.yml
- template: templates/osx/pack.signed/step1-layout.yml
Expand All @@ -26,7 +29,7 @@ jobs:
dependsOn: osx_step1
condition: succeeded()
pool:
name: VSEng-MicroBuildVS2017
name: $(signPool)
steps:
- template: templates/osx/pack.signed/step2-signpayload.yml

Expand All @@ -35,7 +38,7 @@ jobs:
dependsOn: osx_step2
condition: succeeded()
pool:
vmImage: macOS 10.13
vmImage: $(osxImage)
steps:
- template: templates/osx/pack.signed/step3-pack.yml

Expand All @@ -44,7 +47,7 @@ jobs:
dependsOn: osx_step3
condition: succeeded()
pool:
name: VSEng-MicroBuildVS2017
name: $(signPool)
steps:
- template: templates/osx/pack.signed/step4-signpack.yml

Expand All @@ -53,6 +56,6 @@ jobs:
dependsOn: osx_step4
condition: succeeded()
pool:
vmImage: macOS 10.13
vmImage: $(osxImage)
steps:
- template: templates/osx/pack.signed/step5-dist.yml
3 changes: 2 additions & 1 deletion src/shared/GitHub.Tests/GitHubRestApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Git.CredentialManager;
using Microsoft.Git.CredentialManager.Tests.Objects;
Expand Down Expand Up @@ -380,7 +381,7 @@ public async Task GitHubRestApi_AcquireTokenAsync_UnknownResponse_ReturnsFailure

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

AuthenticationHeaderValue authHeader = request.Headers.Authorization;
Assert.NotNull(authHeader);
Expand Down
4 changes: 1 addition & 3 deletions src/shared/GitHub/GitHubRestApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ public async Task<AuthenticationResult> AcquireTokenAsync(Uri targetUri, string
EnsureArgument.AbsoluteUri(targetUri, nameof(targetUri));
EnsureArgument.NotNull(scopes, nameof(scopes));

string base64Cred = new GitCredential(username, password).ToBase64String();

Uri requestUri = GetAuthenticationRequestUri(targetUri);

_context.Trace.WriteLine($"HTTP: POST {requestUri}");
Expand All @@ -56,7 +54,7 @@ public async Task<AuthenticationResult> AcquireTokenAsync(Uri targetUri, string
{
// Set the request content as well as auth and 2FA headers
request.Content = content;
request.Headers.Authorization = new AuthenticationHeaderValue(Constants.Http.WwwAuthenticateBasicScheme, base64Cred);
request.AddBasicAuthenticationHeader(username, password);
if (!string.IsNullOrWhiteSpace(authenticationCode))
{
request.Headers.Add(GitHubConstants.GitHubOptHeader, authenticationCode);
Expand Down
4 changes: 2 additions & 2 deletions src/shared/Microsoft.AzureRepos.Tests/AzureDevOpsApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -329,13 +329,13 @@ public async Task AzureDevOpsRestApi_CreatePersonalAccessTokenAsync_IdentSvcRetu
var identSvcError = CreateIdentityServiceErrorResponse(serverErrorMessage);

var httpHandler = new TestHttpMessageHandler {ThrowOnUnexpectedRequest = true};
httpHandler.Setup(HttpMethod.Get, locSvcRequestUri, x =>
httpHandler.Setup(HttpMethod.Get, locSvcRequestUri, x =>
{
AssertAcceptJson(x);
AssertBearerToken(x, accessToken);
return locSvcResponse;
});
httpHandler.Setup(HttpMethod.Post, identSvcRequestUri, _ => identSvcError);
httpHandler.Setup(HttpMethod.Post, identSvcRequestUri, identSvcError);

context.HttpClientFactory.MessageHandler = httpHandler;
var api = new AzureDevOpsRestApi(context);
Expand Down
Loading

0 comments on commit 0b0752d

Please sign in to comment.