Skip to content

Commit d54745c

Browse files
author
Keegan Caruso
committed
Don't mutate options, but instread keep changes in new prop
1 parent e476a7c commit d54745c

File tree

10 files changed

+27
-314
lines changed

10 files changed

+27
-314
lines changed

src/Microsoft.Identity.Web.TokenAcquisition/MergedOptions.cs

Lines changed: 8 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -55,127 +55,12 @@ public ConfidentialClientApplicationOptions ConfidentialClientApplicationOptions
5555
// This is for supporting for CIAM authorities including custom url domains, see https://github.com/AzureAD/microsoft-identity-web/issues/2690
5656
internal bool PreserveAuthority { get; set; }
5757

58-
internal MergedOptions()
59-
{
60-
61-
}
62-
63-
internal MergedOptions(MergedOptions other)
64-
{
65-
_confidentialClientApplicationOptions = other._confidentialClientApplicationOptions;
66-
AadAuthorityAudience = other.AadAuthorityAudience;
67-
AppHomeTenantId = other.AppHomeTenantId;
68-
AzureCloudInstance = other.AzureCloudInstance;
69-
AzureRegion = other.AzureRegion;
70-
ClientCapabilities = other.ClientCapabilities?.ToList();
71-
ClientName = other.ClientName;
72-
ClientVersion = other.ClientVersion;
73-
Component = other.Component;
74-
EnablePiiLogging = other.EnablePiiLogging;
75-
IsDefaultPlatformLoggingEnabled = other.IsDefaultPlatformLoggingEnabled;
76-
LogLevel = other.LogLevel;
77-
RedirectUri = other.RedirectUri;
78-
EnableCacheSynchronization = other.EnableCacheSynchronization;
79-
MergedWithCca = other.MergedWithCca;
80-
PreserveAuthority = other.PreserveAuthority;
81-
82-
// Copy properties from MicrosoftIdentityOptions
83-
Instance = other.Instance;
84-
TenantId = other.TenantId;
85-
Domain = other.Domain;
86-
EditProfilePolicyId = other.EditProfilePolicyId;
87-
SignUpSignInPolicyId = other.SignUpSignInPolicyId;
88-
ResetPasswordPolicyId = other.ResetPasswordPolicyId;
89-
LegacyCacheCompatibilityEnabled = other.LegacyCacheCompatibilityEnabled;
90-
ClientCertificates = other.ClientCertificates?.ToList();
91-
TokenDecryptionCertificates = other.TokenDecryptionCertificates?.ToList();
92-
ClientCredentials = other.ClientCredentials?.ToList();
93-
TokenDecryptionCredentials = other.TokenDecryptionCredentials?.ToList();
94-
SendX5C = other.SendX5C;
95-
WithSpaAuthCode = other.WithSpaAuthCode;
96-
AllowWebApiToBeAuthorizedByACL = other.AllowWebApiToBeAuthorizedByACL;
97-
UserAssignedManagedIdentityClientId = other.UserAssignedManagedIdentityClientId;
98-
ClientCredentialsUsingManagedIdentity = other.ClientCredentialsUsingManagedIdentity;
99-
ResetPasswordPath = other.ResetPasswordPath;
100-
ErrorPath = other.ErrorPath;
101-
ExtraQueryParameters = other.ExtraQueryParameters?.ToDictionary(entry => entry.Key, entry => entry.Value);
58+
/// <summary>
59+
/// Id Web will modify the instance so that it can be used by MSAL.
60+
/// This modifies this property so that the original value is not changed.
61+
/// </summary>
62+
internal string? PreparedInstance { get; set; }
10263

103-
#if !NETSTANDARD2_0 && !NETFRAMEWORK
104-
// OpenIdConnectOptions
105-
Authority = other.Authority;
106-
ClientId = other.ClientId;
107-
ClientSecret = other.ClientSecret;
108-
Configuration = other.Configuration;
109-
ConfigurationManager = other.ConfigurationManager;
110-
GetClaimsFromUserInfoEndpoint = other.GetClaimsFromUserInfoEndpoint;
111-
RequireHttpsMetadata = other.RequireHttpsMetadata;
112-
MetadataAddress = other.MetadataAddress;
113-
Events = other.Events;
114-
MaxAge = other.MaxAge;
115-
ProtocolValidator = other.ProtocolValidator;
116-
SignedOutCallbackPath = other.SignedOutCallbackPath;
117-
SignedOutRedirectUri = other.SignedOutRedirectUri;
118-
RefreshOnIssuerKeyNotFound = other.RefreshOnIssuerKeyNotFound;
119-
AuthenticationMethod = other.AuthenticationMethod;
120-
this.Resource = other.Resource;
121-
ResponseMode = other.ResponseMode;
122-
ResponseType = other.ResponseType;
123-
Prompt = other.Prompt;
124-
RemoteSignOutPath = other.RemoteSignOutPath;
125-
SignOutScheme = other.SignOutScheme;
126-
StateDataFormat = other.StateDataFormat;
127-
StringDataFormat = other.StringDataFormat;
128-
#pragma warning disable CS0618
129-
SecurityTokenValidator = other.SecurityTokenValidator;
130-
#pragma warning restore CS0618
131-
TokenValidationParameters = other.TokenValidationParameters;
132-
UseTokenLifetime = other.UseTokenLifetime;
133-
SkipUnrecognizedRequests = other.SkipUnrecognizedRequests;
134-
DisableTelemetry = other.DisableTelemetry;
135-
NonceCookie = other.NonceCookie;
136-
UsePkce = other.UsePkce;
137-
AutomaticRefreshInterval = other.AutomaticRefreshInterval;
138-
RefreshInterval = other.RefreshInterval;
139-
MapInboundClaims = other.MapInboundClaims;
140-
141-
// Copy collections
142-
foreach (var scope in other.Scope)
143-
{
144-
Scope.Add(scope);
145-
}
146-
147-
foreach (var claimAction in other.ClaimActions)
148-
{
149-
ClaimActions.Add(claimAction);
150-
}
151-
152-
// RemoteAuthenticationOptions
153-
BackchannelTimeout = other.BackchannelTimeout;
154-
BackchannelHttpHandler = other.BackchannelHttpHandler;
155-
Backchannel = other.Backchannel;
156-
DataProtectionProvider = other.DataProtectionProvider;
157-
CallbackPath = other.CallbackPath;
158-
AccessDeniedPath = other.AccessDeniedPath;
159-
ReturnUrlParameter = other.ReturnUrlParameter;
160-
SignInScheme = other.SignInScheme;
161-
RemoteAuthenticationTimeout = other.RemoteAuthenticationTimeout;
162-
Events = other.Events;
163-
SaveTokens = other.SaveTokens;
164-
CorrelationCookie = other.CorrelationCookie;
165-
166-
// AuthenticationSchemeOptions
167-
ClaimsIssuer = other.ClaimsIssuer;
168-
Events = other.Events;
169-
EventsType = other.EventsType;
170-
ForwardDefault = other.ForwardDefault;
171-
ForwardAuthenticate = other.ForwardAuthenticate;
172-
ForwardChallenge = other.ForwardChallenge;
173-
ForwardForbid = other.ForwardForbid;
174-
ForwardSignIn = other.ForwardSignIn;
175-
ForwardSignOut = other.ForwardSignOut;
176-
ForwardDefaultSelector = other.ForwardDefaultSelector;
177-
#endif
178-
}
17964

