Table of Contents

Class BlazorController

Namespace
Arc4u.Blazor
Assembly
Arc4u.OAuth2.AspNetCore.Blazor.dll

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

options IOptionsSnapshot<SimpleKeyValueSettings>

The named key/value settings; the ones named Cookies (the OpenID settings) are used to request the token.

configuration IConfiguration

The configuration, which must define Authentication:OpenId.Settings:RootServiceUrl.

logger ILogger<BlazorController>

The logger.

Exceptions

InvalidOperationException

Authentication:OpenId.Settings:RootServiceUrl is 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

id int?

The 1-based index of the chunk of the token to send. The default is 1.

redirectTo string

The url-encoded host of the Blazor application; the redirection goes to https://{redirectTo}/_content/Arc4u.OAuth2.Blazor/GetToken.html.

applicationContext IApplicationContext

The application context giving the current principal.

containerResolve IServiceProvider

The service provider used to resolve the token provider.

logger ILogger<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.