Class WebAuthenticator
Handles OAuth redirection to the system browser and re-activation.
Inheritance
Inherited Members
Namespace: WinUIEx
Assembly: WinUIEx.dll
Syntax
public sealed class WebAuthenticator
Remarks
Your app must be configured for OAuth with schema activation. The scheme must be the first part of the url, ie if your
oauth redirection url starts with for instance myappscheme://signin/
, the scheme would be myappscheme
.
Note that http(s) schemes are not supported here.
If your app is packaged, in your app's Package.appxmanifest
under Declarations
, add a
Protocol declaration and add the scheme you registered for your application's oauth redirect url under "Name".
If your app is unpackaged, make sure you register the application for protocol activation.
try
{
Microsoft.Windows.AppLifecycle.ActivationRegistrationManager.RegisterForProtocolActivation("myappscheme", "Assets\\Square150x150Logo.scale-100", "My App Name", null);
var result = await WebAuthenticator.AuthenticateAsync(authorizeUri, callbackUri, cancellationToken);
}
finally
{
Microsoft.Windows.AppLifecycle.ActivationRegistrationManager.UnregisterForProtocolActivation("myappscheme", null);
}
Methods
| Improve this Doc View SourceAuthenticateAsync(Uri, Uri)
Begin an authentication flow by navigating to the specified url and waiting for a callback/redirect to the callbackUrl scheme.
Declaration
public static Task<WebAuthenticatorResult> AuthenticateAsync(Uri authorizeUri, Uri callbackUri)
Parameters
Type | Name | Description |
---|---|---|
System.Uri | authorizeUri | Url to navigate to, beginning the authentication flow. |
System.Uri | callbackUri | Expected callback url that the navigation flow will eventually redirect to. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<WebAuthenticatorResult> | Returns a result parsed out from the callback url. |
Remarks
Prior to calling this, a call to CheckOAuthRedirectionActivation(Boolean) must be made during application startup.
See Also
| Improve this Doc View SourceAuthenticateAsync(Uri, Uri, CancellationToken)
Begin an authentication flow by navigating to the specified url and waiting for a callback/redirect to the callbackUrl scheme.
Declaration
public static Task<WebAuthenticatorResult> AuthenticateAsync(Uri authorizeUri, Uri callbackUri, CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
System.Uri | authorizeUri | Url to navigate to, beginning the authentication flow. |
System.Uri | callbackUri | Expected callback url that the navigation flow will eventually redirect to. |
System.Threading.CancellationToken | cancellationToken | Cancellation token. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<WebAuthenticatorResult> | Returns a result parsed out from the callback url. |
Remarks
Prior to calling this, a call to CheckOAuthRedirectionActivation(Boolean) must be made during application startup.
See Also
| Improve this Doc View SourceCheckOAuthRedirectionActivation(Boolean)
Performs an OAuth protocol activation check and redirects activation to the correct application instance.
Declaration
public static bool CheckOAuthRedirectionActivation(bool skipShutDownOnActivation = false)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | skipShutDownOnActivation | If |
Returns
Type | Description |
---|---|
System.Boolean |
|
Remarks
The call to this method should be done preferably in the Program.Main method, or the application constructor. It must be called prior to using AuthenticateAsync(Uri, Uri, CancellationToken)
See Also
| Improve this Doc View SourceCheckOAuthRedirectionActivation(Nullable<AppActivationArguments>, Boolean)
Performs an OAuth protocol activation check and redirects activation to the correct application instance.
Declaration
public static bool CheckOAuthRedirectionActivation(AppActivationArguments? activatedEventArgs, bool skipShutDownOnActivation = false)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<AppActivationArguments> | activatedEventArgs | The activation arguments |
System.Boolean | skipShutDownOnActivation | If |
Returns
Type | Description |
---|---|
System.Boolean |
|
Remarks
The call to this method should be done preferably in the Program.Main method, or the application constructor. It must be called prior to using AuthenticateAsync(Uri, Uri, CancellationToken)