Class UsernamePasswordTokenProvider
An ITokenProvider for a client application whose user signs in with a user name and password. The credentials are kept in the secure cache; when they are missing,
they are requested from the registered IUserNamePasswordProvider. A token is requested from the CredentialDirect ICredentialTokenProvider and cached until it expires in less than one minute.
The Authority and ServiceApplicationId settings are required; PasswordStoreKey selects the cache entries of the credentials (secret by default).
[Export("usernamePassword", typeof(ITokenProvider))]
public class UsernamePasswordTokenProvider : ISignOutTokenProvider, ITokenProvider
- Inheritance
-
UsernamePasswordTokenProvider
- Implements
- Inherited Members
Constructors
UsernamePasswordTokenProvider(ISecureCache, INetworkInformation, ILogger<UsernamePasswordTokenProvider>, IServiceProvider)
An ITokenProvider for a client application whose user signs in with a user name and password. The credentials are kept in the secure cache; when they are missing,
they are requested from the registered IUserNamePasswordProvider. A token is requested from the CredentialDirect ICredentialTokenProvider and cached until it expires in less than one minute.
The Authority and ServiceApplicationId settings are required; PasswordStoreKey selects the cache entries of the credentials (secret by default).
public UsernamePasswordTokenProvider(ISecureCache secureCache, INetworkInformation networkStatus, ILogger<UsernamePasswordTokenProvider> logger, IServiceProvider container)
Parameters
secureCacheISecureCacheThe secure cache holding the credentials and the token.
networkStatusINetworkInformationThe network status; a token cannot be requested without network.
loggerILogger<UsernamePasswordTokenProvider>The logger.
containerIServiceProviderThe service provider used to resolve the credential providers.
Fields
ProviderName
The key (usernamePassword) under which the provider is registered.
public const string ProviderName = "usernamePassword"
Field Value
Methods
CheckCredentialsAsync(string, string)
Checks credentials by requesting a token for them; on success the token is stored in the cache. It is the callback given to IUserNamePasswordProvider.
public Task<bool> CheckCredentialsAsync(string upn, string password)
Parameters
Returns
CreateBasicTokenInfoAsync(IKeyValueSettings, CredentialsResult)
Requests a token for the credentials from the CredentialDirect ICredentialTokenProvider.
protected Task<TokenInfo> CreateBasicTokenInfoAsync(IKeyValueSettings settings, CredentialsResult credential)
Parameters
settingsIKeyValueSettingsThe provider settings.
credentialCredentialsResultThe credentials of the user.
Returns
Exceptions
- InvalidOperationException
The credential token provider is not registered or no token is received.
GetTokenAsync(IKeyValueSettings?, object?)
Gets the token of the user, asking for the credentials when they are not yet known.
public ValueTask<Result<TokenInfo>> GetTokenAsync(IKeyValueSettings? settings, object? platformParameters)
Parameters
settingsIKeyValueSettingsThe provider settings (see TokenKeys).
platformParametersobjectNot used.
Returns
- ValueTask<Result<TokenInfo>>
The token, or a failed result when there is no credential provider or the user gives no credential.
Exceptions
- ArgumentNullException
settingsis null.- ArgumentException
The
AuthorityorServiceApplicationIdsetting is missing.- InvalidOperationException
The settings are empty or no token is received.
SignOutAsync(IKeyValueSettings, CancellationToken)
Removes the user name, the password and the token of the user from the secure cache. Nothing is done when the settings have no Authority or no
ServiceApplicationId: they are the settings of another provider.
public ValueTask SignOutAsync(IKeyValueSettings settings, CancellationToken cancellationToken)
Parameters
settingsIKeyValueSettingsThe provider settings.
cancellationTokenCancellationTokenA token to cancel the operation.
Returns
- ValueTask
A completed task.
Exceptions
- ArgumentNullException
settingsis null.