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

Signs up to Wepin Firebase using an email and password. If the sign-up is successful, it returns Firebase login information.

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

Error CodeError MessageError Description

INVALID_APP_KEY

"Invalid app key"

The Wepin app key is invalid.

INVALID_PARAMETER `

"Invalid parameter"

One or more parameters provided are invalid or missing.

INVALID_LOGIN_PROVIDER

"Invalid login provider"

The login provider specified is not supported or is invalid.

INVALID_TOKEN

"Token does not exist"

The token does not exist.

INVALID_LOGIN_SESSION

"Invalid Login Session"

The login session information does not exist.

NOT_INITIALIZED_ERROR

"Not initialized error"

The WepinLoginLibrary has not been properly initialized.

ALREADY_INITIALIZED_ERROR

"Already initialized"

The WepinLoginLibrary is already initialized, so the logout operation cannot be performed again.

NOT_ACTIVITY

"Context is not activity"

The Context is not an activity

USER_CANCELLED

"User cancelled"

The user has cancelled the operation.

UNKNOWN_ERROR

"An unknown error occurred"

An unknown error has occurred, and the cause is not identified.

NOT_CONNECTED_INTERNET

"No internet connection"

The system is unable to detect an active internet connection.

FAILED_LOGIN

"Failed to Oauth log in"

The login attempt has failed due to incorrect credentials or other issues.

ALREADY_LOGOUT

"Already Logout"

The user is already logged out, so the logout operation cannot be performed again.

INVALID_EMAIL_DOMAIN

"Invalid email domain"

The provided email address's domain is not allowed or recognized by the system.

FAILED_SEND_EMAIL

"Failed to send email"

The system encountered an error while sending an email. This is because the email address is invalid or we sent verification emails too often. Please change your email or try again after 1 minute.

REQUIRED_EMAIL_VERIFIED

"Email verification required"

Email verification is required to proceed with the requested operation.

INCORRECT_EMAIL_FORM

"Incorrect email format"

The provided email address does not match the expected format.

INCORRECT_PASSWORD_FORM

"Incorrect password format"

The provided password does not meet the required format or criteria.

NOT_INITIALIZED_NETWORK

"Network Manager not initialized"

The network or connection required for the operation has not been properly initialized.

REQUIRED_SIGNUP_EMAIL

"Email sign-up required."

The user needs to sign up with an email address to proceed.

FAILED_EMAIL_VERIFIED

"Failed to verify email."

The WepinLoginLibrary encountered an issue while attempting to verify the provided email address.

FAILED_PASSWORD_SETTING

"Failed to set password."

The WepinLoginLibrary failed to set the password.

EXISTED_EMAIL

"Email already exists."

The provided email address is already registered in Wepin.

Last updated