Wepin Login Library for ComposeMultiplatform. This package is exclusively available for use in Android and 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.
- Android API version 24 or newer is required.
- iOS 13+
- Swift 5.x
val commonMain by getting { implementation("io.wepin:wepin-compose-sdk-login-v1:0.0.2") api("io.wepin:wepin-compose-sdk-login-v1:0.0.2") }
for iOS add cocoapods plugin in build.gradle.kts
plugins {
kotlin("native.cocoapods")
}
cocoapods {
summary = "Some description for a Kotlin/Native module"
homepage = "Link to a Kotlin/Native module homepage"
ios.deploymentTarget = "13.0"
version = "0.0.1"
pod("AppAuth") {
version = "~> 1.7.5"
}
pod("secp256k1") {
version = "~> 0.1.0"
}
pod("JFBCrypt") {
version = "~> 0.1"
}
}
For iOS, You must add Podfile in iosApp Folder for install ios dependencies.
# Uncomment the next line to define a global platform for your project
platform :ios, '13.0'
target 'iosApp' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!
# Pods for iosApp
pod 'shared', :path => '../shared'
end
post_install do |installer|
installer.generated_projects.each do |project|
project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '13.0'
end
end
end
endAfter Sync Project with Gradle Files, Do pod install
Add the below line in your app's AndroidManifest.xml file
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
-
Android Deep Link scheme format :
wepin. + Your Wepin App IDWhen a custom scheme is used, WepinLogin Library can be easily configured to capture all redirects using this custom scheme through a manifest placeholder:
Add the below lines in your app's build.gradle.kts file
// For Deep Link => RedirectScheme Format : wepin. + Wepin App ID android.defaultConfig.manifestPlaceholders = [ 'appAuthRedirectScheme': 'wepin.{{YOUR_WEPIN_APPID}}' ]
Add the below line in your app's AndroidManifest.xml file
android:name="com.wepin.cm.loginlib.RedirectUriReceiverActivity" android:exported="true"> <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:host="oauth2redirect" android:scheme="${appAuthRedirectScheme}" /> </intent-filter> </activity>
-
iOS 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> import com.wepin.cm.loginlib.WepinLoginCreate instance of WepinLoginLibrary in shared code to use wepin and pass your activity(Android) or ViewController(iOS) as a parameter This method is a suspend method, so you can call it within another suspend method or in a coroutine.
class LoginManager(context: Any) {
private val appId = "WEPIN_APP_ID"
private val appKey = "WEPIN_APP_KEY"
private val privateKey = "WEPIN_APP_PRIVATE_KEY"
private val initOptions = WepinLoginOptions(
context = context,
appId = appId,
appKey = appKey
)
private val wepinLogin = WepinLogin(initOptions)
private fun initLoginManager(coroutineScope: CoroutineScope, setText: (String) -> Unit) {
coroutineScope.launch {
setText(
if (wepinLogin.isInitialized()) {
"It's already Initialized"
} else {
wepinLogin.init().toString()
},
)
}
}
}wepinLogin.isInitialized()The isInitialized() method checks Wepin Login Library is initialized.
- <Boolean>
- true if Wepin Login Library is already initialized.
Methods can be used after initialization of Wepin Login Library.
wepinLogin.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. This method is a suspend method, so you can call it within another suspend method or in a coroutine.
-
params<LoginOauth2Params>-
provider<'google'|'naver'|'discord'|'apple'> - Provider for login -
clientId<String>
-
- <LoginOauthResult>
-
provider<String> - login provider -
token<String> - accessToken (if provider is "naver" or "discord") or idToken (if provider is "google" or "apple") -
type<OauthTokenType> - type of token
-
- kotlin
val loginOption = LoginOauth2Params( provider = "discord", clientId = getString(R.string.default_discord_client_id), ) coroutineScope.launch { try { val loginResponse = wepinLogin.loginWithOauthProvider(loginOption) } catch (e: Exception) { setResponse(null) setText("fail - $e") } }
wepinLogin.signUpWithEmailAndPassword(params)This function signs up on Wepin Firebase with your email and password. It returns Firebase login information upon successful signup. This method is a suspend method, so you can call it within another suspend method or in a coroutine.
-
params<LoginWithEmailParams>-
email<String> - User email -
password<String> - User password -
locale<String> - optional Language for the verification email (default value: "en")
-
- <LoginResult>
-
provider<Providers.EMAIL> -
token<FBToken>-
idToken<String> - wepin firebase idToken -
refreshToken<String> - wepin firebase refreshToken
-
-
- kotlin
val loginOption = LoginWithEmailParams(email, password) coroutineScope.launch { try { val response = wepinLogin.signUpWithEmailAndPassword(loginOption) setResponse(response) setText("$response") } catch (e: Exception) { setText("fail - $e") } }
wepinLogin.loginWithEmailAndPassword(params)This function logs in to the Wepin Firebase using your email and password. It returns Firebase login information upon successful login. This method is a suspend method, so you can call it within another suspend method or in a coroutine.
-
params<LoginWithEmailParams>-
email<String> - User email -
password<String> - User password
-
- <LoginResult>
-
provider<Providers.EMAIL> -
token<FBToken>-
idToken<String> - wepin firebase idToken -
refreshToken<String> - wepin firebase refreshToken
-
-
- kotlin
val loginOption = LoginWithEmailParams(email, password) coroutineScope.launch { try { val response = wepinLogin.loginWithEmailAndPassword(loginOption) setResponse(response) setText("$response") } catch (e: Exception) { setText("fail - $e") } }
wepinLogin.loginWithIdToken(params)This function logs in to the Wepin Firebase using an external ID token. It returns Firebase login information upon successful login. This method is a suspend method, so you can call it within another suspend method or in a coroutine.
-
params<LoginOauthIdTokenRequest>-
token<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())
-
- <LoginResult>
-
provider<Providers.EXTERNAL_TOKEN> -
token<FBToken>-
idToken<String> - wepin firebase idToken -
refreshToken<String> - wepin firebase refreshToken
-
-
- kotlin
coroutineScope.launch { try { val sign = wepinLogin.getSignForLogin( privateKey, token, ) val loginOption = LoginOauthIdTokenRequest(idToken = token, sign = sign) val loginResponse = wepinLogin.loginWithIdToken(loginOption) setResponse(loginResponse) setText("$loginResponse") } catch (e: Exception) { setResponse(null) setText("fail - ${e.message}") } }
wepinLogin.loginWithAccessToken(params)This function logs in to the Wepin Firebase using an external access token. It returns Firebase login information upon successful login. This method is a suspend method, so you can call it within another suspend method or in a coroutine.
-
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 token provided as the first parameter. (Returned value of getSignForLogin())
-
- <LoginResult>
-
provider<Providers.EXTERNAL_TOKEN> -
token<FBToken>-
idToken<String> - wepin firebase idToken -
refreshToken<String> - wepin firebase refreshToken
-
-
- kotlin
coroutineScope.launch { try { val sign = wepinLogin.getSignForLogin( privateKey, token ) val loginOption = LoginOauthAccessTokenRequest(provider, token, sign) val loginResponse = wepinLogin.loginWithAccessToken(loginOption) setResponse(loginResponse) setText("$loginResponse") } catch (e: Exception) { setResponse(null) setText("fail - ${e.message}") } }
wepinLogin.getRefreshFirebaseToken()This method retrieves the current firebase token's information from the Wepin. This method is a suspend method, so you can call it within another suspend method or in a coroutine.
- void
- <LoginResult>
-
provider<Providers> -
token<FBToken>-
idToken<String> - wepin firebase idToken -
refreshToken<String> - wepin firebase refreshToken
-
-
- kotlin
coroutineScope.launch { try { val response = wepinLogin.getRefreshFirebaseToken() setText("$response") setResponse(response) } catch (e: Exception) { setText("fail - $e") } }
wepinLogin.loginWepin(param)This method logs the user into the Wepin application using the specified provider and token. This method is a suspend method, so you can call it within another suspend method or in a coroutine.
The parameters should utilize the return values from the loginWithEmailAndPassword(), loginWithIdToken(), and loginWithAccessToken() methods within this module.
- <LoginResult>
-
provider<Providers> -
token<FBToken>-
idToken<String> - Wepin Firebase idToken -
refreshToken<String> - Wepin Firebase refreshToken
-
-
- <WepinUser> - A promise that resolves to an object containing the user's login status and information. The object includes:
- 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> - The user's status of wepin login. including:
- loginStats: <'complete' | 'pinRequired' | 'registerRequired'> - If the user's loginStatus value is not complete, it must be registered in the wepin.
- pinRequired?: <Boolean>
- token: <Token> - The user's token of wepin.
- accessToken: <String>
- refreshToken <String>
- kotlin
coroutineScope.launch { try { val response = wepinLogin.loginWepin(loginResult!!) setText("$response") } catch (e: Exception) { setText("fail - ${e.message}") } }
wepinLogin.getCurrentWepinUser()This method retrieves the current logged-in user's information from the Wepin. This method is a suspend method, so you can call it within another suspend method or in a coroutine.
- void
- <WepinUser> - A promise that resolves to an object containing the user's login status and information. The object includes:
- 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> - The user's status of wepin login. including:
- loginStats: <'complete' | 'pinRequired' | 'registerRequired'> - If the user's loginStatus value is not complete, it must be registered in the wepin.
- pinRequired?: <Boolean>
- token: <Token> - The user's token of wepin.
- accessToken: <String>
- refreshToken <String>
- kotlin
coroutineScope.launch { try { val response = wepinLogin.getCurrentWepinUser() setText("$response") } catch (e: Exception) { setText("fail - $e") } }
wepinLogin.logoutWepin()The logoutWepin() method logs out the user logged into Wepin.
This method is a suspend method, so you can call it within another suspend method or in a coroutine.
- void
- <Boolean>
coroutineScope.launch {
try {
val response = wepinLogin.logoutWepin()
setText("$response")
} catch (e: Exception) {
setText("fail - ${e.message}")
}
}Generates signatures to verify the issuer. It is mainly used to generate signatures for login-related information such as ID tokens and access tokens.
wepinLogin.getSignForLogin(privKey, 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.
- kotlin
val response = wepinLogin.getSignForLogin(privateKey, token)
wepinLogin.finalize()
The finalize() method finalizes the Wepin Login Library.
- void
- void
wepinLogin.finalize()| Error Code | Error Message | Error 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. |