Skip to content

Commit

Permalink
reducing config verbosity
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshLozensky committed Nov 30, 2023
1 parent 0f987fa commit 11fde20
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 78 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.ComponentModel;

namespace Microsoft.Identity.Abstractions
{
Expand All @@ -11,24 +8,18 @@ namespace Microsoft.Identity.Abstractions
public class ManagedIdentityDescription
{
/// <summary>
/// Gets or sets the source of the managed identity as defined in <see cref="ManagedIdentitySource"/>.
/// Defaults to <see cref="ManagedIdentitySource.SystemAssigned"/> if not set.
/// Gets or sets the type of managed identity (and if applicable the unique id) as defined in
/// <see cref="ManagedIdentityType"/>.Defaults to <see cref="ManagedIdentityType.SystemAssigned"/> if not set.
/// </summary>
[DefaultValue(ManagedIdentitySource.SystemAssigned)]
public ManagedIdentitySource Source { get; set; }
[DefaultValue(ManagedIdentityType.SystemAssigned)]
public ManagedIdentityType IdType { get; set; }

/// <summary>
/// Gets or sets the type of unique id to expect in the <see cref="UniqueIdValue"/> field. Only used when
/// <see cref="Source"/> is set to <see cref="ManagedIdentitySource.UserAssigned"/>.
/// </summary>
public ManagedIdentityUniqueIdType? UniqueIdType { get; set; }

/// <summary>
/// Gets or sets the value of the unique id correlated to the <see cref="UniqueIdType"/> field for the
/// managed identity resource being described. Only used when <see cref="Source"/> is set to
/// <see cref="ManagedIdentitySource.UserAssigned"/>.
/// Gets or sets the value of the unique id correlated to the <see cref="IdType"/> field for the
/// managed identity resource being described. Only used when <see cref="IdType"/> is set to a user-assigned option.
/// </summary>
public string? UniqueIdValue { get; set; }
public string? IdValue { get; set; }

/// <summary>
/// Ensures a clone of this object will not have the same reference.
Expand All @@ -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
};
}

Expand All @@ -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;
}

/// <summary>
Expand All @@ -68,7 +57,7 @@ public override bool Equals(object obj)
/// <returns>A 32-bit signed integer hash code.</returns>
public override int GetHashCode()
{
return new { Source, UniqueIdType, UniqueIdValue }.GetHashCode();
return new { IdType, IdValue }.GetHashCode();
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,29 @@
namespace Microsoft.Identity.Abstractions
{
/// <summary>
///
/// Used by
/// </summary>
public enum ManagedIdentityUniqueIdType
public enum ManagedIdentityType

{
/// <summary>
/// The default value, indicating that the managed identity will be the one assigned to the application.
/// </summary>
SystemAssigned = 0,

/// <summary>
/// The Azure resource client Id of a user-assigned managed identity.
/// </summary>
ClientId = 0,
UserAssignedClientId = 1,

/// <summary>
/// The Azure resource object Id of a user-assigned managed identity.
/// </summary>
ObjectId = 1,
UserAssignedObjectId = 2,

/// <summary>
/// The host resource Id of a user-assigned managed identity.
/// </summary>
HostResourceId = 2
UserAssignedHostResourceId = 3
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,11 @@ public AcquireTokenOptions(AcquireTokenOptions other)
/// When <see cref="ManagedIdentity"/> is set, the application uses a managed identity instead of client credentials to
/// acquire an app token.<br/><br/>
///
/// The source of a managed identity is defined by the <see cref="ManagedIdentityDescription.Source"/>
/// field, when using a <see cref="ManagedIdentitySource.SystemAssigned"/> identity, this is the only field that needs to
/// be set. <br/><br/>
/// The type of a managed identity is defined by the <see cref="ManagedIdentityDescription.IdType"/> field, when using a
/// <see cref="ManagedIdentityType.SystemAssigned"/> identity, this is the only field that needs to be set.<br/><br/>
///
/// To use a <see cref="ManagedIdentitySource.UserAssigned"/> identity as the source, the
/// <see cref="ManagedIdentityDescription.UniqueIdType"/> and <see cref="ManagedIdentityDescription.UniqueIdValue"/>
/// fields must also be set. <br/><br/>
/// To use a user-assigned identity, select the <see cref="ManagedIdentityType"/> that corresponds to the
/// <see cref="ManagedIdentityDescription.IdValue"/> you plan to use for authentication.<br/><br/>
///
/// 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
Expand All @@ -124,8 +122,8 @@ public AcquireTokenOptions(AcquireTokenOptions other)
/// ]]></format>
/// </example>
/// <remarks>
/// If the <see cref="ManagedIdentity"/> field is set with no further details provided, the application will default to using the
/// system-assigned managed identity.
/// If the <see cref="ManagedIdentity"/> field is set with no further details provided, the application will default to
/// using the system-assigned managed identity.
/// </remarks>
public ManagedIdentityDescription? ManagedIdentity { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public void ManagedIdentitySystemAssigned()
{
"AquireTokenOptions": {
"ManagedIdentity": {
"Source": "SystemAssigned"
"IdType": "SystemAssigned"
}
}
}
Expand All @@ -25,7 +25,7 @@ public void ManagedIdentitySystemAssigned()
// <managedidentity_csharp>
ManagedIdentityDescription managedIdentityDescription = new ManagedIdentityDescription
{
Source = ManagedIdentitySource.SystemAssigned
IdType = ManagedIdentityType.SystemAssigned
};

AcquireTokenOptions acquireTokenOptions = new AcquireTokenOptions
Expand All @@ -34,9 +34,8 @@ public void ManagedIdentitySystemAssigned()
};
// </managedidentitysystem_csharp>

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]
Expand All @@ -50,9 +49,8 @@ public void ManagedIdentityUserAssigned()
{
"AquireTokenOptions": {
"ManagedIdentity": {
"Source": "UserAssigned"
"UniqueIdType": "ClientId"
"UniqueIdValue": "[InsertRelevantValueForTheManagedIdentityResource]"
"IdType": "UserAssignedClientId"
"IdValue": "[InsertRelevantValueForTheManagedIdentityResource]"
}
}
}
Expand All @@ -62,9 +60,8 @@ public void ManagedIdentityUserAssigned()
// <managedidentityuser_csharp>
ManagedIdentityDescription managedIdentityDescription = new ManagedIdentityDescription
{
Source = ManagedIdentitySource.UserAssigned,
UniqueIdType = ManagedIdentityUniqueIdType.ClientId,
UniqueIdValue = "[InsertRelevantValueForTheManagedIdentityResource]"
IdType = ManagedIdentityType.UserAssignedClientId,
IdValue = "[InsertRelevantValueForTheManagedIdentityResource]"
};

AcquireTokenOptions acquireTokenOptions = new AcquireTokenOptions
Expand All @@ -73,9 +70,8 @@ public void ManagedIdentityUserAssigned()
};
// </managedidentityuser_csharp>

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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Microsoft.Identity.Abstractions.Tests
public class ManagedIdentityDescriptionTests
{
/// <summary>
/// If no field is set for <see cref="ManagedIdentityDescription"/> the <see cref="ManagedIdentityDescription.Source"/>
/// If no field is set for <see cref="ManagedIdentityDescription"/> the <see cref="ManagedIdentityDescription.IdType"/>
/// field needs to default to <see cref="ManagedIdentitySource.SystemAssigned"/> as other Microsoft.Identity libraries
/// will depend on this.
/// </summary>
Expand All @@ -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);
}
}
}

0 comments on commit 11fde20

Please sign in to comment.