Skip to content
This repository was archived by the owner on Feb 16, 2024. It is now read-only.

BlazoradeMsalService

Mika Berglund edited this page Jan 31, 2021 · 1 revision

BlazoradeMsalService Class

The BlazoradeMsalService class is added to the service collection in your application when you configure Blazorade MSAL. This is where all the magic in Blazorade MSAL happens.

Use this service class and one of the methods documented below whenever you need an access token or identity token in your application. The token is in normal operations acquired directly from the cache in MSAL, so it is very quick and effective.

The benefit of getting the token every time you need it is that MSAL will automatically refresh the token once it has expired, often without any user interaction. This makes your application much simpler.

Methods

This class exposes the following methods.

AcquireTokenAsync(string, IEnumerable<string>, bool)

Attempts to acquire a token. The method first tries to acquire the token silently. If that fails, the configured interactive login mode is used.

Parameters

Name Type Description
loginHint string The username of the user for whom to acquire a token.
scopes IEnumerable<string> A collection of scopes to include in the returned access token.
fallbackToDefaultAccount bool If a login hint is not given, setting this to true would use the previously used username as login hint.

Returns

Task<AuthenticationResult>

AcquireTokenInteractiveAsync(string, IEnumerable<string>)

Attempts to acquire a token using either of the configured interactive login modes, i.e. using a popup dialog or redirection. You configure the login mode in the startup routines of your application.

Parameters

Name Type Description
loginHint string The username of the user for whom to acquire a token.
scopes IEnumerable<string> A collection of scopes to include in the returned access token.

Returns

Task<AuthenticationResult>

AcquireTokenSilentAsync(string, IEnumerable<string>, bool)

Attempts to acquire a token silently. It does not fall back to any other acquisition models if a token cannot be acquired silently.

This method is typically used during initial page or view render with fallbackToDefaultAccount set to true to get any token that might have been acquired and cached previously. This method will also process and complete any results from a redirect login, in case this method is called on the login page when returning from the login process.

Parameters

Name Type Description
loginHint string The username of the user for whom to acquire a token.
scopes IEnumerable<string> A collection of scopes to include in the returned access token.
fallbackToDefaultAccount bool If a login hint is not given, setting this to true would use the previously used username as login hint.

Returns

Task<AuthenticationResult>

HandleRedirectPromiseAsync()

This method processes a redirect login after the user has successfully logged in. You should call this method on your login page during first render. Your login page is the page corresponding to the RedirectUrl property specified on the BlazoradeMsalOptions during your application's startup.

This method is also automatically called by the AcquireTokenSilentAsync method because this method does not invoke any user interaction. Typically, this method is not called directly, but rather indirectly through the AcquireTokenSilentAsync method.

Returns

Task<AuthenticationResult>

LogoutAsync()

Logs the user out. After successfully logging out, the user is redirected to the url specified in the PostLogoutUrl property on the BlazoradeMsalOptions class during startup.

Returns

Task

Clone this wiki locally