18065

18166
internal static void UpdateMergedOptionsFromMicrosoftIdentityOptions(MicrosoftIdentityOptions microsoftIdentityOptions, MergedOptions mergedOptions)
@@ -591,14 +476,14 @@ public void PrepareAuthorityInstanceForMsal()
591476
if (IsB2C && Instance.EndsWith("/tfp/", StringComparison.OrdinalIgnoreCase))
592477
{
593478
#if !NETSTANDARD2_0 && !NET462 && !NET472
594-
Instance = Instance.Replace("/tfp/", string.Empty, StringComparison.OrdinalIgnoreCase).TrimEnd('/') + "/";
479+
PreparedInstance = Instance.Replace("/tfp/", string.Empty, StringComparison.OrdinalIgnoreCase).TrimEnd('/') + "/";
595480
#else
596-
Instance = Instance.Replace("/tfp/", string.Empty).TrimEnd('/') + "/";
481+
PreparedInstance = Instance.Replace("/tfp/", string.Empty).TrimEnd('/') + "/";
597482
#endif
598483
}
599484
else
600485
{
601-
Instance = Instance.TrimEnd('/') + "/";
486+
PreparedInstance = Instance.TrimEnd('/') + "/";
602487
}
603488
}
604489

src/Microsoft.Identity.Web.TokenAcquisition/PublicAPI/net462/InternalAPI.Unshipped.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
Microsoft.Identity.Web.MergedOptions.AppHomeTenantId.get -> string?
33
Microsoft.Identity.Web.MergedOptions.AppHomeTenantId.set -> void
44
Microsoft.Identity.Web.MergedOptions.MergedOptions(Microsoft.Identity.Web.MergedOptions! other) -> void
5+
Microsoft.Identity.Web.MergedOptions.PreparedInstance.get -> string?
6+
Microsoft.Identity.Web.MergedOptions.PreparedInstance.set -> void
57
Microsoft.Identity.Web.TokenAcquisitionExtensionOptions.InvokeOnBeforeTokenAcquisitionForApp(Microsoft.Identity.Client.AcquireTokenForClientParameterBuilder! builder, Microsoft.Identity.Abstractions.AcquireTokenOptions? acquireTokenOptions) -> void
68
Microsoft.Identity.Web.TokenAcquisitionExtensionOptions.InvokeOnBeforeTokenAcquisitionForTestUser(Microsoft.Identity.Client.AcquireTokenByUsernameAndPasswordConfidentialParameterBuilder! builder, Microsoft.Identity.Abstractions.AcquireTokenOptions? acquireTokenOptions, System.Security.Claims.ClaimsPrincipal! user) -> void
79
readonly Microsoft.Identity.Web.TokenAcquisition.tokenAcquisitionExtensionOptionsMonitor -> Microsoft.Extensions.Options.IOptionsMonitor<Microsoft.Identity.Web.TokenAcquisitionExtensionOptions!>?

