This document describes how to integrate Kakao Login APIs into your service with the Kakao SDK for iOS.
To learn about each API in detail, refer to Concepts.
For a Kakao Login button, you can download the resources provided by Kakao or customize buttons according to your service user interface by referring to the Design Guide.
According to the Apple's new policy, you must offer account deletion within your app along with account creation. Likewise, if you integrate Kakao Login into your service, you must also provide a function to unlink from your app because users are linked to your app when they log in with Kakao. This applies to the app submission starting January 31, 2022. For more information, refer to App Store Review Guidelines.
Before using Kakao Login APIs with the iOS SDK,
To implement Kakao Login, you need to install both the Kakao Login and Authentication modules. After adding KakaoSDKAuth
(Authentication and token management module) and KakaoSDKUser
(Kakao Login module) to the Podfile, add the import statement for the modules as follows.
import KakaoSDKCommon
import KakaoSDKAuth
import KakaoSDKUser
import KakaoSDKCommon
import RxKakaoSDKCommon
import KakaoSDKAuth
import RxKakaoSDKAuth
import KakaoSDKUser
import RxKakaoSDKUser
- Less than iOS 2.4.0: You should call 'AuthApi' in the KakaoSDKAuth module and 'UserApi' in the KakaoSDKUser module to use the Kakao Login APIs. - Since iOS 2.4.0 or higher: You can call 'UserAPi' in the KakaoSDKUser module only to use the Kakao Login APIs. However, to call the Checking token presence API related to user authentication, call 'AuthApi'. The code snippets have been updated along with this change.
*This configuration is required for Login with Kakao Talk.
The Login with Kakao Talk allows users to move to Kakao Talk from a service app and go back to the app when the user selects [Accept and Continue] or [Cancel] on Kakao Talk. To implement this process, you must configure these things:
handleOpenUrl()
method that asks to open the URL in the AppDelegate.swift file to complete the login process after coming back to the service app.import KakaoSDKAuth
...
class AppDelegate: UIResponder, UIApplicationDelegate {
...
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
if (AuthApi.isKakaoTalkLoginUrl(url)) {
return AuthController.handleOpenUrl(url: url)
}
return false
}
...
}
import RxKakaoSDKAuth
import KakaoSDKAuth
...
class AppDelegate: UIResponder, UIApplicationDelegate {
...
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
if (AuthApi.isKakaoTalkLoginUrl(url)) {
return AuthController.rx.handleOpenUrl(url: url)
}
return false
}
...
}
If you make a project for an app in iOS 13 or higher, UIApplicationSceneManifest
is added in the Info.plist file and UISceneDelegate.swift is set to use as a default. If you use UISceneDelegate.swift, add the handleOpenUrl()
method in the SceneDelegate.swift file, instead of the AppDelegate.swift file.
If you use the SwiftUI App Life Cycle, add handleOpenUrl()
inside the ${PROJECT_NAME}App class using onOpenURL()
in the same way with initializing SDK.
import KakaoSDKAuth
...
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
...
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
if let url = URLContexts.first?.url {
if (AuthApi.isKakaoTalkLoginUrl(url)) {
_ = AuthController.handleOpenUrl(url: url)
}
}
}
...
}
import RxKakaoSDKAuth
import KakaoSDKAuth
...
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
...
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
if let url = URLContexts.first?.url {
if (AuthApi.isKakaoTalkLoginUrl(url)) {
_ = AuthController.rx.handleOpenUrl(url: url)
}
}
}
...
}
import SwiftUI
import KakaoSDKCommon
import KakaoSDKAuth
...
@main
struct SwiftUI_testApp: App {
...
init() {
// Initialize Kakao SDK.
KakaoSDK.initSDK(appKey: "NATIVE_APP_KEY")
}
var body: some Scene {
WindowGroup {
// Handle Custom URL Scheme using onOpenURL().
ContentView().onOpenURL(perform: { url in
if (AuthApi.isKakaoTalkLoginUrl(url)) {
AuthController.handleOpenUrl(url: url)
}
})
}
}
...
}
The Login API enables users to log in through Kakao Talk or their Kakao Account information.
The module that provides Kakao Login API has changed: - In iOS SDK 2.3.2 or less, the KakaoSDKAuth (or RxKakaoSDKAuth) module provides Kakao Login API. - In iOS SDK 2.4.0 or higher, the KakaoSDKUser (or RxKakaoSDKUser) module provides Kakao Login API.
Permission | Prerequisite | Kakao Login | User consent |
---|---|---|---|
- | Register platforms Activate Kakao Login Manage consent items Advanced: Activate OpenID Connect(Optional) Set Simple Signup(for Kakao Sync) |
Required | Required: Required consent item |
For Login with Kakao Talk, you must configure some settings in advance.
After configuration, call the isKakaoTalkLoginAvailable()
method that invokes the loginWithKakaoTalk()
method to check if Kakao Talk has been installed on a user's device. loginWithKakaoTalk()
runs Kakao Talk and prompts the Consent screen that asks consent.
To handle exceptions, refer to the AuthFailureReason
section in API Reference.
Name | Type | Description | Required |
---|---|---|---|
launchMethod | LaunchMethod |
Parameter to set Kakao Talk launch method..CustomScheme : Custom Scheme.UniversalLink : Universal Link |
X |
nonce | String |
Parameter to strengthen security. To prevent replay attacks, generate random strings and pass them as an argument. IMPORTANT: Allowed to set only when you integrate Kakao Login with OpenID Connect. |
X |
// Check if Kakao Talk has been installed.
if (UserApi.isKakaoTalkLoginAvailable()) {
UserApi.shared.loginWithKakaoTalk {(oauthToken, error) in
if let error = error {
print(error)
}
else {
print("loginWithKakaoTalk() success.")
// Do something
_ = oauthToken
}
}
}
// Class member property
let disposeBag = DisposeBag()
// Check if Kakao Talk has been installed.
if (UserApi.isKakaoTalkLoginAvailable()) {
UserApi.shared.rx.loginWithKakaoTalk()
.subscribe(onNext:{ (oauthToken) in
print("loginWithKakaoTalk() success.")
// Do something
_ = oauthToken
}, onError: {error in
print(error)
})
.disposed(by: disposeBag)
}
When a user consents, Kakao identifies the user with the user's Kakao Account information linked to Kakao Talk, and then issues tokens. The iOS SDK provides the issued tokens through the OAuthToken object.
The issued tokens are stored through the TokenManagerProvider
class. The stored tokens are automatically added to the authorization header when calling the token-based APIs.
Name | Type | Description | Required |
---|---|---|---|
accessToken | String |
One of the tokens that authorizes you to call Kakao APIs and identifies users. | O |
expiredAt | Date |
Validity period in seconds until the access token expires. | O |
refreshToken | String |
One of the tokens that is used to gain new tokens. | O |
refreshTokenExpiredAt | Date |
Validity period in seconds until the refresh token expires. | O |
scopes | [String] |
List of scopes of user information to be retrieved with the issued access token. | X |
idToken | String |
JSON Web Token that contain user's authentication information, encoded using Base64 algorithm. For more details, refer to ID Token. IMPORTANT: Only returned when you integrate Kakao Login with OpenID Connect. If you call the Requesting additional consent API, only returned when openid is added to scope in the request. |
X |
Permission | Prerequisite | Kakao Login | User consent |
---|---|---|---|
- | Register platforms Activate Kakao Login Manage consent items Advanced: Activate OpenID Connect(Optional) Set Simple Signup(for Kakao Sync) |
Required | Required: Required consent item |
For Login with Kakao Account, call the loginWithKakaoAccount()
method that runs a web browser and prompts the Consent screen that asks consent.
Name | Type | Description | Required |
---|---|---|---|
prompts | [Prompt] |
Used to request reauthentication by selecting whether to present an interactive UI. - .Login : Used when requesting reauthentication even though a user has already been authenticated by presenting the Kakao Account Login screen to a user. Not available in Kakao Talk in-app browser.- .Create : Used to prompt the Kakao Account sign-up page first. The Kakao Login consent screen will be present after signing up for Kakao Account. |
X |
nonce | String |
Parameter to strengthen security. To prevent replay attacks, generate random strings and pass them as an argument. IMPORTANT: Allowed to set only when you integrate Kakao Login with OpenID Connect. |
X |
UserApi.shared.loginWithKakaoAccount {(oauthToken, error) in
if let error = error {
print(error)
}
else {
print("loginWithKakaoAccount() success.")
// Do something
_ = oauthToken
}
}
// Class member property
let disposeBag = DisposeBag()
UserApi.shared.rx.loginWithKakaoAccount()
.subscribe(onNext:{ (oauthToken) in
print("loginWithKakaoAccount() success.")
// Do something
_ = oauthToken
}, onError: {error in
print(error)
})
.disposed(by: disposeBag)
When a user consents, Kakao identifies the user through the user's Kakao Account cookie stored on the default web browser and then issues tokens through the OAuthToken class.
You can request reauthentication regardless of a user's login status to enhance security. Set prompts
to .LOGIN
, and pass it when calling loginWithKakaoAccount()
. Then, the login screen is prompted even though a user has already been logged in on the same web browser on the device.
UserApi.shared.loginWithKakaoAccount(prompts:[.Login]) {(oauthToken, error) in
if let error = error {
print(error)
}
else {
print("loginWithKakaoAccount() success.")
// Do something
_ = oauthToken
}
}
// Class member property
let disposeBag = DisposeBag()
UserApi.shared.rx.loginWithKakaoAccount(prompts: [.Login])
.subscribe(onNext:{ (oauthToken) in
print("loginWithKakaoAccount() success.")
// Do something
_ = oauthToken
}, onError: {error in
print(error)
})
.disposed(by: disposeBag)
You can request to prompt the Kakao Account sign-up page before Kakao Login. Set prompts
to .Create
, and pass it when calling loginWithKakaoAccount()
. The Kakao Login consent screen will be present after signing up for Kakao Account.
UserApi.shared.loginWithKakaoAccount(prompts:[.Create]) {(oauthToken, error) in
if let error = error {
print(error)
}
else {
print("loginWithKakaoAccount() success.")
// Do something
_ = oauthToken
}
}
// Class member property
let disposeBag = DisposeBag()
UserApi.shared.rx.loginWithKakaoAccount(prompts: [.Create])
.subscribe(onNext:{ (oauthToken) in
print("loginWithKakaoAccount() success.")
// Do something
_ = oauthToken
}, onError: {error in
print(error)
})
.disposed(by: disposeBag)
Permission | Prerequisite | Kakao Login | User consent |
---|---|---|---|
- | Register platforms Activate Kakao Login |
Required | - |
To check if a user has obtained an access token through Kakao Login, call the hasToken()
method in AuthApi
. This API returns the presence of an access token or refresh token as a boolean type. However, note that the return value true
does not guarantee that the user is in a logged-in state.
if (AuthApi.hasToken()) {
UserApi.shared.accessTokenInfo { (_, error) in
if let error = error {
if let sdkError = error as? SdkError, sdkError.isInvalidTokenError() == true {
//Login is required.
}
else {
//Handle other errors.
}
}
else {
//Succeeded in validating token (Token is refreshed if needed).
}
}
}
else {
//Login is required.
}
// Class member property
let disposeBag = DisposeBag()
if (AuthApi.hasToken()) {
UserApi.shared.rx.accessTokenInfo()
.subscribe(onSuccess:{ (_) in
//Succeeded in validating token (Token is refreshed if needed).
}, onFailure: {error in
if let sdkError = error as? SdkError, sdkError.isInvalidTokenError() == true {
//Login is required.
}
else {
//Handle other errors.
}
})
.disposed(by: disposeBag)
}
else {
//Login is required.
}
If the value false
is returned, it means that a token does not exist. In this case, implement a process for a user to log in to issue a token. On the other hand, if the return value is true
, you can validate the access token that the user has through the accessTokenInfo()
method in UserApi
, and then proceed as follows depending on the request result:
Permission | Prerequisite | Kakao Login | User consent |
---|---|---|---|
- | Register platforms Activate Kakao Login |
Required | - |
The Logout API deletes the access and refresh token issued through the login process to have a user log out. You need to call the logout()
method in UserApi class.
Regardless of the result of the logout request, the iOS SDK deletes the access and refresh tokens and has the login session end.
UserApi.shared.logout {(error) in
if let error = error {
print(error)
}
else {
print("logout() success.")
}
}
// Class member property
let disposeBag = DisposeBag()
UserApi.shared.rx.logout()
.subscribe(onCompleted:{
print("logout() success.")
}, onError: {error in
print(error)
})
.disposed(by: disposeBag)
Permission | Prerequisite | Kakao Login | User consent |
---|---|---|---|
- | Register platforms Activate Kakao Login |
Required | - |
The Unlink API unlinks a user's Kakao Account from a service app. Call the unlink() method defined in the UserApi
class.
If the request is successful, the iOS SDK deletes the access and refresh tokens. As the issued tokens are deleted, the session between an app and a user is disconnected, and the user is logged out and unlinked from your app.
UserApi.shared.unlink {(error) in
if let error = error {
print(error)
}
else {
print("unlink() success.")
}
}
// Class member property
let disposeBag = DisposeBag()
UserApi.shared.rx.unlink()
.subscribe(onCompleted:{
print("unlink() success.")
}, onError: {error in
print(error)
})
.disposed(by: disposeBag)
Permission | Prerequisite | Kakao Login | User consent |
---|---|---|---|
- | Register platforms Activate Kakao Login |
Required | - |
You can simply check the validity of the access token and refresh token, instead of requesting user information. Call the accessTokenInfo() method in the UserApi
.
// Retrieve the expiration time of the access token.
UserApi.shared.accessTokenInfo {(accessTokenInfo, error) in
if let error = error {
print(error)
}
else {
print("accessTokenInfo() success.")
// Do something
_ = accessTokenInfo
}
}
// Class member property
let disposeBag = DisposeBag()
// Retrieve the expiration time of the access token.
UserApi.shared.rx.accessTokenInfo()
.subscribe(onSuccess:{ (accessTokenInfo) in
print("accessTokenInfo() success.")
// Do something
_ = accessTokenInfo
}, onFailure: {error in
print(error)
})
.disposed(by: disposeBag)
Name | Type | Description | Required |
---|---|---|---|
id | Int64 |
Service user ID. | X |
appId | Int64 |
App ID that the access token has been issued for. | O |
expiresIn | Int64 |
Validity period in seconds until the access token expires. NOTE: expiresInMillis has been deprecated and replaced with expiresIn . |
O |
Permission | Prerequisite | Kakao Login | User consent |
---|---|---|---|
- | Register platforms Activate Kakao Login Manage consent items |
Required | Required: All consent items to request user information |
To retrieve user data, you must set consent items and obtain user's consent for the data that your service needs. If a user does not consent, you cannot get the user data. To check which scopes a user has already agreed, you can call the Retrieving consent details API and check the agreed scopes first.
To retrieve the information of the user who is currently logged in, call me()
method defined in the UserApi class through the shared
object.
UserApi.shared.me() {(user, error) in
if let error = error {
print(error)
}
else {
print("me() success.")
// Do something
_ = user
}
}
// Class member property
let disposeBag = DisposeBag()
UserApi.shared.rx.me()
.subscribe (onSuccess:{ user in
print("me() success.")
// Do something
_ = user
}, onFailure: {error in
print(error)
})
.disposed(by: disposeBag)
The user information in response to this request is passed to the User
class defined in KakaoSDKUser
. For example, you can access user.id
to retrieve Service user ID, user.kakaoAccount.profile
for Kakao Account's profile information, user.kakaoAccount.email
for email.
Name | Type | Description | Required |
---|---|---|---|
id | Int64 |
Service user ID. | O |
hasSignedUp | Bool |
Only returned when the Auto-link setting is disabled. Whether the user is completely linked with (signed up) your app. false : Preregisteredtrue : Registered |
X |
connectedAt | Date |
The time when the user is linked with a service in UTC*. | X |
synchedAt | Date |
The time when the user is logged in through Kakao Sync Simple Signup in UTC*. This value is only passed for Kakao Sync service users. In this case, its value is the same as connected_at . |
X |
properties | [String : String] |
Additional user information saved on the Kakao platform to use it later. Refer to Prerequisites > Manage user properties. |
X |
kakaoAccount | Account |
Kakao Account information. To see what user data you can get, refer to User information included in Kakao Account. |
X |
Ensure that you need to handle exceptions for the following cases in which you cannot get the user information:
Permission | Prerequisite | Kakao Login | User consent |
---|---|---|---|
Required: Consent item |
Register platforms Activate Kakao Login Manage consent items |
Required | Required: Shipping information |
This API enables you to retrieve shipping addresses saved in user's Kakao Account.
To retrieve shipping address,
The shipping_address
scope is inactivated by default. To set the scope to 'Optional consent', connect your app to a Biz Channel. If your service must get users' shipping addresses, set the scope to 'Required consent' by going through the Review for Provision of Personal Information provided by Kakao Sync and use the Provision after collecting information option.
To retrieve a user's shipping addresses, call the shippingAddresses()
method defined in the UserApi
class. You can also use the following parameters.
Name | Type | Description | Required |
---|---|---|---|
fromUpdatedAt | Date |
If multiple shipping addresses are returned through multiple pages, only the shipping addresses that are changed after updated_at time return. The last shipping address on the previous page is used for an input value for the next page. If set to 0 , shipping addresses are retrieved from the beginning. |
X |
pageSize | Int |
Number of (two or more) shipping addresses displayed on a page. (Default: 10 ) |
X |
UserApi.shared.shippingAddresses {(shippingAddress, error) in
if let error = error {
print(error)
}
else {
print("shippingAddresses() success.")
// Do something
_ = shippingAddress
}
}
// Class member property
let disposeBag = DisposeBag()
UserApi.shared.rx.shippingAddresses()
.subscribe(onSuccess:{ (shippingAddress) in
print("shippingAddresses() success.")
// Do something
_ = shippingAddress
}, onFailure: {error in
print(error)
})
.disposed(by: disposeBag)
shippingAddresses()
returns the UserShippingAddresses
object.
Name | Type | Description | Required |
---|---|---|---|
userId | Int64 |
Service user ID of a user who requested shipping addresses. | X |
shippingAddresses | [ShippingAddress] |
List of shipping addresses that the user added. The default shipping address is displayed on the uppermost, and the rest addresses are sorted by last updated date in decending order. If a user does not agree to provide shipping addresses, nil is returned. In this case, after checking if needsAgreement is true , request additional consent. |
O |
needsAgreement | Bool |
Whether consent to shipping addresses is required. | X |
Name | Type | Description | Required |
---|---|---|---|
id | Int64 |
Shipping address ID. | O |
name | String |
Shipping address name. | X |
isDefault | Bool |
Whether the shipping address is a default address or not. | O |
updatedAt | Date |
The time when a user updated the shipping address. | X |
type | Type |
Shipping address type. - OLD : Administrative address- NEW : Road name address. |
X |
baseAddress | String |
Base address that is automatically input when searching for a zipcode. | X |
detailAddress | String |
Detailed address that a user adds to the base address. | X |
receiverName | String |
Recipient name. | X |
receiverPhoneNumber1 | String |
Recipient phone number. | X |
receiverPhoneNumber2 | String |
Additional recipient phone number. | X |
zoneNumber | String |
New type of 5-digit postal code for a road name address system. Required for the road name address system. |
X |
zipCode | String |
Old type of 6-digit postal code for an administrative address system. Optional for the administrative address system because some old type of addresses may not have a zip code. |
X |
Permission | Prerequisite | Kakao Login | User consent |
---|---|---|---|
- | Register platforms Activate Kakao Login Manage user properties |
Required | - |
You can store or update additional user information into the user property keys that you designated in [My Application] > [User Properties].
Call the updateProfile()
method defined in the UserApi class. You must pass the custom property keys and values that you want to upadate through properties
in a key-value pair. For example, if you want to update a user's clothing size, set properties
to ["clothing_size":"small"]
.
Name | Type | Description | Required |
---|---|---|---|
properties | [String:Any] |
Pass the scope and value to be updated in a key-value pair as an array. Check the property keys of user information that you want to update in [My Application] > [User Properties] by referring to Manage user properties. You can also add new property keys up to five. |
O |
UserApi.shared.updateProfile(properties: ["${CUSTOM_PROPERTY_KEY}":"${CUSTOM_PROPERTY_VALUE}"]) {(error) in
if let error = error {
print(error)
}
else {
print("updateProfile() success.")
}
}
// Class member property
let disposeBag = DisposeBag()
UserApi.shared.rx.updateProfile(properties:["${CUSTOM_PROPERTY_KEY}":"${CUSTOM_PROPERTY_VALUE}"])
.subscribe(onCompleted:{
print("updateProfile() success.")
}, onError: {error in
print(error)
})
.disposed(by: disposeBag)
Permission | Prerequisite | Kakao Login | User consent |
---|---|---|---|
- | Register platforms Activate Kakao Login Manage consent items Advanced: Activate OpenID Connect(Optional) Set Simple Signup(for Kakao Sync) |
Required | Required: Required consent item |
You can request consent to access permission or specific personal information if the user has not agreed when the user logged in with Kakao. Before using this API, read Concepts > Request additional consent thoroughly for a better understanding.
Call the loginWithKakaoAccount()
method defined in the UserApi class. Pass the scopes of user information you want to request additional consent through scopes
as an array of strings.
Name | Type | Description | Required |
---|---|---|---|
scopes | [String] |
Pass the scope IDs of the User information. You can figure out each scope's ID in [My Application] > [Kakao Login] > [Consent Items]. IMPORTANT: If you implement OpenID Connect (OIDC), you must add openid to scopes along with the scope values you want to obtain consent. If not, OAuth is applied even though OIDC is enabled. |
O |
nonce | String |
Parameter to strengthen security. To prevent replay attacks, generate random strings and pass them as an argument. IMPORTANT: Allowed to set only when you integrate Kakao Login with OpenID Connect. |
X |
Here is an example of checking which scopes are required to get consent with the me()
method and requesting additional consent by passing scopes
when calling loginWithKakaoAccount()
.
UserApi.shared.me() { (user, error) in
if let error = error {
print(error)
}
else {
if let user = user {
//Add the desired scope among the list of all scopes.
var scopes = [String]()
if (user.kakaoAccount?.profileNeedsAgreement == true) { scopes.append("profile") }
if (user.kakaoAccount?.emailNeedsAgreement == true) { scopes.append("account_email") }
if (user.kakaoAccount?.birthdayNeedsAgreement == true) { scopes.append("birthday") }
if (user.kakaoAccount?.birthyearNeedsAgreement == true) { scopes.append("birthyear") }
if (user.kakaoAccount?.genderNeedsAgreement == true) { scopes.append("gender") }
if (user.kakaoAccount?.phoneNumberNeedsAgreement == true) { scopes.append("phone_number") }
if (user.kakaoAccount?.ageRangeNeedsAgreement == true) { scopes.append("age_range") }
if (user.kakaoAccount?.ciNeedsAgreement == true) { scopes.append("account_ci") }
if scopes.count > 0 {
// If OpenID Connect (OIDC) is enabled,
// - When "openid" is added to `scopes`, OIDC is applied.
// - When "openid" is not added to `scopes`, OAuth 2.0 is applied.
// To use OIDC, add "openid" to `scopes`.
// scopes.append("openid")
// The tokens are refreshed for the designated scopes.
UserApi.shared.loginWithKakaoAccount(scopes: scopes) { (_, error) in
if let error = error {
print(error)
}
else {
UserApi.shared.me() { (user, error) in
if let error = error {
print(error)
}
else {
print("me() success.")
// Do something
_ = user
}
}
}
}
}
else {
print("Not need to get additional consent.")
}
}
}
}
// Class member property
let disposeBag = DisposeBag()
UserApi.shared.rx.me()
.map({ (user) -> User in
//Add the desired scope among the list of all scopes.
var scopes = [String]()
if (user.kakaoAccount?.profileNeedsAgreement == true) { scopes.append("profile") }
if (user.kakaoAccount?.emailNeedsAgreement == true) { scopes.append("account_email") }
if (user.kakaoAccount?.birthdayNeedsAgreement == true) { scopes.append("birthday") }
if (user.kakaoAccount?.birthyearNeedsAgreement == true) { scopes.append("birthyear") }
if (user.kakaoAccount?.genderNeedsAgreement == true) { scopes.append("gender") }
if (user.kakaoAccount?.phoneNumberNeedsAgreement == true) { scopes.append("phone_number") }
if (user.kakaoAccount?.ageRangeNeedsAgreement == true) { scopes.append("age_range") }
if (user.kakaoAccount?.ciNeedsAgreement == true) { scopes.append("account_ci") }
if (scopes.count > 0) {
// If OpenID Connect (OIDC) is enabled,
// - When "openid" is added to `scopes`, OIDC is applied.
// - When "openid" is not added to `scopes`, OAuth 2.0 is applied.
// To use OIDC, add "openid" to `scopes`.
// scopes.append("openid")
throw SdkError(scopes:scopes)
}
else {
return user
}
})
.retry(when: Auth.shared.rx.incrementalAuthorizationRequired())
.subscribe(onSuccess:{ ( user ) in
print("me() success.")
// Do something
_ = user
}, onFailure: {error in
print(error)
})
.disposed(by: disposeBag)
loginWithKakaoAccount()
presents the Consent screen asking for consent to the requested scope. When a user chooses to provide the scope and selects [Accept and Continue] on the Consent screen, new tokens are issued, and the scope information is updated in the OAuthToken class.
Permission | Prerequisite | Kakao Login | User consent |
---|---|---|---|
- | Register platforms Activate Kakao Login Manage consent items |
Required | - |
This API enables you to retrieve the detailed information of the scopes (consent items) that a user has agreed to. You can check all scopes set in [My Application] > [Kakao Login] > [Consent Items] and the details of the scopes. If a user has consented to the scope before, the scope is included in the response even though your app is currently not using the scope.
Call the scopes()
method in the UserApi
class.
Name | Type | Description | Required |
---|---|---|---|
scopes | [String] |
Used when you retrieve specific scopes only. List of scope IDs you want to retrieve by referring to the IDs set in [My Application] > [Kakao Login] > [Consent Items]. |
X |
UserApi.shared.scopes() { (scopeInfo, error) in
if let error = error {
self?.errorHandler(error: error)
}
else {
self?.success(scopeInfo)
// Do something
_ = scopeInfo
}
}
// Class member property
let disposeBag = DisposeBag()
UserApi.shared.rx.scopes()
.subscribe(onSuccess:{ (scopeInfo) in
self.success(scopeInfo)
// Do something
_ = scopeInfo
}, onFailure: {error in
self.errorHandler(error: error)
})
.disposed(by: self.disposeBag)
You can also retrieve the information of specific scopes by passing scope IDs. In this case, the response includes only the detailed information of the specified scopes if the request is successful.
UserApi.shared.scopes(scopes: ["account_email","gender"]) { (scopeInfo, error) in
if let error = error {
self?.errorHandler(error: error)
}
else {
self?.success(scopeInfo)
// Do something
_ = scopeInfo
}
}
// Class member property
let disposeBag = DisposeBag()
UserApi.shared.rx.scopes(scopes: ["account_email","gender"])
.subscribe(onSuccess:{ (scopeInfo) in
self.success(scopeInfo)
// Do something
_ = scopeInfo
}, onFailure: {error in
self.errorHandler(error: error)
})
.disposed(by: self.disposeBag)
If the request is successful, scopes()
returns the ScopeInfo object that includes the details of each scope and whether a user has agreed to the scope.
Name | Type | Description | Required |
---|---|---|---|
id | Long |
Service user ID. | O |
scopes | [Scope] |
List of scope information. | X |
Name | Type | Description | Required |
---|---|---|---|
id | String |
Scope ID. | O |
displayName | String |
Name or description of the scope (consent item) displayed on the Consent screen. | O |
type | ScopeType |
Enum class for Scope type. - PRIVACY : scopes for Personal Information - SERVICE : scopes for Permission |
O |
using | Boolean |
Whether your app is using the scope.true : Using the scope. false : Not using the scope even though the user has agreed to. |
O |
agreed | Boolean |
Whether the user has agreed to the scope.true : The user has agreed. false : The user has not agreed. |
O |
revocable | Boolean |
Whether you can revoke this scope. Only returned if the user has agreed to the scope.( "agreed"=true )true : Possible to revoke the scope. false : Impossible to revoke the scope. |
X |
Permission | Prerequisite | Kakao Login | User consent |
---|---|---|---|
- | Register platforms Activate Kakao Login Manage consent items |
Required | - |
This API revokes the scope that a user has agreed to. Call the revokeScopes()
method in the UserApi
class.
Name | Type | Description | Required |
---|---|---|---|
scopes | [String] |
List of scope IDs you want to revoke. You can revoke only the scope with "revocable":true among the scopes retrieved through the Retrieving consent details API. If you request to revoke the scope that is not revocable, an error is returned. |
O |
UserApi.shared.revokeScopes(scopes: ["account_email","gender"]) { (scopeInfo, error) in
if let error = error {
self?.errorHandler(error: error)
}
else {
self?.success(scopeInfo)
// Do something
_ = scopeInfo
}
}
// Class member property
let disposeBag = DisposeBag()
UserApi.shared.rx.revokeScopes(scopes: ["account_email","gender"])
.subscribe(onSuccess:{ (scopeInfo) in
self.success(scopeInfo)
// Do something
_ = scopeInfo
}, onFailure: {error in
self.errorHandler(error: error)
})
.disposed(by: self.disposeBag)
If the request is successful, scopes()
returns the ScopeInfo object that includes the details of each scope and whether a user has agreed to the scope.
Permission | Prerequisite | Kakao Login | User consent |
---|---|---|---|
Required: Kakao Sync |
Register platforms Activate Kakao Login Manage consent items Set Simple Signup |
Required | - |
This API is only allowed for the service that adopted Kakao Sync. To see the advantages of Kakao Sync, refer to Concept > Kakao Sync. Before implementing this API, read Design terms and policies.
To check which terms a user has consented to when the user logs in, call the serviceTerms()
method defined in the UserApi
class.
Name | Type | Description | Required |
---|---|---|---|
extra | String |
Used to retrieve all of the terms registered in your app. In this case, set it to app_service_terms . |
X |
UserApi.shared.serviceTerms {(serviceTerms, error) in
if let error = error {
print(error)
}
else {
print("serviceTerms() success.")
// Do something
_ = serviceTerms
}
}
// Class member property
let disposeBag = DisposeBag()
UserApi.shared.rx.serviceTerms()
.subscribe(onSuccess:{ (serviceTerms) in
print("serviceTerms() success.")
// Do something
_ = serviceTerms
}, onFailure: {error in
print(error)
})
.disposed(by: disposeBag)
serviceTerms()
returns the UserServiceTerms
object.
Name | Type | Description | Required |
---|---|---|---|
userId | Int64 |
Service user ID. | X |
appServiceTerms | [AppServiceTerms] |
A list of terms registered for an app. | X |
allowedServiceTerms | [ServiceTerms] |
A list of terms that a user has consented to. | X |
Name | Type | Description | Required |
---|---|---|---|
tag | String |
Tag that is specified in [My Application] > [Simple Signup] for each term. | O |
createdAt | Date |
The time when the term was registered. (RFC3339 internet date/time format) |
O |
updatedAt | Date |
The time when the term was modified. (RFC3339 internet date/time format) |
O |
Name | Type | Description | Required |
---|---|---|---|
tag | String |
Tag of the term that a user consented to. | O |
agreedAt | Date |
The last time when a user consented to the term. (RFC3339 internet date/time format) |
O |
If the request succeeds, the response returns through the UserServiceTerms
object that contains a service user ID and allowedServiceTerms
, the terms the user has consented to. allowedServiceTerms
is the list of the ServiceTerms
object that provides the consented time and the term's tag.
For more details of ServiceTerms
, refer to API Reference and the response of Web.
Permission | Prerequisite | Kakao Login | User consent |
---|---|---|---|
Required: Kakao Sync |
Register platforms Activate Kakao Login Manage consent items Advanced: Activate OpenID Connect(Optional) Set Simple Signup |
Required | Required: Required consent item |
This API is only allowed for the service that adopted Kakao Sync. To see the advantages of Kakao Sync, refer to Concept > Kakao Sync. Before implementing this API, read Design terms and policies.
This API enables you to request consent to a specific term that a user has not consented, regardless of whether the user has already signed up or not.
If your app is used for multiple services and each service requires consent to different terms, or if a new required term is added to your service, you can use this API. For more details, Design terms and policies.
To request consent to specific scopes from a user, pass the list of term tags through serviceTerms
as an argument when you call loginWithKakaoTalk()
or loginWithKakaoAccount()
.
If you do not add serviceTerms
when requesting an authorization code, the general Kakao Login API proceeds. In this case, you cannot request consent to the desired terms. Also, if a user has already consented to all required terms, the user is logged in without the Consent screen prompted. For more details, refer to FAQ.
Name | Type | Description | Required |
---|---|---|---|
serviceTerms | [String] |
Tags for the terms that are required to consent. | O |
// Add service_terms in a string format that includes all terms separated by ‘,’
// ex) "tag1,tag2"
let serviceTerms = ["tag1", "tag2"]
UserApi.shared.loginWithKakaoAccount(serviceTerms: serviceTerms, completion: {(oauthToken, error) in
if let error = error {
print(error)
}
else {
print("loginWithKakaoAccount(serviceTerms:) success.")
// Do something
_ = oauthToken
}
})
// Class member property
let disposeBag = DisposeBag()
// Add service_terms in a string format that includes all terms separated by ‘,’
// ex) "tag1,tag2"
let serviceTerms = ["tag1", "tag2"]
UserApi.shared.rx.loginWithKakaoAccount(serviceTerms: serviceTerms)
.subscribe(onNext: { (oauthToken) in
print("loginWithKakaoAccount(serviceTerms:) success.")
// Do something
_ = oauthToken
}, onError: {error in
print(error)
})
.disposed(by: disposeBag)
The response is returned through the OAuthToken object in the same as the Kakao Login.
Permission | Prerequisite | Kakao Login | User consent |
---|---|---|---|
Required: Manual signup |
Register platforms Activate Kakao Login |
Required | - |
The Manual signup API is only for the app with the Auto-link option disabled. Before using this API, check out when to use this API and the cautions in REST API.
The Manual signup API manually links a user with your app to complete signup when the Auto-link is disabled.
To figure out if the currently logged-in user needs to be linked with your app, check the value of hasSignedUp
in the response of the Retrieving user information API and handle each case:
true
: The user is already linked with your app. You do not need to call the Manual signup API.false
: The user is not linked with your app. You must call signup()
to link the user with your app manually.nil
: Your app is using the Auto-link feature. You do not need to call the Manual signup API.If the return value of hasSignedUp
is false
and the user is ready to sign up, call the signup()
method to complete the signup.
Name | Type | Description | Required |
---|---|---|---|
properties | [String:String] |
A list of user information. Used when you want to store user information needed for your service when linking a user. Refer to Manage user properties. |
X |
UserApi.shared.signup { (userId, error) in
if let error = error {
print(error)
}
else {
print("signup() success.")
}
}
// Class member property
let disposeBag = DisposeBag()
UserApi.shared.rx.signup()
.subscribe (onSuccess:{ (userId) in
print("signup() success.")
}, onFailure: {error in
print(error)
})
.disposed(by: disposeBag)
If the request is successful, the user's service ID is returned.
To check the request result, request the Retrieving user information API again and check the value of hasSignedUp
because the user's linked status is not provided even when the request is successful.