Sign in a user
Call login with LoginParams to start the sign-in flow for an authentication connection.
tip
Additionally, you can associate a function to be triggered on successful login. This function receives the user's profile as a parameter.
void Start()
{
web3Auth = GetComponent<Web3Auth>();
web3Auth.setOptions(new Web3AuthOptions()
{
});
web3Auth.onLogin += onLogin;
}
private void onLogin(Web3AuthResponse response)
{
// Functions to be called after logging in your user
}
Arguments
web3Auth.login() requires LoginParams as a required input.
LoginParams
- Table
- Interface
| Parameter | Description |
|---|---|
authConnection | Authentication method, such as AuthConnection.GOOGLE or AuthConnection.EMAIL_PASSWORDLESS. |
authConnectionId? | ID of a custom authentication connection configured in the Embedded Wallets dashboard. |
groupedAuthConnectionId? | ID of a grouped authentication connection configured in the dashboard. |
extraLoginOptions? | Provider-specific options, such as an email address or custom identity provider token. |
appState? | State to preserve through the browser redirect. |
mfaLevel? | Controls when the multi-factor authentication (MFA) setup screen appears. |
dappShare? | Existing dapp share for a custom authentication connection. |
curve? | Curve used for key generation. The default is Curve.SECP256K1. |
loginHint? | Optional hint that identifies the user to the authentication provider. |
public class LoginParams
{
public AuthConnection authConnection { get; set; }
public string authConnectionId { get; set; }
public string groupedAuthConnectionId { get; set; }
public string appState { get; set; }
public MFALevel mfaLevel { get; set; }
public ExtraLoginOptions extraLoginOptions { get; set; }
public string dappShare { get; set; }
public Curve curve { get; set; } = Curve.SECP256K1;
public string dappUrl { get; set; }
public string loginHint { get; set; }
}
AuthConnection
public enum AuthConnection
{
[EnumMember(Value = "google")]
GOOGLE,
[EnumMember(Value = "facebook")]
FACEBOOK,
[EnumMember(Value = "reddit")]
REDDIT,
[EnumMember(Value = "discord")]
DISCORD,
[EnumMember(Value = "twitch")]
TWITCH,
[EnumMember(Value = "apple")]
APPLE,
[EnumMember(Value = "line")]
LINE,
[EnumMember(Value = "github")]
GITHUB,
[EnumMember(Value = "kakao")]
KAKAO,
[EnumMember(Value = "linkedin")]
LINKEDIN,
[EnumMember(Value = "twitter")]
TWITTER,
[EnumMember(Value = "weibo")]
WEIBO,
[EnumMember(Value = "wechat")]
WECHAT,
[EnumMember(Value = "email_passwordless")]
EMAIL_PASSWORDLESS,
[EnumMember(Value = "email_password")]
EMAIL_PASSWORD,
[EnumMember(Value = "custom")]
CUSTOM,
[EnumMember(Value = "CUSTOM_VERIFIER")]
CUSTOM_VERIFIER,
[EnumMember(Value = "sms_passwordless")]
SMS_PASSWORDLESS,
[EnumMember(Value = "farcaster")]
FARCASTER
}
ExtraLoginOptions
Use extraLoginOptions for provider-specific values, including email hints and custom
authentication tokens.
- Table
- Interface
| Parameter | Description |
|---|---|
additionalParams? | Additional params in Dictionary<string, string> format for OAuth login, use id_token (JWT) to authenticate with Embedded Wallets. |
domain? | Your custom authentication domain in string format. For example, if you are using Auth0, this could be example.au.auth0.com. |
client_id? | Client ID in string format, provided by your login provider used for custom verifier. |
leeway? | The value used to account for clock skew in JWT expirations. The value is in the seconds, and ideally should be no more than 60 seconds, with a maximum of 120 seconds. String value. |
userIdField? | Field in the JWT that maps to the user ID configured in the dashboard. |
isUserIdCaseSensitive? | Whether the user ID field is case-sensitive. |
display? | Allows developers to configure the display of UI. It takes Display as a value. |
prompt? | Prompt shown to the user during the authentication process. It takes Prompt as a value. |
max_age? | Maximum time allowed without reauthentication. If the last time the user authenticated is greater than this value, then the user must reauthenticate. String value. |
ui_locales? | The space separated list of language tags, ordered by preference. For example fr-CA fr en. |
id_token_hint? | It specify the previously issued ID token. String value. |
id_token? | JWT (ID token) to be passed for login. |
access_token? | Access token to pass to the authentication provider. |
flow_type? | Email passwordless flow. Use EmailFlowType.link or EmailFlowType.code. |
login_hint? | It is used to send the user's email address during email passwordless login. String value. |
acr_values? | acr_values |
scope? | The default scope to be used on authentication requests. The default scope defined in the Auth0Client is included along with this scope. String value. |
audience? | The audience, presented as the aud claim in the access token, defines the intended consumer of the token. String value. |
connection? | The name of the connection configured for your application. If null, it will redirect to the Auth0 Login Page and show the Login Widget. String value. |
state? | State |
response_type? | Defines which grant to be execute for the authorization server. String value. |
nonce? | Nonce value |
redirect_uri? | It can be used to specify the default URL, where your custom JWT verifier can redirect your browser to with the result. If you are using Auth0, it must be allowlisted in the Allowed Callback URLs in your Auth0's application. |
public class ExtraLoginOptions {
public Dictionary<string, string> additionalParams { get; set; }
public string domain { get; set; }
public string client_id { get; set; }
public string leeway { get; set; }
public string userIdField { get; set; }
public bool isUserIdCaseSensitive { get; set; }
public Display display { get; set; }
public Prompt prompt { get; set; }
public string max_age { get; set; }
public string ui_locales { get; set; }
public string id_token_hint { get; set; }
public string login_hint { get; set; }
public string id_token { get; set; }
public string access_token { get; set; }
public EmailFlowType flow_type { get; set; } = EmailFlowType.link;
public string acr_values { get; set; }
public string scope { get; set; }
public string audience { get; set; }
public string connection { get; set; }
public string state { get; set; }
public string response_type { get; set; }
public string nonce { get; set; }
public string redirect_uri { get; set; }
}
Curve
The LoginParams class accepts a curve parameter. This parameter can be used to select the elliptic curve to use for the signature.
- SECP256K1
- ED25519
public void login()
{
var authConnection = AuthConnection.GOOGLE;
var options = new LoginParams()
{
authConnection = authConnection,
curve = Curve.SECP256K1
};
web3Auth.login(options);
}
public void login()
{
var authConnection = AuthConnection.GOOGLE;
var options = new LoginParams()
{
authConnection = authConnection,
curve = Curve.ED25519
};
web3Auth.login(options);
}
Sample response
{
"ed25519PrivKey": "666523652352635....",
"privKey": "0ajjsdsd....",
"coreKitKey": "0ajjsdsd....",
"coreKitEd25519PrivKey": "666523652352635....",
"sessionId": "....",
"error": "....",
"userInfo": {
"groupedAuthConnectionId": "grouped-google",
"authConnectionId": "google",
"authConnection": "google",
"userId": "john@gmail.com",
"email": "john@gmail.com",
"name": "John Dash",
"profileImage": "https://lh3.googleusercontent.com/a/Ajjjsdsmdjmnm...",
"dappShare": "<DAPP_SHARE>",
"idToken": "<jwtToken issued by Web3Auth>",
"oAuthIdToken": "<jwtToken issued by OAuth Provider>",
"oAuthAccessToken": "<accessToken issued by OAuth Provider>",
"isMfaEnabled": true
}
}
Examples
- Discord
- Twitch
- Email Passwordless
- JWT
public void login()
{
var authConnection = AuthConnection.GOOGLE;
var options = new LoginParams()
{
authConnection = authConnection
};
web3Auth.login(options);
}
public void login()
{
var authConnection = AuthConnection.FACEBOOK;
var options = new LoginParams()
{
authConnection = authConnection
};
web3Auth.login(options);
}
public void login()
{
var authConnection = AuthConnection.DISCORD;
var options = new LoginParams()
{
authConnection = authConnection
};
web3Auth.login(options);
}
public void login()
{
var authConnection = AuthConnection.TWITCH;
var options = new LoginParams()
{
authConnection = authConnection
};
web3Auth.login(options);
}
public void login()
{
var authConnection = AuthConnection.EMAIL_PASSWORDLESS;
var options = new LoginParams()
{
authConnection = authConnection,
extraLoginOptions = new ExtraLoginOptions()
{
login_hint = "hello@web3auth.io"
}
};
web3Auth.login(options);
}
public void login()
{
var options = new LoginParams
{
authConnection = AuthConnection.CUSTOM,
authConnectionId = "<YOUR_AUTH_CONNECTION_ID>",
extraLoginOptions = new ExtraLoginOptions()
{
id_token = "<YOUR_ID_TOKEN>"
}
};
web3Auth.login(options);
}