From 11fde206379775f9e8e544b82cbd08d55b49a816 Mon Sep 17 00:00:00 2001 From: Josh Lozensky Date: Thu, 30 Nov 2023 15:48:07 -0800 Subject: [PATCH] reducing config verbosity --- .../ManagedIdentityDescription.cs | 37 +++++++------------ .../ManagedIdentity/ManagedIdentitySource.cs | 23 ------------ ...UniqueIdType.cs => ManagedIdentityType.cs} | 15 +++++--- .../TokenAcquisition/AcquireTokenOptions.cs | 14 +++---- .../AquireTokenOptionsTests.cs | 24 +++++------- .../ManagedIdentityDescriptionTests.cs | 7 ++-- 6 files changed, 42 insertions(+), 78 deletions(-) delete mode 100644 src/Microsoft.Identity.Abstractions/ManagedIdentity/ManagedIdentitySource.cs rename src/Microsoft.Identity.Abstractions/ManagedIdentity/{ManagedIdentityUniqueIdType.cs => ManagedIdentityType.cs} (59%) diff --git a/src/Microsoft.Identity.Abstractions/ManagedIdentity/ManagedIdentityDescription.cs b/src/Microsoft.Identity.Abstractions/ManagedIdentity/ManagedIdentityDescription.cs index 8d19f30..9ab90d4 100644 --- a/src/Microsoft.Identity.Abstractions/ManagedIdentity/ManagedIdentityDescription.cs +++ b/src/Microsoft.Identity.Abstractions/ManagedIdentity/ManagedIdentityDescription.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Text; +using System.ComponentModel; namespace Microsoft.Identity.Abstractions { @@ -11,24 +8,18 @@ namespace Microsoft.Identity.Abstractions public class ManagedIdentityDescription { /// - /// Gets or sets the source of the managed identity as defined in . - /// Defaults to if not set. + /// Gets or sets the type of managed identity (and if applicable the unique id) as defined in + /// .Defaults to if not set. /// - [DefaultValue(ManagedIdentitySource.SystemAssigned)] - public ManagedIdentitySource Source { get; set; } + [DefaultValue(ManagedIdentityType.SystemAssigned)] + public ManagedIdentityType IdType { get; set; } - /// - /// Gets or sets the type of unique id to expect in the field. Only used when - /// is set to . - /// - public ManagedIdentityUniqueIdType? UniqueIdType { get; set; } /// - /// Gets or sets the value of the unique id correlated to the field for the - /// managed identity resource being described. Only used when is set to - /// . + /// Gets or sets the value of the unique id correlated to the field for the + /// managed identity resource being described. Only used when is set to a user-assigned option. /// - public string? UniqueIdValue { get; set; } + public string? IdValue { get; set; } /// /// Ensures a clone of this object will not have the same reference. @@ -38,9 +29,8 @@ public ManagedIdentityDescription Clone() { return new ManagedIdentityDescription { - Source = this.Source, - UniqueIdType = this.UniqueIdType, - UniqueIdValue = this.UniqueIdValue + IdType = this.IdType, + IdValue = this.IdValue }; } @@ -57,9 +47,8 @@ public override bool Equals(object obj) } ManagedIdentityDescription other = (ManagedIdentityDescription)obj; - return Source == other.Source && - UniqueIdType == other.UniqueIdType && - UniqueIdValue == other.UniqueIdValue; + return IdType == other.IdType && + IdValue == other.IdValue; } /// @@ -68,7 +57,7 @@ public override bool Equals(object obj) /// A 32-bit signed integer hash code. public override int GetHashCode() { - return new { Source, UniqueIdType, UniqueIdValue }.GetHashCode(); + return new { IdType, IdValue }.GetHashCode(); } } } diff --git a/src/Microsoft.Identity.Abstractions/ManagedIdentity/ManagedIdentitySource.cs b/src/Microsoft.Identity.Abstractions/ManagedIdentity/ManagedIdentitySource.cs deleted file mode 100644 index 6ea271b..0000000 --- a/src/Microsoft.Identity.Abstractions/ManagedIdentity/ManagedIdentitySource.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Microsoft.Identity.Abstractions -{ - /// - /// This is used to specify the source of managed identity the application should use in obtaining an app token. - /// For more info check out - /// - public enum ManagedIdentitySource - { - /// - /// Represents the system-assigned managed identity associated with an application. - /// - SystemAssigned = 0, - - /// - /// Represents a user-assigned managed identity created as an independent Azure resource and assigned to an application. - /// - UserAssigned = 1 - } -} diff --git a/src/Microsoft.Identity.Abstractions/ManagedIdentity/ManagedIdentityUniqueIdType.cs b/src/Microsoft.Identity.Abstractions/ManagedIdentity/ManagedIdentityType.cs similarity index 59% rename from src/Microsoft.Identity.Abstractions/ManagedIdentity/ManagedIdentityUniqueIdType.cs rename to src/Microsoft.Identity.Abstractions/ManagedIdentity/ManagedIdentityType.cs index f722f10..c21c244 100644 --- a/src/Microsoft.Identity.Abstractions/ManagedIdentity/ManagedIdentityUniqueIdType.cs +++ b/src/Microsoft.Identity.Abstractions/ManagedIdentity/ManagedIdentityType.cs @@ -5,24 +5,29 @@ namespace Microsoft.Identity.Abstractions { /// - /// + /// Used by /// - public enum ManagedIdentityUniqueIdType + public enum ManagedIdentityType { + /// + /// The default value, indicating that the managed identity will be the one assigned to the application. + /// + SystemAssigned = 0, + /// /// The Azure resource client Id of a user-assigned managed identity. /// - ClientId = 0, + UserAssignedClientId = 1, /// /// The Azure resource object Id of a user-assigned managed identity. /// - ObjectId = 1, + UserAssignedObjectId = 2, /// /// The host resource Id of a user-assigned managed identity. /// - HostResourceId = 2 + UserAssignedHostResourceId = 3 } } diff --git a/src/Microsoft.Identity.Abstractions/TokenAcquisition/AcquireTokenOptions.cs b/src/Microsoft.Identity.Abstractions/TokenAcquisition/AcquireTokenOptions.cs index 35596c4..ceb3c6f 100644 --- a/src/Microsoft.Identity.Abstractions/TokenAcquisition/AcquireTokenOptions.cs +++ b/src/Microsoft.Identity.Abstractions/TokenAcquisition/AcquireTokenOptions.cs @@ -95,13 +95,11 @@ public AcquireTokenOptions(AcquireTokenOptions other) /// When is set, the application uses a managed identity instead of client credentials to /// acquire an app token.

/// - /// The source of a managed identity is defined by the - /// field, when using a identity, this is the only field that needs to - /// be set.

+ /// The type of a managed identity is defined by the field, when using a + /// identity, this is the only field that needs to be set.

/// - /// To use a identity as the source, the - /// and - /// fields must also be set.

+ /// To use a user-assigned identity, select the that corresponds to the + /// you plan to use for authentication.

/// /// Using either form of managed identity requires the application to be deployed on Azure and /// the managed identity to be configured. For more details, check the @@ -124,8 +122,8 @@ public AcquireTokenOptions(AcquireTokenOptions other) /// ]]> /// /// - /// If the field is set with no further details provided, the application will default to using the - /// system-assigned managed identity. + /// If the field is set with no further details provided, the application will default to + /// using the system-assigned managed identity. /// public ManagedIdentityDescription? ManagedIdentity { get; set; } diff --git a/test/Microsoft.Identity.Abstractions.Tests/AquireTokenOptionsTests.cs b/test/Microsoft.Identity.Abstractions.Tests/AquireTokenOptionsTests.cs index ddea31e..c10157e 100644 --- a/test/Microsoft.Identity.Abstractions.Tests/AquireTokenOptionsTests.cs +++ b/test/Microsoft.Identity.Abstractions.Tests/AquireTokenOptionsTests.cs @@ -15,7 +15,7 @@ public void ManagedIdentitySystemAssigned() { "AquireTokenOptions": { "ManagedIdentity": { - "Source": "SystemAssigned" + "IdType": "SystemAssigned" } } } @@ -25,7 +25,7 @@ public void ManagedIdentitySystemAssigned() // ManagedIdentityDescription managedIdentityDescription = new ManagedIdentityDescription { - Source = ManagedIdentitySource.SystemAssigned + IdType = ManagedIdentityType.SystemAssigned }; AcquireTokenOptions acquireTokenOptions = new AcquireTokenOptions @@ -34,9 +34,8 @@ public void ManagedIdentitySystemAssigned() }; // - Assert.Equal(ManagedIdentitySource.SystemAssigned, acquireTokenOptions.ManagedIdentity.Source); - Assert.Null(acquireTokenOptions.ManagedIdentity.UniqueIdType); - Assert.Null(acquireTokenOptions.ManagedIdentity.UniqueIdValue); + Assert.Equal(ManagedIdentityType.SystemAssigned, acquireTokenOptions.ManagedIdentity.IdType); + Assert.Null(acquireTokenOptions.ManagedIdentity.IdValue); } [Fact] @@ -50,9 +49,8 @@ public void ManagedIdentityUserAssigned() { "AquireTokenOptions": { "ManagedIdentity": { - "Source": "UserAssigned" - "UniqueIdType": "ClientId" - "UniqueIdValue": "[InsertRelevantValueForTheManagedIdentityResource]" + "IdType": "UserAssignedClientId" + "IdValue": "[InsertRelevantValueForTheManagedIdentityResource]" } } } @@ -62,9 +60,8 @@ public void ManagedIdentityUserAssigned() // ManagedIdentityDescription managedIdentityDescription = new ManagedIdentityDescription { - Source = ManagedIdentitySource.UserAssigned, - UniqueIdType = ManagedIdentityUniqueIdType.ClientId, - UniqueIdValue = "[InsertRelevantValueForTheManagedIdentityResource]" + IdType = ManagedIdentityType.UserAssignedClientId, + IdValue = "[InsertRelevantValueForTheManagedIdentityResource]" }; AcquireTokenOptions acquireTokenOptions = new AcquireTokenOptions @@ -73,9 +70,8 @@ public void ManagedIdentityUserAssigned() }; // - Assert.Equal(ManagedIdentitySource.UserAssigned, acquireTokenOptions.ManagedIdentity.Source); - Assert.Equal(ManagedIdentityUniqueIdType.ClientId, acquireTokenOptions.ManagedIdentity.UniqueIdType); - Assert.Equal(managedIdentityDescription.UniqueIdValue, acquireTokenOptions.ManagedIdentity.UniqueIdValue); + Assert.Equal(ManagedIdentityType.UserAssignedClientId, acquireTokenOptions.ManagedIdentity.IdType); + Assert.Equal(managedIdentityDescription.IdValue, acquireTokenOptions.ManagedIdentity.IdValue); } } } diff --git a/test/Microsoft.Identity.Abstractions.Tests/ManagedIdentityDescriptionTests.cs b/test/Microsoft.Identity.Abstractions.Tests/ManagedIdentityDescriptionTests.cs index 27d0e92..33a146b 100644 --- a/test/Microsoft.Identity.Abstractions.Tests/ManagedIdentityDescriptionTests.cs +++ b/test/Microsoft.Identity.Abstractions.Tests/ManagedIdentityDescriptionTests.cs @@ -5,7 +5,7 @@ namespace Microsoft.Identity.Abstractions.Tests public class ManagedIdentityDescriptionTests { /// - /// If no field is set for the + /// If no field is set for the /// field needs to default to as other Microsoft.Identity libraries /// will depend on this. /// @@ -16,9 +16,8 @@ public void ManagedIdentity_NoDescriptionFieldsSet() ManagedIdentityDescription description = new(); // Assert - Assert.Equal(ManagedIdentitySource.SystemAssigned, description.Source); - Assert.Null(description.UniqueIdType); - Assert.Null(description.UniqueIdValue); + Assert.Equal(ManagedIdentityType.SystemAssigned, description.IdType); + Assert.Null(description.IdValue); } } }