diff --git a/src/Components/WebAssembly/Authentication.Msal/src/Interop/AuthenticationService.ts b/src/Components/WebAssembly/Authentication.Msal/src/Interop/AuthenticationService.ts index 03838a5c9b..b06e1892d5 100644 --- a/src/Components/WebAssembly/Authentication.Msal/src/Interop/AuthenticationService.ts +++ b/src/Components/WebAssembly/Authentication.Msal/src/Interop/AuthenticationService.ts @@ -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 { - 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; } } } diff --git a/src/Components/WebAssembly/Authentication.Msal/src/Models/MsalProviderOptions.cs b/src/Components/WebAssembly/Authentication.Msal/src/Models/MsalProviderOptions.cs index 8fa6b8b292..c02c651891 100644 --- a/src/Components/WebAssembly/Authentication.Msal/src/Models/MsalProviderOptions.cs +++ b/src/Components/WebAssembly/Authentication.Msal/src/Models/MsalProviderOptions.cs @@ -14,7 +14,7 @@ namespace Microsoft.Authentication.WebAssembly.Msal.Models /// /// Gets or sets the to use for authentication operations. /// - [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. /// public IList AdditionalScopesToConsent { get; set; } = new List(); + + /// + /// Gets or sets the login mode that is used when initiating the sign-in flow. + /// + public string LoginMode { get; set; } = "popup"; } }