src/Microsoft.Identity.Web.TokenAcquisition/PublicAPI/net472/InternalAPI.Unshipped.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
Microsoft.Identity.Web.MergedOptions.AppHomeTenantId.get -> string?
33
Microsoft.Identity.Web.MergedOptions.AppHomeTenantId.set -> void
44
Microsoft.Identity.Web.MergedOptions.MergedOptions(Microsoft.Identity.Web.MergedOptions! other) -> void
5+
Microsoft.Identity.Web.MergedOptions.PreparedInstance.get -> string?
6+
Microsoft.Identity.Web.MergedOptions.PreparedInstance.set -> void
57
Microsoft.Identity.Web.TokenAcquisitionExtensionOptions.InvokeOnBeforeTokenAcquisitionForApp(Microsoft.Identity.Client.AcquireTokenForClientParameterBuilder! builder, Microsoft.Identity.Abstractions.AcquireTokenOptions? acquireTokenOptions) -> void
68
Microsoft.Identity.Web.TokenAcquisitionExtensionOptions.InvokeOnBeforeTokenAcquisitionForTestUser(Microsoft.Identity.Client.AcquireTokenByUsernameAndPasswordConfidentialParameterBuilder! builder, Microsoft.Identity.Abstractions.AcquireTokenOptions? acquireTokenOptions, System.Security.Claims.ClaimsPrincipal! user) -> void
79
readonly Microsoft.Identity.Web.TokenAcquisition.tokenAcquisitionExtensionOptionsMonitor -> Microsoft.Extensions.Options.IOptionsMonitor<Microsoft.Identity.Web.TokenAcquisitionExtensionOptions!>?

src/Microsoft.Identity.Web.TokenAcquisition/PublicAPI/net6.0/InternalAPI.Unshipped.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
Microsoft.Identity.Web.MergedOptions.AppHomeTenantId.get -> string?
33
Microsoft.Identity.Web.MergedOptions.AppHomeTenantId.set -> void
44
Microsoft.Identity.Web.MergedOptions.MergedOptions(Microsoft.Identity.Web.MergedOptions! other) -> void
5+
Microsoft.Identity.Web.MergedOptions.PreparedInstance.get -> string?
6+
Microsoft.Identity.Web.MergedOptions.PreparedInstance.set -> void
57
Microsoft.Identity.Web.TokenAcquisitionExtensionOptions.InvokeOnBeforeTokenAcquisitionForApp(Microsoft.Identity.Client.AcquireTokenForClientParameterBuilder! builder, Microsoft.Identity.Abstractions.AcquireTokenOptions? acquireTokenOptions) -> void
68
Microsoft.Identity.Web.TokenAcquisitionExtensionOptions.InvokeOnBeforeTokenAcquisitionForTestUser(Microsoft.Identity.Client.AcquireTokenByUsernameAndPasswordConfidentialParameterBuilder! builder, Microsoft.Identity.Abstractions.AcquireTokenOptions? acquireTokenOptions, System.Security.Claims.ClaimsPrincipal! user) -> void
79
readonly Microsoft.Identity.Web.TokenAcquisition.tokenAcquisitionExtensionOptionsMonitor -> Microsoft.Extensions.Options.IOptionsMonitor<Microsoft.Identity.Web.TokenAcquisitionExtensionOptions!>?

