Table of Contents

Class AppServicePrincipalFactory

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

Creates an AppPrincipal on the server side. A token is requested from the ITokenProvider designated by the ProviderId key of the settings, its claims are added to an identity, and the identity is transformed by the registered IClaimsTransformation.

[Export(typeof(IAppPrincipalFactory))]
public class AppServicePrincipalFactory : IAppPrincipalFactory
Inheritance
AppServicePrincipalFactory
Implements
Inherited Members

Constructors

AppServicePrincipalFactory(IServiceProvider, ILogger<AppServicePrincipalFactory>, IOptionsMonitor<SimpleKeyValueSettings>, IClaimsTransformation, IActivitySourceFactory)

Initializes a new instance of the AppServicePrincipalFactory class.

public AppServicePrincipalFactory(IServiceProvider container, ILogger<AppServicePrincipalFactory> logger, IOptionsMonitor<SimpleKeyValueSettings> settings, IClaimsTransformation claimsTransformation, IActivitySourceFactory activitySourceFactory)

Parameters

container IServiceProvider

The service provider used to resolve the token providers.

logger ILogger<AppServicePrincipalFactory>

The logger.

settings IOptionsMonitor<SimpleKeyValueSettings>

The named token provider settings.

claimsTransformation IClaimsTransformation

The transformation that builds the AppPrincipal.

activitySourceFactory IActivitySourceFactory

The factory of the activity source used for telemetry.

Fields

ProviderKey

The settings key (ProviderId) that holds the key of the token provider.

public const string ProviderKey = "ProviderId"

Field Value

string

Methods

CreatePrincipalAsync(IKeyValueSettings, object?)

Create an AppPrincipal from a token obtained with the given settings.

public Task<Result<AppPrincipal>> CreatePrincipalAsync(IKeyValueSettings settings, object? parameter = null)

Parameters

settings IKeyValueSettings

The settings used to create the token.

parameter object

Optional parameter forwarded to the token provider.

Returns

Task<Result<AppPrincipal>>

A FluentResults.Result<TValue>, failed when no token or no principal can be created.

CreatePrincipalAsync(object?)

Not supported: creating a principal requires the settings identifying the token provider. Use CreatePrincipalAsync(string, object?) or CreatePrincipalAsync(IKeyValueSettings, object?).

public Task<Result<AppPrincipal>> CreatePrincipalAsync(object? parameter = null)

Parameters

parameter object

Returns

Task<Result<AppPrincipal>>

Exceptions

NotSupportedException

Always thrown.

CreatePrincipalAsync(string, object?)

Creates the principal using the settings registered under the specified name.

public Task<Result<AppPrincipal>> CreatePrincipalAsync(string settingsResolveName, object? parameter)

Parameters

settingsResolveName string

The name (key) under which the IKeyValueSettings are registered.

parameter object

An optional parameter passed to the token provider.

Returns

Task<Result<AppPrincipal>>

A result containing the principal, or the reasons why it could not be created (for example when no settings exist with that name).

SignOutUserAsync(IKeyValueSettings, CancellationToken)

Removes the cached claims of the current user of the IApplicationContext and signs the user out of every token provider that holds a user session (ISignOutTokenProvider), giving them settings. An exception thrown while removing the claims or by a token provider is logged and not rethrown.

public ValueTask SignOutUserAsync(IKeyValueSettings settings, CancellationToken cancellationToken)

Parameters

settings IKeyValueSettings

The settings given to the token providers.

cancellationToken CancellationToken

A token to cancel the operation.

Returns

ValueTask

A task that completes when the user is signed out.

Exceptions

ArgumentNullException

settings is null.

SignOutUserAsync(CancellationToken)

Removes the cached claims of the current user of the IApplicationContext and signs the user out of every token provider that holds a user session (ISignOutTokenProvider), giving them empty settings.

public ValueTask SignOutUserAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

A token to cancel the operation.

Returns

ValueTask

A task that completes when the user is signed out.