[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:
Chris Sainty 2020-07-08 12:26:33 +01:00 committed by GitHub
parent 37a4457150
commit b8c5193562
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 12 deletions

View File

@ -47,7 +47,8 @@ interface AuthorizeService {
interface AuthorizeServiceConfiguration extends Msal.Configuration {
defaultAccessTokenScopes: string[];
additionalScopesToConsent: string[]
additionalScopesToConsent: string[];
loginMode: string;
}
class MsalAuthorizeService implements AuthorizeService {
@ -142,6 +143,13 @@ class MsalAuthorizeService implements AuthorizeService {
}
async signInCore(request: Msal.AuthenticationParameters): Promise<Msal.AuthResponse | Msal.AuthError | undefined> {
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) {
@ -157,6 +165,7 @@ class MsalAuthorizeService implements AuthorizeService {
}
}
}
}
completeSignIn() {
return this._callbackPromise;

View File

@ -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";
}
}