Skip to content

Login with OAuth

To authenticate a user via an OAuth account (e.g. Google, Discord, Apple), use the Privy client's OAuth handler.

This is a two step process, though Privy's Unity SDK wraps it into a single method call:

  1. Generate an OAuth login URL corresponding to your desired OAuth provider
  2. Redirect the user to the login URL to have them authenticate with the chosen OAuth provider

Supported OAuth Providers

Privy currently supports Google, Discord, and Apple OAuth in Unity. We are actively adding support for other providers.

TIP

If your app integrates Apple login, please make sure to follow our Apple specific documentation for best practices.

Configure allowed URL schemes

Prior to integrating OAuth login, make sure you have properly configured your app's allowed URL schemes in the Privy dashboard.

For non-web platforms, be sure to setup deeplinking with your allowed URL scheme.

WARNING

Login with OAuth will not work if you have not completed this step.

Initializing the login flow

To launch the OAuth flow, simply call PrivyManager.Instance.OAuth.LoginWithProvider. As parameters to this method, pass the following fields:

FieldTypeDescription
providerOAuthProviderA member of the OAuthProvider enum specifying which OAuth provider the user should login with.
redirectUriStringFor WebGL builds, this will be your redirect URL. For applications, this will be your app's URL scheme.

As an example, you might call login like so:

csharp
try
{
    // Log the user in with Google OAuth
    await PrivyManager.Instance.OAuth.LoginWithProvider(OAuthProvider.Google, "myappscheme");
}
catch
{
    // Login with OAuth was unsuccessful
    Debug.Log("Error logging user in.");
}

That's it! If your user was successfully authenticated, the LoginWithProvider method will return the new AuthState for a user.

This method will throw an error if:

  • a redirectUri is not provided
  • the network call to authenticate the user fails