Logging in a User
To login in a user, you can use the login
method. It will trigger login flow will navigate the user to a browser model allowing the user to login into the service. You can pass in the supported providers to the login method for specific social logins such as GOOGLE, APPLE, FACEBOOK, etc., and do whitelabel login.
Parameters
The login
method takes in LoginParams
as a required input.
- Table
- Class
Parameter | Description |
---|---|
loginProvider | It sets the OAuth login method to be used. You can use any of the supported values are GOOGLE , FACEBOOK , REDDIT , DISCORD , TWITCH , APPLE , LINE , GITHUB , KAKAO , LINKEDIN , TWITTER , WEIBO , WECHAT , EMAIL_PASSWORDLESS , JWT , SMS_PASSWORDLESS , and FARCASTER . |
extraLoginOptions? | It can be used to set the OAuth login options for corresponding loginProvider . For instance, you'll need to pass user's email address as. Default value for the field is null , and it accepts ExtraLoginOptions as a value. |
redirectUrl? | Url where user will be redirected after successfull login. By default user will be redirected to same page where login will be initiated. Default value for the field is null , and accepts Uri as a value. |
appState? | It can be used to keep track of the app state when user will be redirected to app after login. Default is null , and accepts String as a value. |
mfaLevel? | Customize the MFA screen shown to the user during OAuth authentication. Default value for field is MFALevel.DEFAULT , which shows MFA screen every 3rd login. It accepts MFALevel as a value. |
dappShare? | Custom verifier logins can get a dapp share returned to them post successful login. This is useful if the dapps want to use this share to allow users to login seamlessly. It accepts String as a value. |
curve? | It will be used to determine the public key encoded in the jwt token which returned in getUserInfo function after user login. This parameter won't change format of private key returned by We3Auth. Private key returned by getPrivKey is always secp256k1. To get the ed25519 key you can use getEd25519PrivKey method. The default value is Curve.SECP256K1 . |
data class LoginParams(
val loginProvider: Provider,
var dappShare: String? = null,
val extraLoginOptions: ExtraLoginOptions? = null,
@Transient var redirectUrl: Uri? = null,
val appState: String? = null,
val mfaLevel: MFALevel? = null,
val curve: Curve? = Curve.SECP256K1
)
enum class Provider {
@SerializedName("google")
GOOGLE,
@SerializedName("facebook")
FACEBOOK,
@SerializedName("reddit")
REDDIT,
@SerializedName("discord")
DISCORD,
@SerializedName("twitch")
TWITCH,
@SerializedName("apple")
APPLE,
@SerializedName("line")
LINE,
@SerializedName("github")
GITHUB,
@SerializedName("kakao")
KAKAO,
@SerializedName("linkedin")
LINKEDIN,
@SerializedName("twitter")
TWITTER,
@SerializedName("weibo")
WEIBO,
@SerializedName("wechat")
WECHAT,
@SerializedName("email_passwordless")
EMAIL_PASSWORDLESS,
@SerializedName("jwt")
JWT,
@SerializedName("sms_passwordless")
SMS_PASSWORDLESS,
@SerializedName("farcaster")
FARCASTER
}
Usage
import com.web3auth.core.Web3Auth
import com.web3auth.core.types.Web3AuthOptions
val web3Auth = Web3Auth(
Web3AuthOptions(
context = this,
clientId = "YOUR_WEB3AUTH_CLIENT_ID", // Pass over your Web3Auth Client ID from Developer Dashboard
network = Network.MAINNET,
redirectUrl = Uri.parse("{YOUR_APP_PACKAGE_NAME}://auth"),
)
)
val loginCompletableFuture: CompletableFuture<Web3AuthResponse> = web3Auth.login(
LoginParams(Provider.GOOGLE)
)
Examples
- Discord
- Twitch
- Email Passwordless
- SMS Passwordless
- Farcaster
- JWT
import com.web3auth.core.Web3Auth
import com.web3auth.core.types.Web3AuthOptions
val web3Auth = Web3Auth(
Web3AuthOptions(
context = this,
clientId = "YOUR_WEB3AUTH_CLIENT_ID", // Pass over your Web3Auth Client ID from Developer Dashboard
network = Network.MAINNET,
redirectUrl = Uri.parse("{YOUR_APP_PACKAGE_NAME}://auth"),
)
)
val loginCompletableFuture: CompletableFuture<Web3AuthResponse> = web3Auth.login(
LoginParams(Provider.GOOGLE)
)
import com.web3auth.core.Web3Auth
import com.web3auth.core.types.Web3AuthOptions
val web3Auth = Web3Auth(
Web3AuthOptions(
context = this,
clientId = "YOUR_WEB3AUTH_CLIENT_ID", // Pass over your Web3Auth Client ID from Developer Dashboard
network = Network.MAINNET,
redirectUrl = Uri.parse("{YOUR_APP_PACKAGE_NAME}://auth"),
)
)
val loginCompletableFuture: CompletableFuture<Web3AuthResponse> = web3Auth.login(
LoginParams(Provider.FACEBOOK)
)
import com.web3auth.core.Web3Auth
import com.web3auth.core.types.Web3AuthOptions
val web3Auth = Web3Auth(
Web3AuthOptions(
context = this,
clientId = "YOUR_WEB3AUTH_CLIENT_ID", // Pass over your Web3Auth Client ID from Developer Dashboard
network = Network.MAINNET,
redirectUrl = Uri.parse("{YOUR_APP_PACKAGE_NAME}://auth"),
)
)
val loginCompletableFuture: CompletableFuture<Web3AuthResponse> = web3Auth.login(
LoginParams(Provider.DISCORD)
)
import com.web3auth.core.Web3Auth
import com.web3auth.core.types.Web3AuthOptions
val web3Auth = Web3Auth(
Web3AuthOptions(
context = this,
clientId = "YOUR_WEB3AUTH_CLIENT_ID", // Pass over your Web3Auth Client ID from Developer Dashboard
network = Network.MAINNET,
redirectUrl = Uri.parse("{YOUR_APP_PACKAGE_NAME}://auth"),
)
)
val loginCompletableFuture: CompletableFuture<Web3AuthResponse> = web3Auth.login(
LoginParams(Provider.TWITCH)
)
import com.web3auth.core.Web3Auth
import com.web3auth.core.types.Web3AuthOptions
val web3Auth = Web3Auth(
Web3AuthOptions(
context = this,
clientId = "YOUR_WEB3AUTH_CLIENT_ID", // Pass over your Web3Auth Client ID from Developer Dashboard
network = Network.MAINNET,
redirectUrl = Uri.parse("{YOUR_APP_PACKAGE_NAME}://auth"),
)
)
val loginCompletableFuture: CompletableFuture<Web3AuthResponse> = web3Auth.login(
LoginParams(
Provider.EMAIL_PASSWORDLESS,
extraLoginOptions = ExtraLoginOptions(login_hint = "hello@web3auth.io")
)
)
import com.web3auth.core.Web3Auth
import com.web3auth.core.types.Web3AuthOptions
val web3Auth = Web3Auth( Web3AuthOptions( context = this, clientId = "YOUR_WEB3AUTH_CLIENT_ID", // Pass over your Web3Auth Client ID from Developer Dashboard network = Network.MAINNET, redirectUrl = Uri.parse("{YOUR_APP_PACKAGE_NAME}://auth"), ) )
// focus-start val loginCompletableFuture: CompletableFuture<Web3AuthResponse> = web3Auth.login( LoginParams( Provider.SMS_PASSWORDLESS, extraLoginOptions = ExtraLoginOptions(login_hint = "+91-9911223344") ) ) // focus-end
import com.web3auth.core.Web3Auth
import com.web3auth.core.types.Web3AuthOptions
val web3Auth = Web3Auth(
Web3AuthOptions(
context = this,
clientId = "YOUR_WEB3AUTH_CLIENT_ID", // Pass over your Web3Auth Client ID from Developer Dashboard
network = Network.MAINNET,
redirectUrl = Uri.parse("{YOUR_APP_PACKAGE_NAME}://auth"),
)
)
val loginCompletableFuture: CompletableFuture<Web3AuthResponse> = web3Auth.login(
LoginParams(Provider.Farcaster)
)
Usage
import com.web3auth.core.Web3Auth
import com.web3auth.core.types.Web3AuthOptions
val web3Auth = Web3Auth(
Web3AuthOptions(
context = this,
clientId = "YOUR_WEB3AUTH_CLIENT_ID", // Pass over your Web3Auth Client ID from Developer Dashboard
network = Network.MAINNET,
redirectUrl = Uri.parse("{YOUR_APP_PACKAGE_NAME}://auth"),
)
)
val loginCompletableFuture: CompletableFuture<Web3AuthResponse> = web3Auth.login(
LoginParams(
Provider.JWT,
extraLoginOptions = ExtraLoginOptions(id_token = "your_jwt_token")
)
)