Skip to content

Commit

Permalink
Archboard feedback for objectId support (#45880)
Browse files Browse the repository at this point in the history
  • Loading branch information
christothes committed Sep 12, 2024
1 parent 2eda985 commit 2029731
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 26 deletions.
11 changes: 5 additions & 6 deletions sdk/identity/Azure.Identity/api/Azure.Identity.netstandard2.0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -317,24 +317,23 @@ protected ManagedIdentityCredential() { }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public ManagedIdentityCredential(Azure.Core.ResourceIdentifier resourceId, Azure.Identity.TokenCredentialOptions options = null) { }
public ManagedIdentityCredential(Azure.Identity.ManagedIdentityCredentialOptions options) { }
public ManagedIdentityCredential(Azure.Identity.ManagedIdentityId managedIdentityId) { }
public ManagedIdentityCredential(Azure.Identity.ManagedIdentityId id) { }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public ManagedIdentityCredential(string clientId = null, Azure.Identity.TokenCredentialOptions options = null) { }
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<Azure.Core.AccessToken> GetTokenAsync(Azure.Core.TokenRequestContext requestContext, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
}
public partial class ManagedIdentityCredentialOptions : Azure.Identity.TokenCredentialOptions
{
public ManagedIdentityCredentialOptions() { }
public Azure.Identity.ManagedIdentityId ManagedIdentityId { get { throw null; } set { } }
public ManagedIdentityCredentialOptions(Azure.Identity.ManagedIdentityId managedIdentityId = null) { }
}
public partial class ManagedIdentityId
{
internal ManagedIdentityId() { }
public static Azure.Identity.ManagedIdentityId SystemAssigned { get { throw null; } }
public static Azure.Identity.ManagedIdentityId FromUserAssignedClientId(string clientId) { throw null; }
public static Azure.Identity.ManagedIdentityId FromUserAssignedObjectId(string objectId) { throw null; }
public static Azure.Identity.ManagedIdentityId FromUserAssignedResourceId(Azure.Core.ResourceIdentifier resourceIdentifier) { throw null; }
public static Azure.Identity.ManagedIdentityId FromUserAssignedClientId(string id) { throw null; }
public static Azure.Identity.ManagedIdentityId FromUserAssignedObjectId(string id) { throw null; }
public static Azure.Identity.ManagedIdentityId FromUserAssignedResourceId(Azure.Core.ResourceIdentifier id) { throw null; }
}
public partial class OnBehalfOfCredential : Azure.Core.TokenCredential
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Net;
using Azure.Core;

Expand Down Expand Up @@ -274,7 +275,7 @@ public string VisualStudioCodeTenantId

internal bool IsForceRefreshEnabled { get; set; }

internal override T Clone<T>()
internal override T Clone<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor | DynamicallyAccessedMemberTypes.NonPublicConstructors)] T>()
{
var clone = base.Clone<T>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,15 @@ public ManagedIdentityCredential(ResourceIdentifier resourceId, TokenCredentialO
/// <summary>
/// Creates an instance of <see cref="ManagedIdentityCredential"/> capable of authenticating using the specified <see cref="ManagedIdentityId"/>.
/// </summary>
/// <param name="managedIdentityId"></param>
public ManagedIdentityCredential(ManagedIdentityId managedIdentityId)
: this(new ManagedIdentityClient(new ManagedIdentityClientOptions { ManagedIdentityId = managedIdentityId, Pipeline = CredentialPipeline.GetInstance(null, IsManagedIdentityCredential: true), Options = null }))
{ }
/// <param name="id">The <see cref="ManagedIdentityId"/> specifying which managed identity will be configured.</param>
public ManagedIdentityCredential(ManagedIdentityId id)
: this(new ManagedIdentityClient(new ManagedIdentityClientOptions { ManagedIdentityId = id, Pipeline = CredentialPipeline.GetInstance(null, IsManagedIdentityCredential: true), Options = null }))
{
if (id == null)
{
Argument.AssertNotNull(id, nameof(id));
}
}

/// <summary>
/// Creates an instance of <see cref="ManagedIdentityCredential"/> configured with the specified options.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,20 @@ namespace Azure.Identity
/// </summary>
public class ManagedIdentityCredentialOptions : TokenCredentialOptions
{
internal ManagedIdentityCredentialOptions() : this(null)
{ }

/// <summary>
/// Creates an instance of <see cref="ManagedIdentityCredentialOptions"/>.
/// </summary>
/// <param name="managedIdentityId">The <see cref="ManagedIdentityId"/> specifying which managed identity will be configured. By default, <see cref="ManagedIdentityId.SystemAssigned"/> will be configured.</param>
public ManagedIdentityCredentialOptions(ManagedIdentityId managedIdentityId = null)
{
ManagedIdentityId = managedIdentityId ?? ManagedIdentityId.SystemAssigned;
}
/// <summary>
/// Specifies the configuration for the managed identity.
/// </summary>
public ManagedIdentityId ManagedIdentityId { get; set; }
internal ManagedIdentityId ManagedIdentityId { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using Azure.Core;

namespace Azure.Identity
Expand Down Expand Up @@ -46,10 +47,10 @@ public Uri AuthorityHost

internal TenantIdResolverBase TenantIdResolver { get; set; } = TenantIdResolverBase.Default;

internal virtual T Clone<T>()
where T : TokenCredentialOptions, new()
internal virtual T Clone<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor | DynamicallyAccessedMemberTypes.NonPublicConstructors)] T>()
where T : TokenCredentialOptions
{
T clone = new T();
T clone = (T)Activator.CreateInstance(typeof(T), true);

// copy TokenCredentialOptions Properties
clone.AuthorityHost = AuthorityHost;
Expand Down
18 changes: 9 additions & 9 deletions sdk/identity/Azure.Identity/src/ManagedIdentityId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,23 @@ private ManagedIdentityId(ManagedIdentityIdType idType, string userAssignedId =
/// <summary>
/// Create an instance of <see cref="ManagedIdentityId"/> for a user-assigned managed identity.
/// </summary>
/// <param name="clientId">The client ID of the user-assigned managed identity.</param>
public static ManagedIdentityId FromUserAssignedClientId(string clientId) =>
new ManagedIdentityId(ManagedIdentityIdType.ClientId, clientId);
/// <param name="id">The client ID of the user-assigned managed identity.</param>
public static ManagedIdentityId FromUserAssignedClientId(string id) =>
new ManagedIdentityId(ManagedIdentityIdType.ClientId, id);

/// <summary>
/// Create an instance of <see cref="ManagedIdentityId"/> for a user-assigned managed identity.
/// </summary>
/// <param name="resourceIdentifier">The resource identifier of the user-assigned managed identity.</param>
public static ManagedIdentityId FromUserAssignedResourceId(ResourceIdentifier resourceIdentifier) =>
new ManagedIdentityId(ManagedIdentityIdType.ResourceId, resourceIdentifier.ToString());
/// <param name="id">The resource ID of the user-assigned managed identity.</param>
public static ManagedIdentityId FromUserAssignedResourceId(ResourceIdentifier id) =>
new ManagedIdentityId(ManagedIdentityIdType.ResourceId, id.ToString());

/// <summary>
/// Create an instance of <see cref="ManagedIdentityId"/> for a user-assigned managed identity.
/// </summary>
/// <param name="objectId">The object ID of the user-assigned managed identity.</param>
public static ManagedIdentityId FromUserAssignedObjectId(string objectId) =>
new ManagedIdentityId(ManagedIdentityIdType.ObjectId, objectId);
/// <param name="id">The object ID of the user-assigned managed identity.</param>
public static ManagedIdentityId FromUserAssignedObjectId(string id) =>
new ManagedIdentityId(ManagedIdentityIdType.ObjectId, id);
}

internal enum ManagedIdentityIdType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public async Task GetManagedIdentityToken(ManagedIdentityIdType idType)
ManagedIdentityIdType.ObjectId => ManagedIdentityId.FromUserAssignedObjectId(TestEnvironment.VMUserAssignedManagedIdentityObjectId),
_ => ManagedIdentityId.SystemAssigned
};
ManagedIdentityCredentialOptions options = new ManagedIdentityCredentialOptions() { ManagedIdentityId = managedIdentityId };
ManagedIdentityCredentialOptions options = new ManagedIdentityCredentialOptions(managedIdentityId);

var cred = new ManagedIdentityCredential(options);
var token = await cred.GetTokenAsync(new(CredentialTestHelpers.DefaultScope));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ public void VerifyCloneHandlesISupportsForAllTypes(Type sourceType, Type destina
CollectionAssert.IsSubsetOf(iSupportsInterfaces, s_KnownISupportsInterfaces);

// create source instance and set values for all the supported intefaces
var source = Activator.CreateInstance(sourceType);
var source = Activator.CreateInstance(sourceType, true);

if (source is ISupportsAdditionallyAllowedTenants aat)
{
Expand Down

0 comments on commit 2029731

Please sign in to comment.