Interface IAuthenticationProvider
- Namespace
- VpnHood.AppLib.Abstractions.Accounts
- Assembly
- VpnHood.AppLib.Abstractions.dll
Who is signed in, and the credential that proves it. Deliberately not a transport: it hands out a token and lets the caller own its own HttpClient, so nothing downstream inherits a client's base address, TLS policy or lifetime from here.
Disposable because it owns the external providers it was given, not because it owns any client.
public interface IAuthenticationProvider : IDisposable
- Inherited Members
Properties
ProviderIds
Gets the IDs of the sign-in methods the app offers, the ones ProviderId may name; the well-known ones are in AuthProviders.
IReadOnlyList<string> ProviderIds { get; }
Property Value
UserId
The signed-in account's id, or null. Ambient and cheap: it is read straight from the persisted session, so a device signed in yesterday knows it without any call.
string? UserId { get; }
Property Value
Methods
GetAccessToken(CancellationToken)
The credential for the current session, or null when nobody is signed in; an anonymous call simply never asks for one. Async, and hence not a property beside UserId, as a provider may have to work for it: the portal's tries a zero-tap restore of the sign-in where nobody is signed in. The portal never renews it: its sessions have no time limit and last until the backend refuses them (InvalidateAccessToken(string)).
Task<string?> GetAccessToken(CancellationToken cancellationToken)
Parameters
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
GetPasswordResetUrl(CancellationToken)
The page of the human account website behind this provider where a person recovers a password, or null when there is none. Asked when the password sign-in form opens, which offers it as its escape hatch only when a page comes back — never as an API endpoint.
Task<Uri?> GetPasswordResetUrl(CancellationToken cancellationToken)
Parameters
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
Exceptions
- ApiException
The account backend refused the request.
- OperationCanceledException
cancellationTokenwas canceled.
InvalidateAccessToken(string)
The backend refused this token: the session is over. The token is passed back so a stale in-flight refusal cannot end a session that has meanwhile been replaced by a newer sign-in.
void InvalidateAccessToken(string accessToken)
Parameters
accessTokenstringThe token the backend refused.
SignIn(IUiContext?, SignInOptions, CancellationToken)
Signs the person in, or answers the second step of a sign-in that asked for one.
Task<SignInResult> SignIn(IUiContext? uiContext, SignInOptions signInOptions, CancellationToken cancellationToken)
Parameters
uiContextIUiContextThe window, or null where none is open, as in the desktop service: the password sign-in needs none.
signInOptionsSignInOptionsThe sign-in method, with its credentials or the second step's code.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- Task<SignInResult>
A task whose result is what the sign-in accomplished.
Exceptions
- UiContextNotAvailableException
uiContextis null, and the method shows a sheet, as Google's and Apple's do.- NotSupportedException
The method is not one of ProviderIds, or the account's second step is of a kind the app cannot answer.
- ArgumentException
The password sign-in's first step lacks the email address or the password.
- InvalidOperationException
A second step's code came with no sign-in waiting for one.
- AuthenticationException
The identity provider gave no ID token, as Google's where the device has no Google account.
- ApiException
The account backend refused the request.
- OperationCanceledException
The person canceled the sign-in, or
cancellationTokenwas canceled.
SignOut(IUiContext?, CancellationToken)
Signs the person out.
Task SignOut(IUiContext? uiContext, CancellationToken cancellationToken)
Parameters
uiContextIUiContextThe window, or null where none is open.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- Task
A task that represents the asynchronous operation.
Remarks
The session ends on the device either way; what only a window can clear on the device is left where none is open.