[Blazor][Wasm] Expose login mode option for AAD and AAD B2C Authentication (#23694)
* Adds a login mode option via MSAL provider options and updates the AuthenticationService.ts to use the new setting
This commit is contained in:
parent
37a4457150
commit
b8c5193562
|
|
@ -47,7 +47,8 @@ interface AuthorizeService {
|
|||
|
||||
interface AuthorizeServiceConfiguration extends Msal.Configuration {
|
||||
defaultAccessTokenScopes: string[];
|
||||
additionalScopesToConsent: string[]
|
||||
additionalScopesToConsent: string[];
|
||||
loginMode: string;
|
||||
}
|
||||
|
||||
class MsalAuthorizeService implements AuthorizeService {
|
||||
|
|
@ -142,18 +143,26 @@ class MsalAuthorizeService implements AuthorizeService {
|
|||
}
|
||||
|
||||
async signInCore(request: Msal.AuthenticationParameters): Promise<Msal.AuthResponse | Msal.AuthError | undefined> {
|
||||
try {
|
||||
return await this._msalApplication.loginPopup(request);
|
||||
} catch (e) {
|
||||
// If the user explicitly cancelled the pop-up, avoid performing a redirect.
|
||||
if (this.isMsalError(e) && e.errorCode !== ClientAuthErrorMessage.userCancelledError.code) {
|
||||
try {
|
||||
this._msalApplication.loginRedirect(request);
|
||||
} catch (e) {
|
||||
if (this._settings.loginMode.toLowerCase() === "redirect") {
|
||||
try {
|
||||
this._msalApplication.loginRedirect(request);
|
||||
} catch (e) {
|
||||
return e;
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
return await this._msalApplication.loginPopup(request);
|
||||
} catch (e) {
|
||||
// If the user explicitly cancelled the pop-up, avoid performing a redirect.
|
||||
if (this.isMsalError(e) && e.errorCode !== ClientAuthErrorMessage.userCancelledError.code) {
|
||||
try {
|
||||
this._msalApplication.loginRedirect(request);
|
||||
} catch (e) {
|
||||
return e;
|
||||
}
|
||||
} else {
|
||||
return e;
|
||||
}
|
||||
} else {
|
||||
return e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ namespace Microsoft.Authentication.WebAssembly.Msal.Models
|
|||
/// <summary>
|
||||
/// Gets or sets the <see cref="MsalAuthenticationOptions"/> to use for authentication operations.
|
||||
/// </summary>
|
||||
[JsonPropertyName("auth")]
|
||||
[JsonPropertyName("auth")]
|
||||
public MsalAuthenticationOptions Authentication { get; set; } = new MsalAuthenticationOptions
|
||||
{
|
||||
RedirectUri = "authentication/login-callback",
|
||||
|
|
@ -43,5 +43,10 @@ namespace Microsoft.Authentication.WebAssembly.Msal.Models
|
|||
/// Use this parameter to request consent for scopes for other resources.
|
||||
/// </remarks>
|
||||
public IList<string> AdditionalScopesToConsent { get; set; } = new List<string>();
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the login mode that is used when initiating the sign-in flow.
|
||||
/// </summary>
|
||||
public string LoginMode { get; set; } = "popup";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue