Skip to content

Commit

Permalink
Merge pull request #1414 from Azure/dev
Browse files Browse the repository at this point in the history
1.10.0 hotfix (#1412)
  • Loading branch information
terencefan authored Aug 26, 2021
2 parents 7c411e3 + a015677 commit 420783a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 13 deletions.
14 changes: 7 additions & 7 deletions src/Microsoft.Azure.SignalR.Common/Endpoints/AadAccessKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
using System.Security.Claims;
using System.Threading;
using System.Threading.Tasks;

using Azure.Core;

using Microsoft.Azure.SignalR.Common;

using Newtonsoft.Json.Linq;

namespace Microsoft.Azure.SignalR
Expand Down Expand Up @@ -34,21 +37,18 @@ internal class AadAccessKey : AccessKey

public TokenCredential TokenCredential { get; }

private string AuthorizeUrl { get; }
internal string AuthorizeUrl { get; }

private Task<object> InitializedTask => _initializedTcs.Task;

public AadAccessKey(string uri, TokenCredential credential) : this(new Uri(uri), credential)
public AadAccessKey(Uri uri, TokenCredential credential): base(uri)
{
var builder = new UriBuilder(Endpoint)
{
Path = "/api/v1/auth/accessKey"
Path = "/api/v1/auth/accessKey",
Port = uri.Port
};
AuthorizeUrl = builder.Uri.AbsoluteUri;
}

public AadAccessKey(Uri uri, TokenCredential credential): base(uri)
{
TokenCredential = credential;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
using System.Security.Claims;
using System.Threading;
using System.Threading.Tasks;

using Azure.Identity;

using Xunit;

namespace Microsoft.Azure.SignalR.Common.Tests.Auth
Expand All @@ -11,12 +13,22 @@ public class AadAccessKeyTests
{
private const string SigningKey = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

[Theory]
[InlineData("https://a.bc", "https://a.bc/api/v1/auth/accessKey")]
[InlineData("https://a.bc:80", "https://a.bc:80/api/v1/auth/accessKey")]
[InlineData("https://a.bc:443", "https://a.bc/api/v1/auth/accessKey")]
public void TestConstructor(string endpoint, string expectedAuthorizeUrl)
{
var key = new AadAccessKey(new Uri(endpoint), new DefaultAzureCredential());
Assert.Equal(expectedAuthorizeUrl, key.AuthorizeUrl);
}

[Fact]
public async Task TestUpdateAccessKey()
{
var credential = new EnvironmentCredential();
var endpoint = "http://localhost";
var key = new AadAccessKey(endpoint, credential);
var key = new AadAccessKey(new Uri(endpoint), credential);

var audience = "http://localhost/chat";
var claims = Array.Empty<Claim>();
Expand All @@ -39,7 +51,7 @@ await Assert.ThrowsAsync<TaskCanceledException>(
public async Task TestInitializeFailed()
{
var credential = new EnvironmentCredential();
var key = new AadAccessKey("http://localhost", credential);
var key = new AadAccessKey(new Uri("http://localhost"), credential);

var audience = "http://localhost/chat";
var claims = Array.Empty<Claim>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
using System.IdentityModel.Tokens.Jwt;
using System;
using System.IdentityModel.Tokens.Jwt;
using System.Threading.Tasks;

using Azure.Core;
using Azure.Identity;

using Microsoft.IdentityModel.Logging;
using Microsoft.IdentityModel.Protocols;
using Microsoft.IdentityModel.Protocols.OpenIdConnect;
using Microsoft.IdentityModel.Tokens;

using Xunit;

namespace Microsoft.Azure.SignalR.Common.Tests.Auth
Expand All @@ -24,7 +28,7 @@ public class AzureActiveDirectoryTests
public async Task TestAcquireAccessToken()
{
var options = new ClientSecretCredential(TestTenantId, TestClientId, TestClientSecret);
var key = new AadAccessKey("https://localhost:8080", options);
var key = new AadAccessKey(new Uri("https://localhost:8080"), options);
var token = await key.GenerateAadTokenAsync();
Assert.NotNull(token);
}
Expand Down Expand Up @@ -71,7 +75,7 @@ public async Task TestGetAzureAdTokenAndAuthenticate()
internal async Task TestAuthenticateAsync()
{
var options = new ClientSecretCredential(TestTenantId, TestClientId, TestClientSecret);
var key = new AadAccessKey("https://localhost:8080", options);
var key = new AadAccessKey(new Uri("https://localhost:8080"), options);
await key.UpdateAccessKeyAsync();

Assert.True(key.Authorized);
Expand Down
2 changes: 1 addition & 1 deletion test/Microsoft.Azure.SignalR.Tests/ServiceMessageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ private class TestAadAccessKey : AadAccessKey
{
public string Token { get; } = Guid.NewGuid().ToString();

public TestAadAccessKey() : base("http://localhost:80", new DefaultAzureCredential())
public TestAadAccessKey() : base(new Uri("http://localhost:80"), new DefaultAzureCredential())
{
}

Expand Down

0 comments on commit 420783a

Please sign in to comment.