UniWebViewAuthenticationFlowDiscord

Summary

A predefined authentication flow for Discord.

This implementation follows the flow described hereopen in new window.

See the OAuth 2.0 Support for a more detailed guide of authentication in UniWebView.

To allow the Discord flow working, at least you need these steps:

  1. Setting Client Id, Client Secret and Redirect Uri in the UniWebViewAuthenticationFlowDiscord inspector.
  2. Setting scope and at least contains identify in the UniWebViewAuthenticationFlowDiscord inspector.
  3. Setting the Auth Callbacks Urls containing Redirect Uri in UniWebView preference panel.

Properties Summary

The client ID of your Discord application.

The client secret of your Discord application.

The redirect URI of this Discord application.

The scope string of all your required scopes.

Optional to control this flow's behaviour.

Whether to enable PKCE when performing authentication.

Whether to enable the state verification.

Events Summary

Called when the authentication flow succeeds and a valid token is generated.

Called when any error (including user cancellation) happens during the authentication flow.

Methods Summary

Starts the authentication flow with the standard OAuth 2.

Properties

The client ID of your Discord application.

The client secret of your Discord application.

The redirect URI of this Discord application.

The scope string of all your required scopes.

Whether to enable PKCE when performing authentication. On mobile platforms, this has to be enabled as S256, otherwise, Discord will reject the authentication request.

Whether to enable the state verification. If enabled, the state will be generated and verified in the authentication callback. Default is true.

Events

Called when the authentication flow succeeds and a valid token is generated.

Example

discordFlow.OnAuthenticationFinished.AddListener(OnDiscordTokenReceived)

void OnDiscordTokenReceived(UniWebViewAuthenticationDiscordToken token) {
  Debug.Log("Discord Access Token: " + token.AccessToken);
}

Called when any error (including user cancellation) happens during the authentication flow.

Example

discordFlow.OnAuthenticationErrored.AddListener(OnDiscordAuthError);

void OnDiscordAuthError(long error, string message) {
  Debug.Log("Error code: " + error + " Message: " + message);
}

Methods

Starts the authentication flow with the standard OAuth 2.0. This implements the abstract method in UniWebViewAuthenticationCommonFlow.