Show / Hide Table of Contents

Class WebAuthenticator

Handles OAuth redirection to the system browser and re-activation.

Inheritance
System.Object
WebAuthenticator
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: WinUIEx
Assembly: WinUIEx.dll
Syntax
[Obsolete("Use Windows App SDK's Microsoft.Security.Authentication.OAuth APIs instead.")]
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 Source

AuthenticateAsync(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
CheckOAuthRedirectionActivation(Boolean)
| Improve this Doc View Source

AuthenticateAsync(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
CheckOAuthRedirectionActivation(Boolean)
| Improve this Doc View Source

CheckOAuthRedirectionActivation(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 true, this application instance will not automatically be shut down. If set to true ensure you handle instance exit, or you'll end up with multiple instances running.

Returns
Type Description
System.Boolean

true if the activation was redirected and this instance should be shut down, otherwise false.

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
AuthenticateAsync(Uri, Uri, CancellationToken)
| Improve this Doc View Source

CheckOAuthRedirectionActivation(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 true, this application instance will not automatically be shut down. If set to true ensure you handle instance exit, or you'll end up with multiple instances running.

Returns
Type Description
System.Boolean

true if the activation was redirected and this instance should be shut down, otherwise false.

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
AuthenticateAsync(Uri, Uri, CancellationToken)
  • Improve this Doc
  • View Source
In This Article
Back to top Generated by DocFX