Methods

These are the methods provided by the Wepin iOS Login Library.

Methods can be used after initialization of Wepin Login Library.

loginWithOauthProvider

await wepin!.loginWithOauthProvider(params)

An in-app browser will open and proceed to log in to the OAuth provider. To retrieve Firebase login information, you need to execute either the loginWithIdToken() or loginWithAccessToken() method.

Parameters

  • params <WepinLoginOauth2Params>

    • provider <'google'|'naver'|'discord'|'apple'> - Provider for login

    • clientId <String>

  • viewController <UIViewController>

Returns

  • <WepinLoginOauthResult>

    • provider <String> - login provider

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

    • type <WepinOauthTokenType> - type of token

Exception

Example

    do {
        let oauthParams = WepinLoginOauth2Params(provider: "discord", clientId: self.discordClientId)
        let res = try await wepin!.loginWithOauthProvider(params: oauthParams, viewController: self)
        let privateKey = "private key for wepin id/access Token"
        // token sign 
        let sign = wepin!.getSignForLogin(privateKey: privateKey, message: res.token)
        //call loginWithIdToken() or loginWithAccessToken()
    } catch (let error){
        self.tvResult.text = String("Faild: \(error)")
    }

signUpWithEmailAndPassword

await wepin!.signUpWithEmailAndPassword(params: params)

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 requiredEmailVerified error will occur if verification is required. If the user is already registered, an existedEmail error will occur, and you should proceed with the login process by calling loginWithEmailAndPassword. Upon successful login, Firebase login information is returned.

Parameters

  • params <WepinLoginWithEmailParams>

    • email <String> - User email

    • password <String> - User password

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

Returns

  • <WepinLoginResult>

    • provider <WepinLoginProviders>

    • token <WepinFBToken>

      • idToken <String> - wepin firebase idToken

      • refreshToken - wepin firebase refreshToken

Exception

Example

    do {
        let email = "EMAIL-ADDRESS"
        let password = "PASSWORD"
        let params = WepinLoginWithEmailParams(email: email, password: password)
        wepinLoginRes = try await wepin!.signUpWithEmailAndPassword(params: params)
        self.tvResult.text = String("Successed: \(wepinLoginRes)")
    } catch (let error){
        self.tvResult.text = String("Faild: \(error)")
    }

loginWithEmailAndPassword

await wepin!.loginWithEmailAndPassword(params: params)

This function logs in to the Wepin Firebase using your email and password. It returns Firebase login information upon successful login.

Parameters

  • params <WepinLoginWithEmailParams>

    • email <String> - User email

    • password <String> - User password

Returns

  • <WepinLoginResult>

    • provider <WepinLoginProviders>

    • token <WepinFBToken>

      • idToken <String> - wepin firebase idToken

      • refreshToken ` - wepin firebase refreshToken

Exception

Example

    do {
        let email = "EMAIL-ADDRESS"
        let password = "PASSWORD"
        let params = WepinLoginWithEmailParams(email: email, password: password)
        wepinLoginRes = try await wepin!.loginWithEmailAndPassword(params: params)
        self.tvResult.text = String("Successed: \(wepinLoginRes)")
    } catch (let error){
        self.tvResult.text = String("Faild: \(error)")
    }

loginWithIdToken

await wepin!.loginWithIdToken(params: params)

This function logs in to the Wepin Firebase using an external ID token. It returns Firebase login information upon successful login.

Parameters

  • params <WepinLoginOauthIdTokenRequest>

    • 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

  • <WepinLoginResult>

    • provider <WepinLoginProviders>

    • token <WepinFBToken>

      • idToken <String> - wepin firebase idToken

      • refreshToken ` - wepin firebase refreshToken

Exception

Example

    do {
        let token = "ID-TOKEN"
        let sign = wepin!.getSignForLogin(privateKey: privateKey, message: token)
        let params = WepinLoginOauthIdTokenRequest(idToken: token, sign: sign!)
        wepinLoginRes = try await wepin!.loginWithIdToken(params: params)
        
        self.tvResult.text = String("Successed: \(wepinLoginRes)")
    } catch (let error){
        self.tvResult.text = String("Faild: \(error)")
    }

loginWithAccessToken

await wepin!.loginWithAccessToken(params: params)

This function logs in to the Wepin Firebase using an external access token. It returns Firebase login information upon successful login.

Parameters

  • params <WepinLoginOauthAccessTokenRequest>

    • 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 token provided as the first parameter. (Returned value of getSignForLogin())

