From 9202497980e4d3f9939e5c64aa1896bed7482b2f Mon Sep 17 00:00:00 2001 From: Scott Schaab Date: Thu, 4 Jun 2020 05:24:48 -0700 Subject: [PATCH 1/2] Making developer credential types public --- sdk/identity/Azure.Identity/CHANGELOG.md | 2 ++ .../Azure.Identity/src/AzureCliCredential.cs | 4 ++-- .../src/VisualStudioCodeCredential.cs | 15 ++++++++------ .../src/VisualStudioCodeCredentialOptions.cs | 20 +++++++++++++++++++ .../src/VisualStudioCredential.cs | 13 +++++++----- .../src/VisualStudioCredentialOptions.cs | 16 +++++++++++++++ 6 files changed, 57 insertions(+), 13 deletions(-) create mode 100644 sdk/identity/Azure.Identity/src/VisualStudioCodeCredentialOptions.cs create mode 100644 sdk/identity/Azure.Identity/src/VisualStudioCredentialOptions.cs diff --git a/sdk/identity/Azure.Identity/CHANGELOG.md b/sdk/identity/Azure.Identity/CHANGELOG.md index 79504191433c..690c4575dedf 100644 --- a/sdk/identity/Azure.Identity/CHANGELOG.md +++ b/sdk/identity/Azure.Identity/CHANGELOG.md @@ -2,6 +2,8 @@ ## 1.2.0-preview.4 (Unreleased) +### New Features +- Makes `AzureCliCredential`, `VisualStudioCredential` and `VisualStudioCodeCredential` public to allow direct usage. ## 1.2.0-preview.3 diff --git a/sdk/identity/Azure.Identity/src/AzureCliCredential.cs b/sdk/identity/Azure.Identity/src/AzureCliCredential.cs index d3b4b66711dd..115dbb1a60e7 100644 --- a/sdk/identity/Azure.Identity/src/AzureCliCredential.cs +++ b/sdk/identity/Azure.Identity/src/AzureCliCredential.cs @@ -18,9 +18,9 @@ namespace Azure.Identity { /// - /// Enables authentication to Azure Active Directory using Azure CLI to generated an access token. + /// Enables authentication to Azure Active Directory using Azure CLI to obtain an access token. /// - internal class AzureCliCredential : TokenCredential + public class AzureCliCredential : TokenCredential { private const string AzureCLINotInstalled = "Azure CLI not installed"; private const string AzNotLogIn = "Please run 'az login' to set up account"; diff --git a/sdk/identity/Azure.Identity/src/VisualStudioCodeCredential.cs b/sdk/identity/Azure.Identity/src/VisualStudioCodeCredential.cs index f51832729f82..1bfa82362af9 100644 --- a/sdk/identity/Azure.Identity/src/VisualStudioCodeCredential.cs +++ b/sdk/identity/Azure.Identity/src/VisualStudioCodeCredential.cs @@ -15,9 +15,9 @@ namespace Azure.Identity { /// - /// Enables authentication to Azure Active Directory using data from Visual Studio Code + /// Enables authentication to Azure Active Directory using data from Visual Studio Code. /// - internal class VisualStudioCodeCredential : TokenCredential + public class VisualStudioCodeCredential : TokenCredential { private const string CredentialsSection = "VS Code Azure"; private const string ClientId = "aebc6443-996d-45c2-90f0-388ff96faa56"; @@ -28,12 +28,15 @@ internal class VisualStudioCodeCredential : TokenCredential private readonly MsalPublicClient _client; /// - /// Protected constructor for mocking + /// Creates a new instance of the . /// - protected VisualStudioCodeCredential() : this(default, default) {} + public VisualStudioCodeCredential() : this(null) { } - /// - public VisualStudioCodeCredential(string tenantId, TokenCredentialOptions options) : this(tenantId, CredentialPipeline.GetInstance(options), default, default) {} + /// + /// Creates a new instance of the with the specified options. + /// + /// Options for configuring the credential. + public VisualStudioCodeCredential(VisualStudioCodeCredentialOptions options) : this(options?.TenantId, CredentialPipeline.GetInstance(options), default, default) { } internal VisualStudioCodeCredential(string tenantId, CredentialPipeline pipeline, IFileSystemService fileSystem, IVisualStudioCodeAdapter vscAdapter) : this(tenantId, pipeline, default, fileSystem, vscAdapter) diff --git a/sdk/identity/Azure.Identity/src/VisualStudioCodeCredentialOptions.cs b/sdk/identity/Azure.Identity/src/VisualStudioCodeCredentialOptions.cs new file mode 100644 index 000000000000..d9626c361703 --- /dev/null +++ b/sdk/identity/Azure.Identity/src/VisualStudioCodeCredentialOptions.cs @@ -0,0 +1,20 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Text; + +namespace Azure.Identity +{ + /// + /// Options for configuring the . + /// + public class VisualStudioCodeCredentialOptions : TokenCredentialOptions + { + /// + /// The tenant ID the user will be authenticated to. If not specified the user will be authenticated to the tenant the user originally authenticated to via the Visual Studio Code Azure Account plugin. + /// + public string TenantId { get; set; } + } +} diff --git a/sdk/identity/Azure.Identity/src/VisualStudioCredential.cs b/sdk/identity/Azure.Identity/src/VisualStudioCredential.cs index 40f551af10d0..cfe47a0be66c 100644 --- a/sdk/identity/Azure.Identity/src/VisualStudioCredential.cs +++ b/sdk/identity/Azure.Identity/src/VisualStudioCredential.cs @@ -20,7 +20,7 @@ namespace Azure.Identity /// /// Enables authentication to Azure Active Directory using data from Visual Studio /// - internal class VisualStudioCredential : TokenCredential + public class VisualStudioCredential : TokenCredential { private const string TokenProviderFilePath = @".IdentityService\AzureServiceAuth\tokenprovider.json"; private const string ResourceArgumentName = "--resource"; @@ -32,12 +32,15 @@ internal class VisualStudioCredential : TokenCredential private readonly IProcessService _processService; /// - /// Protected constructor for mocking + /// Creates a new instance of the . /// - protected VisualStudioCredential() : this(default, default) {} + public VisualStudioCredential() : this(null) { } - /// - internal VisualStudioCredential(string tenantId, TokenCredentialOptions options) : this(tenantId, CredentialPipeline.GetInstance(options), default, default) {} + /// + /// Creates a new instance of the with the specified options. + /// + /// Options for configuring the credential. + public VisualStudioCredential(VisualStudioCredentialOptions options) : this(options?.TenantId, CredentialPipeline.GetInstance(options), default, default) { } internal VisualStudioCredential(string tenantId, CredentialPipeline pipeline, IFileSystemService fileSystem, IProcessService processService) { diff --git a/sdk/identity/Azure.Identity/src/VisualStudioCredentialOptions.cs b/sdk/identity/Azure.Identity/src/VisualStudioCredentialOptions.cs new file mode 100644 index 000000000000..795e8ee79535 --- /dev/null +++ b/sdk/identity/Azure.Identity/src/VisualStudioCredentialOptions.cs @@ -0,0 +1,16 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Azure.Identity +{ + /// + /// Options for configuring the . + /// + public class VisualStudioCredentialOptions : TokenCredentialOptions + { + /// + /// The tenant ID the user will be authenticated to. If not specified the user will be authenticated to their home tenant. + /// + public string TenantId { get; set; } + } +} From 8409c7b710f746e5f61582e77972ad9578fc2992 Mon Sep 17 00:00:00 2001 From: Scott Schaab Date: Thu, 4 Jun 2020 06:21:52 -0700 Subject: [PATCH 2/2] update api listing --- .../api/Azure.Identity.netstandard2.0.cs | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/sdk/identity/Azure.Identity/api/Azure.Identity.netstandard2.0.cs b/sdk/identity/Azure.Identity/api/Azure.Identity.netstandard2.0.cs index e16670e10958..ecef3a326a4b 100644 --- a/sdk/identity/Azure.Identity/api/Azure.Identity.netstandard2.0.cs +++ b/sdk/identity/Azure.Identity/api/Azure.Identity.netstandard2.0.cs @@ -31,6 +31,12 @@ public AuthorizationCodeCredential(string tenantId, string clientId, string clie public override Azure.Core.AccessToken GetToken(Azure.Core.TokenRequestContext requestContext, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public override System.Threading.Tasks.ValueTask GetTokenAsync(Azure.Core.TokenRequestContext requestContext, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } } + public partial class AzureCliCredential : Azure.Core.TokenCredential + { + public AzureCliCredential() { } + public override Azure.Core.AccessToken GetToken(Azure.Core.TokenRequestContext requestContext, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public override System.Threading.Tasks.ValueTask GetTokenAsync(Azure.Core.TokenRequestContext requestContext, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + } public partial class ChainedTokenCredential : Azure.Core.TokenCredential { public ChainedTokenCredential(params Azure.Core.TokenCredential[] sources) { } @@ -189,4 +195,28 @@ public UsernamePasswordCredential(string username, string password, string tenan public override Azure.Core.AccessToken GetToken(Azure.Core.TokenRequestContext requestContext, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public override System.Threading.Tasks.ValueTask GetTokenAsync(Azure.Core.TokenRequestContext requestContext, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } } + public partial class VisualStudioCodeCredential : Azure.Core.TokenCredential + { + public VisualStudioCodeCredential() { } + public VisualStudioCodeCredential(Azure.Identity.VisualStudioCodeCredentialOptions options) { } + public override Azure.Core.AccessToken GetToken(Azure.Core.TokenRequestContext requestContext, System.Threading.CancellationToken cancellationToken) { throw null; } + public override System.Threading.Tasks.ValueTask GetTokenAsync(Azure.Core.TokenRequestContext requestContext, System.Threading.CancellationToken cancellationToken) { throw null; } + } + public partial class VisualStudioCodeCredentialOptions : Azure.Identity.TokenCredentialOptions + { + public VisualStudioCodeCredentialOptions() { } + public string TenantId { get { throw null; } set { } } + } + public partial class VisualStudioCredential : Azure.Core.TokenCredential + { + public VisualStudioCredential() { } + public VisualStudioCredential(Azure.Identity.VisualStudioCredentialOptions options) { } + public override Azure.Core.AccessToken GetToken(Azure.Core.TokenRequestContext requestContext, System.Threading.CancellationToken cancellationToken) { throw null; } + public override System.Threading.Tasks.ValueTask GetTokenAsync(Azure.Core.TokenRequestContext requestContext, System.Threading.CancellationToken cancellationToken) { throw null; } + } + public partial class VisualStudioCredentialOptions : Azure.Identity.TokenCredentialOptions + { + public VisualStudioCredentialOptions() { } + public string TenantId { get { throw null; } set { } } + } }