-
Notifications
You must be signed in to change notification settings - Fork 5
BlazoradeMsalService
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.
This class exposes the following methods.
Attempts to acquire a token. The method first tries to acquire the token silently. If that fails, the configured interactive login mode is used.
| 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. |
Task<AuthenticationResult>
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.
| 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. |
Task<AuthenticationResult>
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.
| 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. |
Task<AuthenticationResult>
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.
Task<AuthenticationResult>
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.
Task