Methods

Below are the methods provided by the Wepin Compose Multiplatform Login Library.

loginWithOauthProvider

suspend fun loginWithOauthProvider(params: LoginOauth2Params): LoginOauthResult

Opens an in-app browser and logs in to the OAuth provider. To retrieve Firebase login information, you need to call the loginWithIdToken() or loginWithAccessToken() methods.

Parameters

  • params <LoginOauth2Params>

    • provider <'google'|'naver'|'discord'|'apple'> The OAuth login Provider

    • clientId <String> The client ID of the OAuth login provider

Returns

  • <LoginOauthResult>

    • provider <String> The name of the OAuth provider used.

    • token <String> The accessToken (if provider is "naver" or "discord") or idToken (if provider is "google" or "apple")

    • type <OauthTokenType> The type of OAuth token (e.g., idToken, accessToken)

Exception

Example

coroutineScope.launch { 
    wepinLogin.loginWithOauthProvider(LoginOauth2Params(
        provider = "google",
        clientId = "your-google-client-id",
    ))
}

signUpWithEmailAndPassword

suspend fun signUpWithEmailAndPassword(params: LoginWithEmailParams): LoginResult

Sign up for Wepin Firebase with an email and password. For users who have not yet registered, a verification email will be sent, and a REQUIRED_EMAIL_VERIFIED error will occur if verification is required. If the user is already registered, an EXISTED_EMAIL error will occur, and you should proceed with the login process by calling loginWithEmailAndPassword. Upon successful login, Firebase login information is returned.

Parameters

  • params <LoginWithEmailParams>

    • email <String> User email

    • password <String> User password

    • locale <String> Language for the verification email (default value: "en")

Returns

  • <LoginResult>

    • provider <Providers.EMAIL> The provider used for the login (in this case, 'email')

    • token <FBToken>

      • idToken <String> The Wepin Firebase ID token

      • refreshToken <String> The Wepin Firebase refresh token

Exception

Example

coroutineScope.launch { 
    wepinLogin.signUpWithEmailAndPassword(
        LoginWithEmailParams(
            email = "abc@defg.com", 
            password = "abcdef123$"
        )
    )
}

loginWithEmailAndPassword

suspend fun loginWithEmailAndPassword(params: LoginWithEmailParams): LoginResult

Logs in to Wepin Firebase using an email and password. If the login is successful, it returns Firebase login information.

Parameters

  • params <LoginWithEmailParams>

    • email <String> User email

    • password <String> User password

Returns

  • <LoginResult>

    • provider <Providers.EMAIL> The provider used for the login (in this case, 'email')

    • token <FBToken>

      • idToken <String> The Wepin Firebase ID token

      • refreshToken <String> The Wepin Firebase refresh token

Exception

Example

coroutineScope.launch { 
    wepinLogin.loginWithEmailAndPassword(
        LoginWithEmailParams(
            email = "abc@defg.com", 
            password = "abcdef123$"
        )
    )
}

loginWithIdToken

suspend fun loginWithIdToken(params: LoginOauthIdTokenRequest): LoginResult

Logs in to Wepin Firebase using an external ID token. If the login is successful, it returns Firebase login information.

Parameters

  • params <LoginOauthIdTokenRequest>

    • idToken <String> ID token value to be used for login

    • sign <String> Signature value for the token provided as the first parameter (returned value of getSignForLogin())

Returns

  • <LoginResult>

    • provider <Providers.EXTERNAL_TOKEN> The provider used for the login

    • token <FBToken>

      • idToken <String> The Wepin Firebase ID token

      • refreshToken <String> The Wepin Firebase refresh token

Exception

Example

coroutineScope.launch { 
    wepinLogin.loginWithIdToken(
        LoginOauthIdTokenRequest(
            idToken = "eyJHGci0...adQssw5c", 
            sign = "9753d4dc...c63466b9"
        )
    )
}

loginWithAccessToken

suspend fun loginWithAccessToken(params: LoginOauthAccessTokenRequest): LoginResult

Logs in to Wepin Firebase using an external access token. If the login is successful, it returns Firebase login information.

Parameters

  • params <LoginOauthAccessTokenRequest>

    • provider <'naver' / 'discord'> Provider that issued the access token.

    • accessToken <String> Access token value to be used for login.

    • sign <String> Signature value for the Access token (returned value of getSignForLogin()).

Returns

  • <LoginResult>

    • provider <Providers.EXTERNAL_TOKEN> The provider used for the login

    • token <FBToken>

      • idToken <String> The Wepin Firebase ID token

      • refreshToken <String> The Wepin Firebase refresh token

Exception

Example

coroutineScope.launch { 
    wepinLogin.loginWithAccessToken(
        LoginOauthAccessTokenRequest(
            provider = "naver",
            accessToken = "eyJHGci0...adQssw5c", 
            sign = "9753d4dc...c63466b9"
        )
    )
}

getRefreshFirebaseToken

suspend fun getRefreshFirebaseToken(): LoginResult

Retrieves information on the current Wepin Firebase token.

Parameters

  • None

