Use custom authentication in Unity
Custom authentication is a way to authenticate users with your custom authentication service. For example, while authenticating with Google, you can use your own Google Client ID to authenticate users directly.
This feature, with MFA turned off, can make Embedded Wallets invisible to the end user.
This is a paid feature and the minimum pricing plan to use this SDK in a production environment is the Growth Plan. You can use this feature in Web3Auth Sapphire Devnet network for free.
Get an auth connection ID
To enable this, you need to create a connection from the Authentication tab of your project from the Embedded Wallets dashboard with your desired configuration.
Configure the connection in the Embedded Wallets dashboard, then pass its
authConnectionId to the SDK.
You can configure multiple connections for the same project.
Learn more about the auth provider setup and the different configurations available for each connection.
Configuration
Pass custom connection details to authConnectionConfig when you initialize the SDK.
The property accepts a List<AuthConnectionConfig>.
Parameters
AuthConnectionConfig
| Parameter | Description |
|---|---|
authConnectionId | Connection ID from the Embedded Wallets dashboard. |
authConnection | Authentication method as an AuthConnection value. |
clientId? | OAuth client ID for the identity provider. |
groupedAuthConnectionId? | Grouped connection ID when several methods must produce the same key. |
name? | Display name for the connection. |
description? | Description displayed with the connection. |
logoHover? | Logo shown on hover. |
logoLight? | Logo shown on dark backgrounds. |
logoDark? | Logo shown on light backgrounds. |
mainOption? | Whether to show the connection as a primary option. |
showOnModal? | Whether to show the connection in the modal. |
showOnDesktop? | Whether to show the connection on desktop. |
showOnMobile? | Whether to show the connection on mobile. |
extraLoginOptions? | Provider-specific options as ExtraLoginOptions. |
extraLoginOptions
The extraLoginOptions parameter can be used to pass additional options required by specific login providers.
| Parameter | Description |
|---|---|
domain? | Your custom authentication domain in string format. For example, if you are using Auth0, it can be example.auth0.com. |
client_id? | Client ID in string format, provided by your login provider and used for the custom verifier. |
userIdField? | Field in the JWT that maps to the user ID configured in the dashboard. |
isUserIdCaseSensitive? | Whether the user ID field is case-sensitive. |
prompt? | Prompt shown to the user during the authentication process. Accepts a string value. |
id_token? | JWT (ID token) to be passed for login. |
login_hint? | It is used to send the user's email address during email passwordless login. Accepts a string value. |
Single connection
Configure authConnectionConfig with the connection ID and authentication method.
void Start()
{
web3Auth = GetComponent<Web3Auth>();
var authConnectionConfig = new AuthConnectionConfig()
{
authConnectionId = "<YOUR_AUTH_CONNECTION_ID>",
authConnection = AuthConnection.GOOGLE,
clientId = "<YOUR_GOOGLE_CLIENT_ID>"
};
web3Auth.setOptions(new Web3AuthOptions()
{
redirectUrl = new Uri("<YOUR_SCHEME>://<YOUR_APP_PACKAGE_NAME>/auth"),
clientId = "<YOUR_CLIENT_ID>",
web3AuthNetwork = Web3Auth.Network.SAPPHIRE_DEVNET,
authConnectionConfig = new List<AuthConnectionConfig>
{
authConnectionConfig
}
});
}
Example implementations
Using Google login
public void loginGoogle()
{
var options = new LoginParams()
{
authConnection = AuthConnection.GOOGLE,
authConnectionId = "<YOUR_AUTH_CONNECTION_ID>"
};
web3Auth.login(options);
}
Using JWT login
To use JWT login (for example, Auth0):
public void loginJWT()
{
var options = new LoginParams()
{
authConnection = AuthConnection.CUSTOM,
authConnectionId = "<YOUR_AUTH_CONNECTION_ID>",
extraLoginOptions = new ExtraLoginOptions()
{
id_token = "<YOUR_ID_TOKEN>",
userIdField = "sub"
}
};
web3Auth.login(options);
}
Grouped connection
Use a grouped connection to let users sign in with different methods and receive the same wallet
address.
Configure each item with its own authConnectionId and the same groupedAuthConnectionId.
void Start()
{
web3Auth = GetComponent<Web3Auth>();
var googleConfig = new AuthConnectionConfig()
{
authConnectionId = "<YOUR_GOOGLE_AUTH_CONNECTION_ID>",
groupedAuthConnectionId = "<YOUR_GROUPED_AUTH_CONNECTION_ID>",
clientId = "<YOUR_GOOGLE_CLIENT_ID>",
authConnection = AuthConnection.GOOGLE,
};
var auth0GitHubConfig = new AuthConnectionConfig()
{
authConnectionId = "<YOUR_GITHUB_AUTH_CONNECTION_ID>",
groupedAuthConnectionId = "<YOUR_GROUPED_AUTH_CONNECTION_ID>",
clientId = "<YOUR_GITHUB_CLIENT_ID>",
authConnection = AuthConnection.CUSTOM,
};
web3Auth.setOptions(new Web3AuthOptions()
{
clientId = "<YOUR_CLIENT_ID>",
redirectUrl = new Uri("<YOUR_SCHEME>://<YOUR_APP_PACKAGE_NAME>/auth"),
web3AuthNetwork = Web3Auth.Network.SAPPHIRE_MAINNET,
authConnectionConfig = new List<AuthConnectionConfig>
{
googleConfig,
auth0GitHubConfig
}
});
}
Example implementations
Using Google and GitHub combined login
public void loginGoogle()
{
var options = new LoginParams()
{
authConnection = AuthConnection.GOOGLE,
authConnectionId = "<YOUR_GOOGLE_AUTH_CONNECTION_ID>",
groupedAuthConnectionId = "<YOUR_GROUPED_AUTH_CONNECTION_ID>"
};
web3Auth.login(options);
}
public void loginGitHub()
{
var options = new LoginParams()
{
authConnection = AuthConnection.CUSTOM,
authConnectionId = "<YOUR_GITHUB_AUTH_CONNECTION_ID>",
groupedAuthConnectionId = "<YOUR_GROUPED_AUTH_CONNECTION_ID>",
extraLoginOptions = new ExtraLoginOptions()
{
id_token = "<YOUR_ID_TOKEN>",
userIdField = "email",
isUserIdCaseSensitive = false,
prompt = Prompt.LOGIN,
}
};
web3Auth.login(options);
}