Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
<MicrosoftIdentityWebVersion Condition="'$(MicrosoftIdentityWebVersion)' == ''">4.3.1</MicrosoftIdentityWebVersion>
<!--This will generate AssemblyVersion, AssemblyFileVersion and AssemblyInformationVersion-->
<Version>$(MicrosoftIdentityWebVersion)</Version>

<EnablePackageValidation>true</EnablePackageValidation>
<PackageValidationBaselineVersion>4.2.0</PackageValidationBaselineVersion>

<BuildDirectory>$(MSBuildThisFileDirectory)/build</BuildDirectory>
<AssemblyOriginatorKeyFile>$(BuildDirectory)/35MSSharedLib1024.snk</AssemblyOriginatorKeyFile>
<RepositoryType>git</RepositoryType>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1228,13 +1228,11 @@ private void NotifyCertificateSelection(
string? tokenUsedToCallTheWebApi = GetActualToken(validatedToken);

AcquireTokenOnBehalfOfParameterBuilder? builder = null;
TokenAcquisitionExtensionOptions? addInOptions = null;
TokenAcquisitionExtensionOptions? addInOptions = tokenAcquisitionExtensionOptionsMonitor?.CurrentValue;

// Case of web APIs: we need to do an on-behalf-of flow, with the token used to call the API
if (tokenUsedToCallTheWebApi != null)
{
addInOptions = tokenAcquisitionExtensionOptionsMonitor?.CurrentValue;

if (string.IsNullOrEmpty(tokenAcquisitionOptions?.LongRunningWebApiSessionKey))
{
builder = application
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,20 @@ public async Task LongRunningSessionForDefaultAuthProviderForUserDefaultKeyTest(
var claimsPrincipal = new ClaimsPrincipal(identity);

var tokenAcquirerFactory = InitTokenAcquirerFactoryForTest();
bool argsNotNull = true;

// Configure the extension option such that the event is subscribed to
// so the test can observe if the service provider is set in the extra parameters
tokenAcquirerFactory.Services.Configure<TokenAcquisitionExtensionOptions>(options =>
{
options.OnBeforeTokenAcquisitionForOnBehalfOf += (builder, options, args) =>
{
//verify that the ClaimsPrincipal passed in the event is the same as the one passed to CreateAuthorizationHeaderForUserAsync and that the BootstrapContext is preserved
Assert.Equal(((CaseSensitiveClaimsIdentity)claimsPrincipal.Identity!).BootstrapContext, ((CaseSensitiveClaimsIdentity)args?.User?.Identity!).BootstrapContext);
Assert.Equal(((CaseSensitiveClaimsIdentity)claimsPrincipal.Identity!).BootstrapContext, args.UserAssertionToken);
if (argsNotNull)
{
//verify that the ClaimsPrincipal passed in the event is the same as the one passed to CreateAuthorizationHeaderForUserAsync and that the BootstrapContext is preserved
Assert.Equal(((CaseSensitiveClaimsIdentity)claimsPrincipal.Identity!).BootstrapContext, ((CaseSensitiveClaimsIdentity)args?.User?.Identity!).BootstrapContext);
Assert.Equal(((CaseSensitiveClaimsIdentity)claimsPrincipal.Identity!).BootstrapContext, args.UserAssertionToken);
}
};
});
IServiceProvider serviceProvider = tokenAcquirerFactory.Build();
Expand All @@ -57,8 +61,6 @@ public async Task LongRunningSessionForDefaultAuthProviderForUserDefaultKeyTest(

using (mockHttpClient)
{


// Create options with LongRunningWebApiSessionKey
var options = new AuthorizationHeaderProviderOptions
{
Expand All @@ -85,6 +87,7 @@ public async Task LongRunningSessionForDefaultAuthProviderForUserDefaultKeyTest(
string key1 = options.AcquireTokenOptions.LongRunningWebApiSessionKey;

// Step 4: Second call without ClaimsPrincipal should return the token from cache
argsNotNull = false;
result = await authorizationHeaderProvider.CreateAuthorizationHeaderForUserAsync(
scopes,
options);
Expand All @@ -94,6 +97,7 @@ public async Task LongRunningSessionForDefaultAuthProviderForUserDefaultKeyTest(
Assert.Equal(key1, options.AcquireTokenOptions.LongRunningWebApiSessionKey);

// Step 5: First call with ClaimsPrincipal to initiate LR session for CreateAuthorizationHeaderAsync
argsNotNull = true;
scopes = new[] { "User.Write" };
mockHttpClient!.AddMockHandler(MockHttpCreator.CreateLrOboTokenHandler("User.Write"));
result = await authorizationHeaderProvider.CreateAuthorizationHeaderAsync(
Expand All @@ -105,6 +109,7 @@ public async Task LongRunningSessionForDefaultAuthProviderForUserDefaultKeyTest(
Assert.NotEqual(options.AcquireTokenOptions.LongRunningWebApiSessionKey, TokenAcquisitionOptions.LongRunningWebApiSessionKeyAuto);
key1 = options.AcquireTokenOptions.LongRunningWebApiSessionKey;

argsNotNull = false;
// Step 6: Second call without ClaimsPrincipal should return the token from cache for CreateAuthorizationHeaderAsync
result = await authorizationHeaderProvider.CreateAuthorizationHeaderAsync(
scopes,
Expand Down
Loading