Skip to content

Commit 4ab0e3b

Browse files
trwalketrwalkegladjohnbgavrilMS
authored
Add WithFmiPath to MSAL (#5114)
* Adding cache logic for additional components * Adding logging. Adding tests. * Resolving test * Clean Up * Resolving cache key issues. Adding test cases. * Updating public api * Remove unused using directive * Adding credential type test * Updating public api files * Apply suggestions from code review Co-authored-by: Gladwin Johnson <[email protected]> * Update tests/Microsoft.Identity.Test.Unit/PublicApiTests/CacheKeyExtensionTests.cs Co-authored-by: Gladwin Johnson <[email protected]> * Addressing feedback. clean up. refactoring * Adding pop test Refactoring Clean up * Adding additional test * Adding WithFmiPath api * Update src/client/Microsoft.Identity.Client/ApiConfig/AcquireTokenForClientParameterBuilder.cs Co-authored-by: Bogdan Gavril <[email protected]> * Adding WithFmiPath api and test * Adding test case * Adding comment * Refactoring * Apply suggestions from code review Co-authored-by: Gladwin Johnson <[email protected]> --------- Co-authored-by: trwalke <[email protected]> Co-authored-by: Gladwin Johnson <[email protected]> Co-authored-by: Bogdan Gavril <[email protected]>
1 parent 6ff1aa7 commit 4ab0e3b

File tree

13 files changed

+109
-2
lines changed

13 files changed

+109
-2
lines changed

src/client/Microsoft.Identity.Client/ApiConfig/AcquireTokenForClientParameterBuilder.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
using Microsoft.Identity.Client.Internal.ClientCredential;
1515
using Microsoft.Identity.Client.TelemetryCore.Internal.Events;
1616
using Microsoft.Identity.Client.Utils;
17+
using Microsoft.Identity.Client.Extensibility;
18+
using Microsoft.Identity.Client.OAuth2;
1719

1820
namespace Microsoft.Identity.Client
1921
{
@@ -122,6 +124,30 @@ public AcquireTokenForClientParameterBuilder WithPreferredAzureRegion(bool useAz
122124
throw new NotImplementedException();
123125
}
124126

127+
/// <summary>
128+
/// Adds an fmi_path parameter to the request. It modifies the subject of the token.
129+
/// </summary>
130+
public AcquireTokenForClientParameterBuilder WithFmiPath(string pathSuffix)
131+
{
132+
ValidateUseOfExperimentalFeature();
133+
134+
if (string.IsNullOrWhiteSpace(pathSuffix))
135+
{
136+
throw new ArgumentNullException(nameof(pathSuffix));
137+
}
138+
139+
var cacheKey = new SortedList<string, string>
140+
{
141+
{ OAuth2Parameter.FmiPath, pathSuffix }
142+
};
143+
144+
this.WithAdditionalCacheKeyComponents(cacheKey);
145+
146+
CommonParameters.FmiPathSuffix = pathSuffix;
147+
148+
return this;
149+
}
150+
125151
/// <inheritdoc/>
126152
internal override Task<AuthenticationResult> ExecuteInternalAsync(CancellationToken cancellationToken)
127153
{

src/client/Microsoft.Identity.Client/ApiConfig/Parameters/AcquireTokenCommonParameters.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,6 @@ internal class AcquireTokenCommonParameters
3131
public X509Certificate2 MtlsCertificate { get; internal set; }
3232
public List<string> AdditionalCacheParameters { get; set; }
3333
public SortedList<string, string> CacheKeyComponents { get; internal set; }
34+
public string FmiPathSuffix { get; internal set; }
3435
}
3536
}

src/client/Microsoft.Identity.Client/Internal/Requests/AuthenticationRequestParameters.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ public string LoginHint
175175
public string LongRunningOboCacheKey { get; set; }
176176

177177
public KeyValuePair<string, string>? CcsRoutingHint { get; set; }
178+
179+
public string FmiPathSuffix => _commonParameters.FmiPathSuffix;
178180
#endregion
179181

180182
public void LogParameters()

src/client/Microsoft.Identity.Client/OAuth2/OAuthConstants.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ internal static class OAuth2Parameter
4343
public const string TokenType = "token_type"; // not a standard OAuth2 param
4444
public const string RequestConfirmation = "req_cnf"; // not a standard OAuth2 param
4545
public const string SpaCode = "return_spa_code"; // not a standard OAuth2 param
46+
public const string FmiPath = "fmi_path"; // not a standard OAuth2 param
4647
}
4748

4849
internal static class OAuth2GrantType

src/client/Microsoft.Identity.Client/OAuth2/TokenClient.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public async Task<MsalTokenResponse> SendTokenRequestAsync(
5656
{
5757
tokenEndpoint = await _requestParams.Authority.GetTokenEndpointAsync(_requestParams.RequestContext).ConfigureAwait(false);
5858
}
59+
5960
Debug.Assert(_requestParams.RequestContext.ApiEvent != null, "The Token Client must only be called by requests.");
6061
_requestParams.RequestContext.ApiEvent.TokenEndpoint = tokenEndpoint;
6162

@@ -163,6 +164,11 @@ await _serviceBundle.Config.ClientCredential.AddConfidentialClientParametersAsyn
163164
_oAuth2Client.AddBodyParameter(kvp.Key, kvp.Value);
164165
}
165166

167+
if (!string.IsNullOrEmpty(_requestParams.FmiPathSuffix))
168+
{
169+
_oAuth2Client.AddBodyParameter(OAuth2Parameter.FmiPath, _requestParams.FmiPathSuffix);
170+
}
171+
166172
_oAuth2Client.AddHeader(
167173
TelemetryConstants.XClientCurrentTelemetry,
168174
_serviceBundle.HttpTelemetryManager.GetCurrentRequestHeader(
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Microsoft.Identity.Client.AcquireTokenForClientParameterBuilder.WithFmiPath(string pathSuffix) -> Microsoft.Identity.Client.AcquireTokenForClientParameterBuilder
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Microsoft.Identity.Client.AcquireTokenForClientParameterBuilder.WithFmiPath(string pathSuffix) -> Microsoft.Identity.Client.AcquireTokenForClientParameterBuilder
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Microsoft.Identity.Client.AcquireTokenForClientParameterBuilder.WithFmiPath(string pathSuffix) -> Microsoft.Identity.Client.AcquireTokenForClientParameterBuilder
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Microsoft.Identity.Client.AcquireTokenForClientParameterBuilder.WithFmiPath(string pathSuffix) -> Microsoft.Identity.Client.AcquireTokenForClientParameterBuilder
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Microsoft.Identity.Client.AcquireTokenForClientParameterBuilder.WithFmiPath(string pathSuffix) -> Microsoft.Identity.Client.AcquireTokenForClientParameterBuilder

0 commit comments

Comments
 (0)