Wepin Login Library for iOS. This package is exclusively available for use in iOS environments.
After signing up for Wepin Workspace, go to the development tools menu and enter the information for each app platform to receive your App ID and App Key.
- iOS 13+
- Swift 5.x
WepinLogin is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'WepinLogin'
⚠️ Notice - Resolution for Build ErrorsWhen building the WepinLogin library, the following error may occur:
SDK does not contain 'libarclite' at the path '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/arc/libarclite_iphonesimulator.a'; try increasing the minimum deployment target
This error can be resolved by changing the "Minimum Deployment Target" setting of the secp256k1 library. Please update the "Minimum Deployment Target" setting of the secp256k1 library project to an iOS version supported by Xcode. This should resolve the build error you are encountering.
import WepinLogin
You must add the app's URL scheme to the Info.plist file. This is necessary for redirection back to the app after the authentication process.
The value of the URL scheme should be 'wepin.' + your Wepin app id
.
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<string>Editor</string>
<key>CFBundleURLName</key>
<string>unique name</string>
<array>
<string>wepin + your Wepin app id</string>
</array>
</dict>
</array>
Before using the created instance, initialize it using the App ID and App Key.
let appKey: String = "Wepin-App-Key"
let appId: String = "Wepin-App-ID"
var wepin: WepinLogin? = nil
let initParam = WepinLoginParams(appId: appId, appKey: appKey)
wepin = WepinLogin(initParam)
// Call initialize function
do{
let res = try await wepin!.initialize()
self.tvResult.text = String("Successed: " + String(res!))
} catch (let error){
self.tvResult.text = String("Faild: \(error)")
}
wepin!.isInitialized()
The isInitialized()
method checks Wepin Login Library is initialized.
- <Bool>
- true if Wepin Login Library is already initialized.
Methods can be used after initialization of Wepin Login Library.
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.
params
<WepinLoginOauth2Params>provider
<'google'|'naver'|'discord'|'apple'> - Provider for loginclientId
<String>
viewController
<UIViewController>
- <WepinLoginOauthResult>
provider
<String> - login providertoken
<String> - accessToken (if provider is "naver" or "discord") or idToken (if provider is "google" or "apple")type
<WepinOauthTokenType> - type of token
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)")
}
await wepin!.signUpWithEmailAndPassword(params: params)
This function signs up on Wepin Firebase with your email and password. It returns Firebase login information upon successful signup.
params
<WepinLoginWithEmailParams>email
<String> - User emailpassword
<String> - User passwordlocale
<String> - optional Language for the verification email (default value: "en")
- <WepinLoginResult>
provider
<WepinLoginProviders>token
<WepinFBToken>idToken
<String> - wepin firebase idTokenrefreshToken
- wepin firebase refreshToken
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)")
}
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.
params
<WepinLoginWithEmailParams>email
<String> - User emailpassword
<String> - User password
- <WepinLoginResult>
provider
<WepinLoginProviders>token
<WepinFBToken>idToken
<String> - wepin firebase idTokenrefreshToken
` - wepin firebase refreshToken
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)")
}
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.
params
<WepinLoginOauthIdTokenRequest>idToken
<String> - ID token value to be used for loginsign
<String> - Signature value for the token provided as the first parameter.(Returned value of getSignForLogin())
- <WepinLoginResult>
provider
<WepinLoginProviders>token
<WepinFBToken>idToken
<String> - wepin firebase idTokenrefreshToken
` - wepin firebase refreshToken
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)")
}
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.
params
<WepinLoginOauthAccessTokenRequest>provider
<"naver"|"discord"> - Provider that issued the access tokenaccessToken
<String> - Access token value to be used for loginsign
<String> - Signature value for the token provided as the first parameter. (Returned value of getSignForLogin())
- <WepinLoginResult>
provider
<WepinLoginProviders>token
<WepinFBToken>idToken
<String> - wepin firebase idTokenrefreshToken
` - wepin firebase refreshToken
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)")
}
await wepin!.getRefreshFirebaseToken()
This method retrieves the current firebase token's information from the Wepin.
- void
- <WepinLoginResult>
provider
<WepinLoginProviders>token
<WepinFBToken>idToken
<String> - wepin firebase idTokenrefreshToken
` - wepin firebase refreshToken
do {
let res = try await wepin!.getRefreshFirebaseToken()
wepinLoginRes = res
self.tvResult.text = String("Successed: \(res)")
} catch (let error){
self.tvResult.text = String("Faild: \(error)")
}
await wepin!.loginWepin(params: wepinLoginRes)
This method logs the user into the Wepin application using the specified provider and token.
The parameters should utilize the return values from the loginWithEmailAndPassword()
, loginWithIdToken()
, and loginWithAccessToken()
methods within this module.
- - If the parameter value does not exist, it checks the login session status and refreshes the login session.
provider
<WepinLoginProviders>token
<WepinFBToken>idToken
<String> - Wepin Firebase idTokenrefreshToken
` - Wepin Firebase refreshToken
- <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>
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)")
}
await wepin!.getCurrentWepinUser()
This method retrieves the current logged-in user's information from the Wepin.
- void
- <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>
do {
let res = try await wepin!.getCurrentWepinUser()
self.tvResult.text = String("Successed: \(res)")
} catch (let error){
self.tvResult.text = String("Faild: \(error)")
}
await wepin!.logoutWepin()
The logoutWepin()
method logs out the user logged into Wepin.
- void
- <Bool>
do {
let res = try await wepin!.logoutWepin()
self.tvResult.text = String("Successed: \(res)")
} catch (let error){
self.tvResult.text = String("Faild: \(error)")
}
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: "")
privKey
<String> - The authentication key used for signature generation.message
<String> - The message or payload to be signed.
- String - The generated signature.
‼️ Caution‼️ The authentication key (
privKey
) must be stored securely and must not be exposed to the outside. It is recommended to execute thegetSignForLogin()
method on the backend rather than the frontend for enhanced security and protection of sensitive information.
- java
let privKey = '0400112233445566778899001122334455667788990011223344556677889900' let idToken = 'idtokenabcdef' let sign = wepin!.getSignForLogin(privateKey: privKey, message: idToken)
wepin!.finalize()
The finalize()
method finalizes the Wepin Login Library.
- void
- void
wepin!.finalize()
To run the example project, clone the repo, and run pod install
from the Example directory first.
Error | Error Description |
---|---|
invalidParameters |
One or more parameters provided are invalid or missing. |
notInitialized |
The WepinLoginLibrary has not been properly initialized. |
invalidAppKey |
The Wepin app key is invalid. |
invalidLoginProvider |
The login provider specified is not supported or is invalid. |
invalidToken |
The token does not exist. |
invalidLoginSession |
The login session information does not exist. |
userCancelled |
The user has cancelled the operation. |
unkonwError(message: String) |
An unknown error has occurred, and the cause is not identified. |
notConnectedInternet |
The system is unable to detect an active internet connection. |
failedLogin |
The login attempt has failed due to incorrect credentials or other issues. |
alreadyLogout |
The user is already logged out, so the logout operation cannot be performed again. |
alreadyInitialized |
The WepinLoginLibrary is already initialized, so the logout operation cannot be performed again. |
invalidEmailDomain |
The provided email address's domain is not allowed or recognized by the system. |
failedSendEmail |
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. |
requiredEmailVerified |
Email verification is required to proceed with the requested operation. |
incorrectEmailForm |
The provided email address does not match the expected format. |
incorrectPasswordForm |
The provided password does not meet the required format or criteria. |
notInitializedNetwork |
The network or connection required for the operation has not been properly initialized. |
requiredSignupEmail |
The user needs to sign up with an email address to proceed. |
failedEmailVerified |
The WepinLoginLibrary encountered an issue while attempting to verify the provided email address. |
failedPasswordStateSetting |
The WepinLoginLibrary failed to set state of the password. |
failedPasswordSetting |
The WepinLoginLibrary failed to set the password. |
existedEmail |
The provided email address is already registered in Wepin. |