Returns

  • <LoginResult>

    • provider <Providers.EXTERNAL_TOKEN> The provider used for the login

    • token <FBToken>

      • idToken <String> The Wepin Firebase ID token

      • refreshToken <String> The Wepin Firebase refresh token.

Exception

Example

coroutineScope.launch { 
    wepinLogin.getRefreshFirebaseToken()
}

loginWepin

suspend fun loginWepin(params: LoginResult?): WepinUser

Logs the user into Wepin using the Wepin Firebase token.

Parameters

Returns

  • <WepinUser>

    • status <'success' | 'fail'> The login status

    • userInfo <UserInfo> (optional) The user's information, including:

      • userId <String> The user's ID

      • email <String> The user's email

      • provider <'google' | 'apple' | 'naver' | 'discord' | 'email' | 'external_token'> The login provider

      • use2FA <Boolean> Whether the user uses two-factor authentication

    • walletId <String> The user's wallet ID

    • userStatus <UserStatus> (optional) The user's Wepin login status, including:

      • loginStatus <WepinLoginStatus - 'complete' | 'pinRequired' | 'registerRequired'> If the user's loginStatus value is not 'complete', the user must register with Wepin.

      • pinRequired <Boolean> Whether a PIN is required

    • token <Token> The user's Wepin token

      • accessToken <String> The access token

      • refreshToken <String> The refresh token

Exception

Example

coroutineScope.launch { 
    val wepinLogin: WepinLogin = WepinLogin(
        WepinLoginOptions(
            context = context,
            appId = appId,
            appKey = appKey
        )
    )
    wepinLogin.init()
    
    val response = wepinLogin.loginWithOauthProvider(
        LoginOauth2Params(
            provider = "google",
            clientId = "your-google-client-id"
        )
    )
    val sign = wepinLogin.getSignForLogin(
        privateKeyHex = "private key", 
        message = response.token
    )
    var loginResult: LoginResult? = null
    if (response.provider == "naver" || response.provider = "discord") {
        loginResult = wepinLogin.loginWithAccessToken(
            LoginOauthAccessTokenRequest(
                provider = response.provider,
                token = response.token,
                sign = sign
            )
        )
    } else {
        loginResult = wepinLogin.loginWithIdToken(
            LoginOauthIdTokenRequest(
                idToken = response.token,
                sign = sign
            )
        )
    }
    val userInfo = wepinLogin.loginWepin(loginResult)
    val userStatus = userInfo.userStatus
    if (userStatus.loginStatus != WepinLoginStatus.COMPLETE) {
        //Wepin Register 코드..
    }
}

getCurrentWepinUser

suspend fun getCurrentWepinUser(): WepinUser

Retrieves information about the currently logged-in user in Wepin.

Parameters

  • None

Returns

  • <WepinUser>

    • status <'success' | 'fail'> The login status

    • userInfo <UserInfo> (optional) The user's information, including:

      • userId <String> The user's ID

      • email <String> The user's email

      • provider <'google' | 'apple' | 'naver' | 'discord' | 'email' | 'external_token'> The login provider

      • use2FA <Boolean> Whether the user uses two-factor authentication

    • walletId <String> The user's wallet ID

    • userStatus <UserStatus> (optional) The user's Wepin login status, including:

      • loginStatus <WepinLoginStatus - 'complete' | 'pinRequired' | 'registerRequired'> If the user's loginStatus value is not 'complete', the user must register with Wepin.

      • pinRequired <Boolean> Whether a PIN is required

    • token <Token> The user's Wepin token

      • accessToken <String> The access token

      • refreshToken <String> The refresh token

Exception

Example

coroutineScope.launch {
    val userInfo = wepinLogin.getCurrentWepinUser()
    val userStatus = userInfo.userStatus!!
    if (userStatus.loginStatus != WepinLoginStatus.COMPLETE) {
        //Wepin Register 코드..
    }
}

logoutWepin

suspend fun logoutWepin(): Boolean

Logs out the currently logged-in user from Wepin.

Parameters

  • None

Returns

  • <Boolean>

Exception

Example

coroutineScope.launch {
    wepinLogin.logoutWepin()
}

getSignForLogin

fun getSignForLogin(privateKeyHex: String, message: String): String

Generates a signature for verifying the issuer. This method is mainly used to generate signatures for login-related information such as ID tokens and access tokens.

Parameters

  • privateKey <String> The authentication key used for signature generation

  • message <String> The message or payload to be signed

The key for signing can be obtained from Wepin Workspace. In the Development Tools menu, click Get your authentication key on the Login tab to retrieve the authentication key.

Returns

  • <String> - The generated signature

The private key (privateKey) must be securely stored and should not be exposed externally. To enhance security and protect sensitive information, it is recommended to execute the getSignForLogin() method on the backend rather than the frontend. For details on how to generate signatures, please refer to the following document:

Exception

Example

wepinLogin.getSignForLogin(
    privateKeyHex = "private key", 
    message = "idtokenoraccesstoken"
) 

finalize

fun finalize()

Terminates the Wepin Login Library.

Parameters

  • None

Returns

  • None

Exception

Example

wepinLogin.finalize()

Wepin Error

Last updated