src/Microsoft.Identity.Web.TokenAcquisition/PublicAPI/net7.0/InternalAPI.Unshipped.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
Microsoft.Identity.Web.MergedOptions.AppHomeTenantId.get -> string?
33
Microsoft.Identity.Web.MergedOptions.AppHomeTenantId.set -> void
44
Microsoft.Identity.Web.MergedOptions.MergedOptions(Microsoft.Identity.Web.MergedOptions! other) -> void
5+
Microsoft.Identity.Web.MergedOptions.PreparedInstance.get -> string?
6+
Microsoft.Identity.Web.MergedOptions.PreparedInstance.set -> void
57
Microsoft.Identity.Web.TokenAcquisitionExtensionOptions.InvokeOnBeforeTokenAcquisitionForApp(Microsoft.Identity.Client.AcquireTokenForClientParameterBuilder! builder, Microsoft.Identity.Abstractions.AcquireTokenOptions? acquireTokenOptions) -> void
68
Microsoft.Identity.Web.TokenAcquisitionExtensionOptions.InvokeOnBeforeTokenAcquisitionForTestUser(Microsoft.Identity.Client.AcquireTokenByUsernameAndPasswordConfidentialParameterBuilder! builder, Microsoft.Identity.Abstractions.AcquireTokenOptions? acquireTokenOptions, System.Security.Claims.ClaimsPrincipal! user) -> void
79
readonly Microsoft.Identity.Web.TokenAcquisition.tokenAcquisitionExtensionOptionsMonitor -> Microsoft.Extensions.Options.IOptionsMonitor<Microsoft.Identity.Web.TokenAcquisitionExtensionOptions!>?

src/Microsoft.Identity.Web.TokenAcquisition/PublicAPI/net8.0/InternalAPI.Unshipped.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
Microsoft.Identity.Web.MergedOptions.AppHomeTenantId.get -> string?
33
Microsoft.Identity.Web.MergedOptions.AppHomeTenantId.set -> void
44
Microsoft.Identity.Web.MergedOptions.MergedOptions(Microsoft.Identity.Web.MergedOptions! other) -> void
5+
Microsoft.Identity.Web.MergedOptions.PreparedInstance.get -> string?
6+
Microsoft.Identity.Web.MergedOptions.PreparedInstance.set -> void
57
Microsoft.Identity.Web.TokenAcquisitionExtensionOptions.InvokeOnBeforeTokenAcquisitionForApp(Microsoft.Identity.Client.AcquireTokenForClientParameterBuilder! builder, Microsoft.Identity.Abstractions.AcquireTokenOptions? acquireTokenOptions) -> void
68
Microsoft.Identity.Web.TokenAcquisitionExtensionOptions.InvokeOnBeforeTokenAcquisitionForTestUser(Microsoft.Identity.Client.AcquireTokenByUsernameAndPasswordConfidentialParameterBuilder! builder, Microsoft.Identity.Abstractions.AcquireTokenOptions? acquireTokenOptions, System.Security.Claims.ClaimsPrincipal! user) -> void
79
readonly Microsoft.Identity.Web.TokenAcquisition.tokenAcquisitionExtensionOptionsMonitor -> Microsoft.Extensions.Options.IOptionsMonitor<Microsoft.Identity.Web.TokenAcquisitionExtensionOptions!>?

src/Microsoft.Identity.Web.TokenAcquisition/PublicAPI/net9.0/InternalAPI.Unshipped.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
Microsoft.Identity.Web.MergedOptions.AppHomeTenantId.get -> string?
33
Microsoft.Identity.Web.MergedOptions.AppHomeTenantId.set -> void
44
Microsoft.Identity.Web.MergedOptions.MergedOptions(Microsoft.Identity.Web.MergedOptions! other) -> void
5+
Microsoft.Identity.Web.MergedOptions.PreparedInstance.get -> string?
6+
Microsoft.Identity.Web.MergedOptions.PreparedInstance.set -> void
57
Microsoft.Identity.Web.TokenAcquisitionExtensionOptions.InvokeOnBeforeTokenAcquisitionForApp(Microsoft.Identity.Client.AcquireTokenForClientParameterBuilder! builder, Microsoft.Identity.Abstractions.AcquireTokenOptions? acquireTokenOptions) -> void
68
Microsoft.Identity.Web.TokenAcquisitionExtensionOptions.InvokeOnBeforeTokenAcquisitionForTestUser(Microsoft.Identity.Client.AcquireTokenByUsernameAndPasswordConfidentialParameterBuilder! builder, Microsoft.Identity.Abstractions.AcquireTokenOptions? acquireTokenOptions, System.Security.Claims.ClaimsPrincipal! user) -> void
79
readonly Microsoft.Identity.Web.TokenAcquisition.tokenAcquisitionExtensionOptionsMonitor -> Microsoft.Extensions.Options.IOptionsMonitor<Microsoft.Identity.Web.TokenAcquisitionExtensionOptions!>?