Returns

  • <WepinLoginResult>

    • provider <WepinLoginProviders>

    • token <WepinFBToken>

      • idToken <String> - wepin firebase idToken

      • refreshToken ` - wepin firebase refreshToken

Exception

Example

    do {
        let token = "ACCESS-TOKEN"
        let sign = wepin!.getSignForLogin(privateKey: privateKey, message: token)
        let params = WepinLoginOauthAccessTokenRequest(provider: "discord", accessToken: token, sign: sign!)
        wepinLoginRes = try await wepin!.loginWithAccessToken(params: params)
        self.tvResult.text = String("Successed: \(wepinLoginRes)")
    } catch (let error){
        self.tvResult.text = String("Faild: \(error)")
    }

getRefreshFirebaseToken

await wepin!.getRefreshFirebaseToken()

This method retrieves the current firebase token's information from the Wepin.

Parameters

  • void

Returns

  • <WepinLoginResult>

    • provider <WepinLoginProviders>

    • token <WepinFBToken>

      • idToken <String> - wepin firebase idToken

      • refreshToken ` - wepin firebase refreshToken

Exception

Example

    do {
        let res = try await wepin!.getRefreshFirebaseToken()
        wepinLoginRes = res
        self.tvResult.text = String("Successed: \(res)")
    } catch (let error){
        self.tvResult.text = String("Faild: \(error)")
    }

loginWepin

await wepin!.loginWepin(params: wepinLoginRes)

This method logs the user into the Wepin application using the specified provider and token.

Parameters

The parameters should utilize the return values from the loginWithEmailAndPassword(), loginWithIdToken(), and loginWithAccessToken() methods within this module.

  • <WepinLoginResult>

    • provider <WepinLoginProviders>

    • token <WepinFBToken>

      • idToken <String> - Wepin Firebase idToken

      • refreshToken ` - Wepin Firebase refreshToken

Returns

  • <WepinUser> - An object containing the user's login status and information. The object includes:

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

    • userInfo <WepinUserInfo> optional - The user's information, including:

      • userId <String> - The user's ID.

      • email <String> - The user's email.

      • provider <WepinLoginProviders> - 'google'|'apple'|'naver'|'discord'|'email'|'external_token'

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

    • walletId <String> optional - The user's wallet ID.

    • userStatus: <WepinUserStatus> optional - The user's status of wepin login. including:

      • loginStatus: <WepinLoginStatus> - 'complete' | 'pinRequired' | 'registerRequired' - If the user's loginStatus value is not complete, it must be registered in the wepin.

      • pinRequired: optional

    • token: <WepinToken> optional - The user's token of wepin.

      • refresh: <String>

      • access <String>

Exception

Example

    do {
        let res = try await wepin!.loginWepin(params: wepinLoginRes)
        wepinLoginRes = nil
        self.tvResult.text = String("Successed: \(res)")
    } catch (let error){
        self.tvResult.text = String("Faild: \(error)")
    }

getCurrentWepinUser

await wepin!.getCurrentWepinUser()

This method retrieves the current logged-in user's information from the Wepin.

Parameters

  • void

Returns

  • <WepinUser> - An object containing the user's login status and information. The object includes:

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

    • userInfo <WepinUserInfo> optional - The user's information, including:

      • userId <String> - The user's ID.

      • email <String> - The user's email.

      • provider <WepinLoginProviders> - 'google'|'apple'|'naver'|'discord'|'email'|'external_token'

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

    • walletId <String> optional - The user's wallet ID.

    • userStatus: <WepinUserStatus> optional - The user's status of wepin login. including:

      • loginStatus: <WepinLoginStatus> - 'complete' | 'pinRequired' | 'registerRequired' - If the user's loginStatus value is not complete, it must be registered in the wepin.

      • pinRequired: optional

    • token: <WepinToken> optional - The user's token of wepin.

      • refresh: <String>

      • access <String>

Exception

Example

    do {
        let res = try await wepin!.getCurrentWepinUser()
        self.tvResult.text = String("Successed: \(res)")
    } catch (let error){
        self.tvResult.text = String("Faild: \(error)")
    }

logoutWepin

await wepin!.logoutWepin()

This method logs out the user logged into Wepin.

Parameters

  • void

Returns

  • <Bool>

Exception

Example

    do {
        let res = try await wepin!.logoutWepin()
        self.tvResult.text = String("Successed: \(res)")
    } catch (let error){
        self.tvResult.text = String("Faild: \(error)")
    }

getSignForLogin

Generates signatures to verify the issuer. It is mainly used to generate signatures for login-related information such as ID tokens and access tokens.

wepin!.getSignForLogin(privateKey: privateKey, message: "")

Parameters

  • privKey <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 authentication key (privKey) must be stored securely and must not be exposed to the outside. It is recommended to execute the getSignForLogin() method on the backend rather than the frontend for enhanced security and protection of sensitive information.

Example

let privKey = '0400112233445566778899001122334455667788990011223344556677889900'
let idToken = 'idtokenabcdef'
let sign = wepin!.getSignForLogin(privateKey: privKey, message: idToken)

finalize

wepin!.finalize()

This method finalizes the Wepin Login Library.

Parameters

  • void

Returns

  • void

Example

wepin!.finalize()

WepinLoginError

Last updated