Class BlazorController
This controller is used to obtain an access token as a result of a back-end authentication and transmit it back to the Blazor application.
[Authorize]
[ApiController]
[Route("[controller]")]
[ApiExplorerSettings(IgnoreApi = true)]
[ProducesResponseType(typeof(ProblemDetails), 400)]
public class BlazorController : ControllerBase
- Inheritance
-
BlazorController
- Inherited Members
Remarks
This controller is known to the API Gateway (Yarp). It needs a property called "RootServiceUrl" in the section Authentication:OpenId.Settings pointing to the yarp service URL.
Constructors
BlazorController(IOptionsSnapshot<SimpleKeyValueSettings>, IConfiguration, ILogger<BlazorController>)
Initializes a new instance of the BlazorController class.
public BlazorController(IOptionsSnapshot<SimpleKeyValueSettings> options, IConfiguration configuration, ILogger<BlazorController> logger)
Parameters
optionsIOptionsSnapshot<SimpleKeyValueSettings>The named key/value settings; the ones named
Cookies(the OpenID settings) are used to request the token.configurationIConfigurationThe configuration, which must define
Authentication:OpenId.Settings:RootServiceUrl.loggerILogger<BlazorController>The logger.
Exceptions
- InvalidOperationException
Authentication:OpenId.Settings:RootServiceUrlis not defined in the configuration.
Methods
Get(int?, string, IApplicationContext, IServiceProvider, ILogger<BlazorController>)
This action is used to redirect the user to the Blazor application after having retrieved his/her access token.
[ProducesResponseType(typeof(string), 200)]
[ProducesResponseType(typeof(string), 401)]
[HttpGet("redirectTo/{redirectTo}/{id?}")]
public Task<IActionResult> Get(int? id, string redirectTo, IApplicationContext applicationContext, IServiceProvider containerResolve, ILogger<BlazorController> logger)
Parameters
idint?The 1-based index of the chunk of the token to send. The default is 1.
redirectTostringThe url-encoded host of the Blazor application; the redirection goes to
https://{redirectTo}/_content/Arc4u.OAuth2.Blazor/GetToken.html.applicationContextIApplicationContextThe application context giving the current principal.
containerResolveIServiceProviderThe service provider used to resolve the token provider.
loggerILogger<BlazorController>The logger. It is not used: the logger of the controller is used.
Returns
- Task<IActionResult>
A redirection to the Blazor application carrying the token, a 401 status when the principal is unknown or has no operation, or a 400 status when the token or the redirect url is invalid.
Remarks
The access token is taken from the BootstrapContext of the current principal or, if empty, requested from the Oidc token provider.
It is sent to the Blazor application in chunks of 1024 characters: id is the 1-based index of the chunk.