src/Microsoft.Identity.Web.TokenAcquisition/PublicAPI/netstandard2.0/InternalAPI.Unshipped.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
Microsoft.Identity.Web.MergedOptions.AppHomeTenantId.get -> string?
33
Microsoft.Identity.Web.MergedOptions.AppHomeTenantId.set -> void
44
Microsoft.Identity.Web.MergedOptions.MergedOptions(Microsoft.Identity.Web.MergedOptions! other) -> void
5+
Microsoft.Identity.Web.MergedOptions.PreparedInstance.get -> string?
6+
Microsoft.Identity.Web.MergedOptions.PreparedInstance.set -> void
57
Microsoft.Identity.Web.TokenAcquisitionExtensionOptions.InvokeOnBeforeTokenAcquisitionForApp(Microsoft.Identity.Client.AcquireTokenForClientParameterBuilder! builder, Microsoft.Identity.Abstractions.AcquireTokenOptions? acquireTokenOptions) -> void
68
Microsoft.Identity.Web.TokenAcquisitionExtensionOptions.InvokeOnBeforeTokenAcquisitionForTestUser(Microsoft.Identity.Client.AcquireTokenByUsernameAndPasswordConfidentialParameterBuilder! builder, Microsoft.Identity.Abstractions.AcquireTokenOptions? acquireTokenOptions, System.Security.Claims.ClaimsPrincipal! user) -> void
79
readonly Microsoft.Identity.Web.TokenAcquisition.tokenAcquisitionExtensionOptionsMonitor -> Microsoft.Extensions.Options.IOptionsMonitor<Microsoft.Identity.Web.TokenAcquisitionExtensionOptions!>?

src/Microsoft.Identity.Web.TokenAcquisition/TokenAcquisition.cs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public async Task<AcquireTokenResult> AddAccountToCacheFromAuthorizationCodeAsyn
157157
if (mergedOptions.IsB2C)
158158
{
159159

160-
var authority = $"{mergedOptions.Instance}{ClaimConstants.Tfp}/{mergedOptions.Domain}/{authCodeRedemptionParameters.UserFlow ?? mergedOptions.DefaultUserFlow}";
160+
var authority = $"{mergedOptions.PreparedInstance}{ClaimConstants.Tfp}/{mergedOptions.Domain}/{authCodeRedemptionParameters.UserFlow ?? mergedOptions.DefaultUserFlow}";
161161
builder.WithB2CAuthority(authority);
162162
}
163163

@@ -754,12 +754,8 @@ private bool IsInvalidClientCertificateOrSignedAssertionError(MsalServiceExcepti
754754
/// </summary>
755755
private async Task<IConfidentialClientApplication> BuildConfidentialClientApplicationAsync(MergedOptions mergedOptions)
756756
{
757-
// PrepareAuthorityInstanceForMsal modifies the object, this can affect other operations.
758-
// Make a copy and the modify the copy.
759-
var copiedOption = new MergedOptions(mergedOptions);
760-
copiedOption.PrepareAuthorityInstanceForMsal();
761-
762-
return await BuildConfidentialClientApplicationImplementationAsync(copiedOption);
757+
mergedOptions.PrepareAuthorityInstanceForMsal();
758+
return await BuildConfidentialClientApplicationImplementationAsync(mergedOptions);
763759
}
764760

765761
private async Task<IConfidentialClientApplication> BuildConfidentialClientApplicationImplementationAsync(MergedOptions mergedOptions)
@@ -797,12 +793,12 @@ private async Task<IConfidentialClientApplication> BuildConfidentialClientApplic
797793
}
798794
else if (mergedOptions.IsB2C)
799795
{
800-
authority = $"{mergedOptions.Instance}{ClaimConstants.Tfp}/{mergedOptions.Domain}/{mergedOptions.DefaultUserFlow}";
796+
authority = $"{mergedOptions.PreparedInstance}{ClaimConstants.Tfp}/{mergedOptions.Domain}/{mergedOptions.DefaultUserFlow}";
801797
builder.WithB2CAuthority(authority);
802798
}
803799
else
804800
{
805-
authority = $"{mergedOptions.Instance}{mergedOptions.TenantId}/";
801+
authority = $"{mergedOptions.PreparedInstance}{mergedOptions.TenantId}/";
806802
builder.WithAuthority(authority);
807803
}
808804

0 commit comments

Comments
 (0)