Skip to content

Commit

Permalink
Lozensky/add fmi path (#161)
Browse files Browse the repository at this point in the history
* Added FmiPath member to AcquireTokenOptions
* Add test for FMI path
  • Loading branch information
JoshLozensky authored Feb 12, 2025
1 parent bcdd33a commit d7bbd42
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
#nullable enable
Microsoft.Identity.Abstractions.AcquireTokenOptions.FmiPath.get -> string?
Microsoft.Identity.Abstractions.AcquireTokenOptions.FmiPath.set -> void
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
#nullable enable
Microsoft.Identity.Abstractions.AcquireTokenOptions.FmiPath.get -> string?
Microsoft.Identity.Abstractions.AcquireTokenOptions.FmiPath.set -> void
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
#nullable enable
Microsoft.Identity.Abstractions.AcquireTokenOptions.FmiPath.get -> string?
Microsoft.Identity.Abstractions.AcquireTokenOptions.FmiPath.set -> void
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
#nullable enable
Microsoft.Identity.Abstractions.AcquireTokenOptions.FmiPath.get -> string?
Microsoft.Identity.Abstractions.AcquireTokenOptions.FmiPath.set -> void
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public AcquireTokenOptions(AcquireTokenOptions other)
ExtraHeadersParameters = other.ExtraHeadersParameters;
ExtraParameters = other.ExtraParameters;
ForceRefresh = other.ForceRefresh;
FmiPath = other.FmiPath;
Claims = other.Claims;
PopPublicKey = other.PopPublicKey;
PopClaim = other.PopClaim;
Expand Down Expand Up @@ -81,6 +82,11 @@ public AcquireTokenOptions(AcquireTokenOptions other)
/// </summary>
public string? Claims { get; set; }

/// <summary>
/// Federated Managed Identity (FMI) sub-path.
/// </summary>
public string? FmiPath { get; set; }

/// <summary>
/// Specifies if the token request will ignore the access token in the token cache
/// and will attempt to acquire a new access token.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,31 @@ public void ManagedIdentityUserAssigned()
Assert.NotNull(acquireTokenOptions.ManagedIdentity);
Assert.Equal(managedIdentityOptions.UserAssignedClientId, acquireTokenOptions.ManagedIdentity.UserAssignedClientId);
}

[Fact]
public void FmiPathTest()
{
// App token from a Federated Managed Identity (FMI).
// -------------------------------------------------
/*
// <fmipath_json>
{
"AquireTokenOptions": {
"FmiPath": "/example.org/service/my-service"
}
}
// </fmipath_json>
*/

// <fmipath_csharp>
AcquireTokenOptions acquireTokenOptions = new AcquireTokenOptions
{
FmiPath = "/example.org/service/my-service"
};
// </fmipath_csharp>

Assert.NotNull(acquireTokenOptions.FmiPath);
Assert.Equal("/example.org/service/my-service", acquireTokenOptions.FmiPath);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public void Secret()
[Fact]
public void SignedAssertionFromMSI()
{
// Signed assertion from Managed identity federation
// Signed assertion from Federation Identity Credential (Managed Identity)
// -------------------------------------------------
// https://learn.microsoft.com/azure/active-directory/develop/workload-identity-federation
/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public void CloneClonesAllProperties()
ExtraHeadersParameters = new Dictionary<string, string> { { "slice", "test" } },
ExtraQueryParameters = new Dictionary<string, string> { { "slice", "test" } },
ExtraParameters = new Dictionary<string, object> { { "param1", "value1" }, { "param2", "value2" } },
FmiPath = "fmiPath",
ForceRefresh = true,
LongRunningWebApiSessionKey = AcquireTokenOptions.LongRunningWebApiSessionKeyAuto,
ManagedIdentity = new ManagedIdentityOptions(),
Expand Down Expand Up @@ -83,6 +84,7 @@ public void CloneClonesAllProperties()
Assert.Equal(downstreamApiOptions.AcquireTokenOptions.ExtraHeadersParameters, downstreamApiClone.AcquireTokenOptions.ExtraHeadersParameters);
Assert.Equal(downstreamApiOptions.AcquireTokenOptions.ExtraQueryParameters, downstreamApiClone.AcquireTokenOptions.ExtraQueryParameters);
Assert.Equal(downstreamApiOptions.AcquireTokenOptions.ExtraParameters, downstreamApiClone.AcquireTokenOptions.ExtraParameters);
Assert.Equal(downstreamApiOptions.AcquireTokenOptions.FmiPath, downstreamApiClone.AcquireTokenOptions.FmiPath);
Assert.Equal(downstreamApiOptions.AcquireTokenOptions.ForceRefresh, downstreamApiClone.AcquireTokenOptions.ForceRefresh);
Assert.Equal(downstreamApiOptions.AcquireTokenOptions.LongRunningWebApiSessionKey, downstreamApiClone.AcquireTokenOptions.LongRunningWebApiSessionKey);
Assert.Equal(downstreamApiOptions.AcquireTokenOptions.ManagedIdentity.UserAssignedClientId, downstreamApiClone.AcquireTokenOptions.ManagedIdentity?.UserAssignedClientId);
Expand All @@ -95,7 +97,7 @@ public void CloneClonesAllProperties()

// If this fails, think of also adding a line to test the new property
Assert.Equal(12, typeof(DownstreamApiOptions).GetProperties().Length);
Assert.Equal(14, typeof(AcquireTokenOptions).GetProperties().Length);
Assert.Equal(15, typeof(AcquireTokenOptions).GetProperties().Length);

DownstreamApiOptionsReadOnlyHttpMethod options = new DownstreamApiOptionsReadOnlyHttpMethod(downstreamApiOptions, HttpMethod.Delete.ToString());
Assert.Equal(HttpMethod.Delete.ToString(), options.HttpMethod);
Expand Down

0 comments on commit d7bbd42

Please sign in to comment.