Class AppServicePrincipalFactory
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
containerIServiceProviderThe service provider used to resolve the token providers.
loggerILogger<AppServicePrincipalFactory>The logger.
settingsIOptionsMonitor<SimpleKeyValueSettings>The named token provider settings.
claimsTransformationIClaimsTransformationThe transformation that builds the AppPrincipal.
activitySourceFactoryIActivitySourceFactoryThe 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
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
settingsIKeyValueSettingsThe settings used to create the token.
parameterobjectOptional 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
parameterobject
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
settingsResolveNamestringThe name (key) under which the IKeyValueSettings are registered.
parameterobjectAn 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
settingsIKeyValueSettingsThe settings given to the token providers.
cancellationTokenCancellationTokenA token to cancel the operation.
Returns
- ValueTask
A task that completes when the user is signed out.
Exceptions
- ArgumentNullException
settingsis 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
cancellationTokenCancellationTokenA token to cancel the operation.
Returns
- ValueTask
A task that completes when the user is signed out.