From 7461ec21baa7504c90a0b2a1148e56ca2aee29ce Mon Sep 17 00:00:00 2001 From: Craig Treasure Date: Tue, 2 Feb 2021 16:02:38 -0800 Subject: [PATCH] Mixed Reality Authentication: Updated the MR STS spec file (#18341) This change updated the library to consume the latest version of spec file, which changes the account identifier to be a `Guid` rather than a `string`. The service expects a `Guid` or `UUID`, so it makes sense to be specific. --- .../CHANGELOG.md | 4 ++++ ...xedReality.Authentication.netstandard2.0.cs | 10 +++++----- .../shared/MixedRealityAccountKeyCredential.cs | 8 ++++---- .../shared/MixedRealityTokenCredential.cs | 4 ++-- .../src/Generated/MixedRealityStsRestClient.cs | 18 +++--------------- .../src/MixedRealityStsClient.cs | 12 ++++++------ .../src/autorest.md | 2 +- .../tests/MixedRealityStsClientLiveTests.cs | 3 ++- 8 files changed, 27 insertions(+), 34 deletions(-) diff --git a/sdk/mixedreality/Azure.MixedReality.Authentication/CHANGELOG.md b/sdk/mixedreality/Azure.MixedReality.Authentication/CHANGELOG.md index 68d46c7016fc..b1c7d069a93b 100644 --- a/sdk/mixedreality/Azure.MixedReality.Authentication/CHANGELOG.md +++ b/sdk/mixedreality/Azure.MixedReality.Authentication/CHANGELOG.md @@ -1,5 +1,9 @@ # Release History +## 1.0.0-preview.3 (2021-01-15) + +- Updated to latest version of spec file which changes the account identifier to be a `Guid` rather than a `string`. + ## 1.0.0-preview.2 (2021-01-12) - Configured with shared source. diff --git a/sdk/mixedreality/Azure.MixedReality.Authentication/api/Azure.MixedReality.Authentication.netstandard2.0.cs b/sdk/mixedreality/Azure.MixedReality.Authentication/api/Azure.MixedReality.Authentication.netstandard2.0.cs index acf9434b357c..df6335bd3158 100644 --- a/sdk/mixedreality/Azure.MixedReality.Authentication/api/Azure.MixedReality.Authentication.netstandard2.0.cs +++ b/sdk/mixedreality/Azure.MixedReality.Authentication/api/Azure.MixedReality.Authentication.netstandard2.0.cs @@ -3,11 +3,11 @@ namespace Azure.MixedReality.Authentication public partial class MixedRealityStsClient { protected MixedRealityStsClient() { } - public MixedRealityStsClient(string accountId, string accountDomain, Azure.AzureKeyCredential keyCredential, Azure.MixedReality.Authentication.MixedRealityStsClientOptions? options = null) { } - public MixedRealityStsClient(string accountId, string accountDomain, Azure.Core.TokenCredential credential, Azure.MixedReality.Authentication.MixedRealityStsClientOptions? options = null) { } - public MixedRealityStsClient(string accountId, System.Uri endpoint, Azure.AzureKeyCredential keyCredential, Azure.MixedReality.Authentication.MixedRealityStsClientOptions? options = null) { } - public MixedRealityStsClient(string accountId, System.Uri endpoint, Azure.Core.TokenCredential credential, Azure.MixedReality.Authentication.MixedRealityStsClientOptions? options = null) { } - public string AccountId { get { throw null; } } + public MixedRealityStsClient(System.Guid accountId, string accountDomain, Azure.AzureKeyCredential keyCredential, Azure.MixedReality.Authentication.MixedRealityStsClientOptions? options = null) { } + public MixedRealityStsClient(System.Guid accountId, string accountDomain, Azure.Core.TokenCredential credential, Azure.MixedReality.Authentication.MixedRealityStsClientOptions? options = null) { } + public MixedRealityStsClient(System.Guid accountId, System.Uri endpoint, Azure.AzureKeyCredential keyCredential, Azure.MixedReality.Authentication.MixedRealityStsClientOptions? options = null) { } + public MixedRealityStsClient(System.Guid accountId, System.Uri endpoint, Azure.Core.TokenCredential credential, Azure.MixedReality.Authentication.MixedRealityStsClientOptions? options = null) { } + public System.Guid AccountId { get { throw null; } } public System.Uri Endpoint { get { throw null; } } public virtual Azure.Response GetToken(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task> GetTokenAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } diff --git a/sdk/mixedreality/Azure.MixedReality.Authentication/shared/MixedRealityAccountKeyCredential.cs b/sdk/mixedreality/Azure.MixedReality.Authentication/shared/MixedRealityAccountKeyCredential.cs index 36c0c23cf8e0..69cf4427df49 100644 --- a/sdk/mixedreality/Azure.MixedReality.Authentication/shared/MixedRealityAccountKeyCredential.cs +++ b/sdk/mixedreality/Azure.MixedReality.Authentication/shared/MixedRealityAccountKeyCredential.cs @@ -14,7 +14,7 @@ namespace Azure.MixedReality.Authentication /// internal class MixedRealityAccountKeyCredential : TokenCredential { - private readonly string _accountId; + private readonly Guid _accountId; private readonly AzureKeyCredential _accountKey; @@ -23,7 +23,7 @@ internal class MixedRealityAccountKeyCredential : TokenCredential /// /// The Mixed Reality service account identifier. /// The Mixed Reality service account primary or secondary key. - public MixedRealityAccountKeyCredential(string accountId, string accountKey) + public MixedRealityAccountKeyCredential(Guid accountId, string accountKey) : this(accountId, new AzureKeyCredential(accountKey)) { } @@ -33,9 +33,9 @@ public MixedRealityAccountKeyCredential(string accountId, string accountKey) /// /// The Mixed Reality service account identifier. /// The Mixed Reality service account primary or secondary key credential. - public MixedRealityAccountKeyCredential(string accountId, AzureKeyCredential keyCredential) + public MixedRealityAccountKeyCredential(Guid accountId, AzureKeyCredential keyCredential) { - Argument.AssertNotNullOrWhiteSpace(accountId, nameof(accountId)); + Argument.AssertNotDefault(ref accountId, nameof(accountId)); Argument.AssertNotNull(keyCredential, nameof(keyCredential)); _accountId = accountId; diff --git a/sdk/mixedreality/Azure.MixedReality.Authentication/shared/MixedRealityTokenCredential.cs b/sdk/mixedreality/Azure.MixedReality.Authentication/shared/MixedRealityTokenCredential.cs index 947b1c37bc38..f6e2b5b697da 100644 --- a/sdk/mixedreality/Azure.MixedReality.Authentication/shared/MixedRealityTokenCredential.cs +++ b/sdk/mixedreality/Azure.MixedReality.Authentication/shared/MixedRealityTokenCredential.cs @@ -24,7 +24,7 @@ internal class MixedRealityTokenCredential : TokenCredential /// The Mixed Reality STS service endpoint. /// The credential used to access the Mixed Reality service. /// The options. - private MixedRealityTokenCredential(string accountId, Uri endpoint, TokenCredential credential, MixedRealityStsClientOptions? options = null) + private MixedRealityTokenCredential(Guid accountId, Uri endpoint, TokenCredential credential, MixedRealityStsClientOptions? options = null) { _stsClient = new MixedRealityStsClient(accountId, endpoint, credential, options); } @@ -58,7 +58,7 @@ public override async ValueTask GetTokenAsync(TokenRequestContext r /// The credential used to access the Mixed Reality service. /// The options. /// . - public static TokenCredential GetMixedRealityCredential(string accountId, Uri endpoint, TokenCredential credential, MixedRealityStsClientOptions? options = null) + public static TokenCredential GetMixedRealityCredential(Guid accountId, Uri endpoint, TokenCredential credential, MixedRealityStsClientOptions? options = null) { if (credential is StaticAccessTokenCredential) { diff --git a/sdk/mixedreality/Azure.MixedReality.Authentication/src/Generated/MixedRealityStsRestClient.cs b/sdk/mixedreality/Azure.MixedReality.Authentication/src/Generated/MixedRealityStsRestClient.cs index d1a875f87083..4bb0565b88bf 100644 --- a/sdk/mixedreality/Azure.MixedReality.Authentication/src/Generated/MixedRealityStsRestClient.cs +++ b/sdk/mixedreality/Azure.MixedReality.Authentication/src/Generated/MixedRealityStsRestClient.cs @@ -36,7 +36,7 @@ public MixedRealityStsRestClient(ClientDiagnostics clientDiagnostics, HttpPipeli _pipeline = pipeline; } - internal HttpMessage CreateGetTokenRequest(string accountId, MixedRealityTokenRequestOptions tokenRequestOptions) + internal HttpMessage CreateGetTokenRequest(Guid accountId, MixedRealityTokenRequestOptions tokenRequestOptions) { var message = _pipeline.CreateMessage(); var request = message.Request; @@ -63,14 +63,8 @@ internal HttpMessage CreateGetTokenRequest(string accountId, MixedRealityTokenRe /// The Mixed Reality account identifier. /// Parameter group. /// The cancellation token to use. - /// is null. - public async Task> GetTokenAsync(string accountId, MixedRealityTokenRequestOptions tokenRequestOptions = null, CancellationToken cancellationToken = default) + public async Task> GetTokenAsync(Guid accountId, MixedRealityTokenRequestOptions tokenRequestOptions = null, CancellationToken cancellationToken = default) { - if (accountId == null) - { - throw new ArgumentNullException(nameof(accountId)); - } - using var message = CreateGetTokenRequest(accountId, tokenRequestOptions); await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); var headers = new MixedRealityStsGetTokenHeaders(message.Response); @@ -92,14 +86,8 @@ public async Task The Mixed Reality account identifier. /// Parameter group. /// The cancellation token to use. - /// is null. - public ResponseWithHeaders GetToken(string accountId, MixedRealityTokenRequestOptions tokenRequestOptions = null, CancellationToken cancellationToken = default) + public ResponseWithHeaders GetToken(Guid accountId, MixedRealityTokenRequestOptions tokenRequestOptions = null, CancellationToken cancellationToken = default) { - if (accountId == null) - { - throw new ArgumentNullException(nameof(accountId)); - } - using var message = CreateGetTokenRequest(accountId, tokenRequestOptions); _pipeline.Send(message, cancellationToken); var headers = new MixedRealityStsGetTokenHeaders(message.Response); diff --git a/sdk/mixedreality/Azure.MixedReality.Authentication/src/MixedRealityStsClient.cs b/sdk/mixedreality/Azure.MixedReality.Authentication/src/MixedRealityStsClient.cs index 9d18f04a226f..22fec4a837be 100644 --- a/sdk/mixedreality/Azure.MixedReality.Authentication/src/MixedRealityStsClient.cs +++ b/sdk/mixedreality/Azure.MixedReality.Authentication/src/MixedRealityStsClient.cs @@ -23,7 +23,7 @@ public class MixedRealityStsClient /// /// Gets the Mixed Reality service account identifier. /// - public string AccountId { get; } + public Guid AccountId { get; } /// /// The Mixed Reality STS service endpoint. @@ -37,7 +37,7 @@ public class MixedRealityStsClient /// The Mixed Reality service account domain. /// The Mixed Reality service account primary or secondary key credential. /// The options. - public MixedRealityStsClient(string accountId, string accountDomain, AzureKeyCredential keyCredential, MixedRealityStsClientOptions? options = null) + public MixedRealityStsClient(Guid accountId, string accountDomain, AzureKeyCredential keyCredential, MixedRealityStsClientOptions? options = null) : this(accountId, AuthenticationEndpoint.ConstructFromDomain(accountDomain), new MixedRealityAccountKeyCredential(accountId, keyCredential), options) { } /// @@ -47,7 +47,7 @@ public MixedRealityStsClient(string accountId, string accountDomain, AzureKeyCre /// The Mixed Reality STS service endpoint. /// The Mixed Reality service account primary or secondary key credential. /// The options. - public MixedRealityStsClient(string accountId, Uri endpoint, AzureKeyCredential keyCredential, MixedRealityStsClientOptions? options = null) + public MixedRealityStsClient(Guid accountId, Uri endpoint, AzureKeyCredential keyCredential, MixedRealityStsClientOptions? options = null) : this(accountId, endpoint, new MixedRealityAccountKeyCredential(accountId, keyCredential), options) { } /// @@ -57,7 +57,7 @@ public MixedRealityStsClient(string accountId, Uri endpoint, AzureKeyCredential /// The Mixed Reality service account domain. /// The credential used to access the Mixed Reality service. /// The options. - public MixedRealityStsClient(string accountId, string accountDomain, TokenCredential credential, MixedRealityStsClientOptions? options = null) + public MixedRealityStsClient(Guid accountId, string accountDomain, TokenCredential credential, MixedRealityStsClientOptions? options = null) : this(accountId, AuthenticationEndpoint.ConstructFromDomain(accountDomain), credential, options) { } /// @@ -67,9 +67,9 @@ public MixedRealityStsClient(string accountId, string accountDomain, TokenCreden /// The Mixed Reality STS service endpoint. /// The credential used to access the Mixed Reality service. /// The options. - public MixedRealityStsClient(string accountId, Uri endpoint, TokenCredential credential, MixedRealityStsClientOptions? options = null) + public MixedRealityStsClient(Guid accountId, Uri endpoint, TokenCredential credential, MixedRealityStsClientOptions? options = null) { - Argument.AssertNotNull(accountId, nameof(accountId)); + Argument.AssertNotDefault(ref accountId, nameof(accountId)); Argument.AssertNotNull(endpoint, nameof(endpoint)); Argument.AssertNotNull(credential, nameof(credential)); diff --git a/sdk/mixedreality/Azure.MixedReality.Authentication/src/autorest.md b/sdk/mixedreality/Azure.MixedReality.Authentication/src/autorest.md index 8abe937fe810..dbcda5b6bf32 100644 --- a/sdk/mixedreality/Azure.MixedReality.Authentication/src/autorest.md +++ b/sdk/mixedreality/Azure.MixedReality.Authentication/src/autorest.md @@ -4,5 +4,5 @@ Run `dotnet build /t:GenerateCode` to generate code. ``` yaml input-file: - - https://raw.githubusercontent.com/Azure/azure-rest-api-specs/e0b78897850ccbb648b3efe286b78e78c5cd8bcf/specification/mixedreality/data-plane/Microsoft.MixedReality/preview/2019-02-28-preview/mr-sts.json + - https://raw.githubusercontent.com/Azure/azure-rest-api-specs/aa19725fe79aea2a9dc580f3c66f77f89cc34563/specification/mixedreality/data-plane/Microsoft.MixedReality/preview/2019-02-28-preview/mr-sts.json ``` diff --git a/sdk/mixedreality/Azure.MixedReality.Authentication/tests/MixedRealityStsClientLiveTests.cs b/sdk/mixedreality/Azure.MixedReality.Authentication/tests/MixedRealityStsClientLiveTests.cs index bd169613f6dd..473a76036000 100644 --- a/sdk/mixedreality/Azure.MixedReality.Authentication/tests/MixedRealityStsClientLiveTests.cs +++ b/sdk/mixedreality/Azure.MixedReality.Authentication/tests/MixedRealityStsClientLiveTests.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +using System; using System.Threading.Tasks; using Azure.Core; using Azure.Core.TestFramework; @@ -22,7 +23,7 @@ public MixedRealityStsClientLiveTests(bool isAsync) private MixedRealityStsClient CreateClient() { string mixedRealityAccountDomain = TestEnvironment.AccountDomain; - string mixedRealityAccountId = TestEnvironment.AccountId; + Guid mixedRealityAccountId = Guid.Parse(TestEnvironment.AccountId); string mixedRealityAccountKey = TestEnvironment.AccountKey; return InstrumentClient(new MixedRealityStsClient(