Table of Contents

Class AppPrincipalFactory

Namespace
Arc4u.OAuth2.Client.Security.Principal
Assembly
Arc4u.OAuth2.Client.dll

Creates an AppPrincipal on the client side. A token is requested from the ITokenProvider designated by the ProviderId key of the settings, its claims (and the ones given by the registered IClaimsFiller) are added to an identity and cached; the authorization and profile are then built from the claims. Without network, the principal is built from the cached claims. The principal is set in the IApplicationContext.

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

Constructors

AppPrincipalFactory(IServiceProvider, INetworkInformation, ISecureCache, ICacheKeyGenerator, IApplicationContext, ILogger<AppPrincipalFactory>)

Creates an AppPrincipal on the client side. A token is requested from the ITokenProvider designated by the ProviderId key of the settings, its claims (and the ones given by the registered IClaimsFiller) are added to an identity and cached; the authorization and profile are then built from the claims. Without network, the principal is built from the cached claims. The principal is set in the IApplicationContext.

public AppPrincipalFactory(IServiceProvider container, INetworkInformation networkInformation, ISecureCache claimsCache, ICacheKeyGenerator cacheKeyGenerator, IApplicationContext applicationContext, ILogger<AppPrincipalFactory> logger)

Parameters

container IServiceProvider

The service provider used to resolve the token providers and the claim fillers.

networkInformation INetworkInformation

The network status.

claimsCache ISecureCache

The secure cache in which the claims are kept.

cacheKeyGenerator ICacheKeyGenerator

The generator of the cache key of the claims.

applicationContext IApplicationContext

The application context that receives the principal.

logger ILogger<AppPrincipalFactory>

The logger.

Fields

PlatformParameters

The name (platformParameters) of the platform specific parameters.

public const string PlatformParameters = "platformParameters"

Field Value

string

Methods

CreatePrincipalAsync(IKeyValueSettings, object?)

Creates the principal with the given settings.

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

Parameters

settings IKeyValueSettings

The settings, which must contain the ProviderId key.

parameter object

Optional parameter forwarded to the token provider.

Returns

Task<Result<AppPrincipal>>

The principal, or a failed result when the principal cannot be built.

Exceptions

ArgumentNullException

settings is null.

CreatePrincipalAsync(object?)

Creates the principal with the settings named OAuth2.

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

Parameters

parameter object

Optional parameter forwarded to the token provider.

Returns

Task<Result<AppPrincipal>>

The principal, or a failed result.

CreatePrincipalAsync(string, object?)

Creates the principal with the named settings.

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

Parameters

settingsResolveName string

The name of the SimpleKeyValueSettings options holding the settings.

parameter object

Optional parameter forwarded to the token provider.

Returns

Task<Result<AppPrincipal>>

The principal, or a failed result when the settings do not exist or the principal cannot be built.

SignOutUserAsync(IKeyValueSettings, CancellationToken)

Removes the cached claims and signs the user out of every token provider that holds a user session (ISignOutTokenProvider), giving them settings. An exception thrown 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)

Signs the user out with the settings named OAuth2, or with empty settings when they do not exist.

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.