User management

User management is core functionality provided by kakao platform service. User management connects user's account with kakao platform easily. You can now make secure and user interactive app easily.

Details on functionality of user management follows.

  • Login: Support easy and fast login through kakao account.
  • Logout: Disconnect user login session.
  • Disconnecting App: Disconnect connection of user and app to kakao platform permanently. This is similar to request for unregistering user.
  • User information retrieval: Possible to retrieve user information. In order to use such functionality, login and app must be connected.
  • Saving user information: Possible to save specific user information.In order to use such functionality, login and app must be connected.

Getting started

  1. Check if settings for using login API has been set properly in App. Refer loginbase template.
  2. During app sign procedures, check if key being used is registered through settings > general > platform > Android > key hash.

    For creating key hash, refer to Creating App's procedure 2.

Login

You can login with kakao account.

Generally speaking, user will use kakao account login button to login to kakao account based logins.

  1. Simple login is supported in a device with kakao talk version 4.2.0 or above. Procedures on login through kakaotalk follows.

    • If kakao account is linked: Uses kakaoTalk account.
    • If kakao account is not linked: Gives back native login window to link with account.
  2. Device with kakao story version of 2.6.0 or above, login through kakao story's kakao account is possible.

  3. If kakaotalk or kakaostory is not installed with version supported in a device, only webview login will supported.

From 3 options above, you can pick which ever suits your app's characteristic. On how to choose such options can be found through sample code below.

Such login functionality support OAuth 2.0. Following is the most common way Kakao platform service provides to authenticate through OAuth.

  1. User clicks on login button using kakao account.
  2. Use kakao account credentials in kakaotalk for identifying users.
  3. If ownership info is correct,resource must be granted from agreement of resource owner.
  4. If up to procedure 3 finish successfully, Authorization Code will be issued. Such code will be sent to third app through Redirection URI.
  5. Using authentication code received from third party app, Access Token, Refresh Token will be requested and received.

    User token in kakao platform service is provided as important key for login based services. For details on OAuth 2.0 please refer here.

Many of the complicated procedures are dealt by Kakao SDK for you, and following explains how to use them correctly.

1. Initialize session by calling Session#initialize(Context) on Application#onCreate. pass in current context, which attempts login and optional selected authentication type. Unless authentication type is not given as parameter, all possible authentication type on user's device will be used. (reference to followed [Result example] for details) If given authentication type is more than two, pop up asking user to choose the type when user clicks LoginButton. Otherwise, popup will not be shown.

public class GlobalApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();

        // Initialize session.
        Session.initialize(this);
        //  If you want to login only through kakaotalk
        // Session.initializeSession(this, AuthType.KAKAO_TALK)
        ...
    }
    ...
}

2. LoginButton is a FrameLayout with login button included. Add this to login window layout file.

<com.kakao.widget.LoginButton
    android:id="@+id/com_kakao_login"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:layout_marginBottom="30dp"
    android:layout_marginLeft="20dp"
    android:layout_marginRight="20dp"/>

3. This is an example code for login Activity, in which, com.kakao.template.loginbase.SampleLoginActivity is included in loginbase-template.

login Activity of Login based samples, such as usermgmt-sample, kakaostory-sample, kakaotalk-sample, is constructed through inheritance such as below.

public class SampleLoginActivity extends Activity {
    private LoginButton loginButton;
    private final SessionCallback mySessionCallback = new MySessionStatusCallback();

    @Override
    protected void onCreate(final Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login);
        // Retrieve login button.
        loginButton = (LoginButton) findViewById(R.id.com_kakao_login);

        // add session callback.
        session = Session.getCurrentSession();
        session.addCallback(mySessionCallback);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        session.removeCallback(mySessionCallback);
    }

    @Override
    protected void onResume() {
        super.onResume();
        // If session is closed, show LoginButton.
        if (session.isClosed()){
            loginButton.setVisibility(View.VISIBLE);
        }
        // If session is opened or openable, hide LoginButton
        else {
            loginButton.setVisibility(View.GONE);

            // If it's a state where access token is able to be refreshed, do it.
            if (session.isOpenable()) {
                session.implicitOpen();
            }
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (Session.getCurrentSession().handleActivityResult(requestCode, resultCode, data)) {
            return;
        }

        super.onActivityResult(requestCode, resultCode, data);
    }

    private class MySessionStatusCallback implements SessionCallback {
        @Override
        public void onSessionOpened() {
            // If progress bar is shown, stop the progress bar.

            // Redirect to a page in which should appear after session has been opened.
            final Intent intent = new Intent(SampleLoginActivity.this, SampleSignupActivity.class);
            startActivity(intent);
            finish();
        }

        @Override
        public void onSessionClosed(final KakaoException exception) {
            // If progress bar is shown, stop the progress bar.

            // Expose login button since opening session failed.
            loginButton.setVisibility(View.VISIBLE);
        }

        @Override
        public void onSessionOpening() {
            //start a progress bar.
        }
    }
}
  • onCreate(Bundle) : Retrieve login button when login Activity is created and add session callback which is called when session state is changed.
  • onDestroy() : Remove session callback since there is no use to receive session events.
  • onResume() : Change UI depending on session state. follow appropriate actions depending on whether session is openable, opened or closed. In our example, if it's closed, login button will be shown, if it's opened, login button will be hidden and if it's openable, access token will be refreshed implicitly.
  • onActivityResult(int, int, Intent) : Delegate the result through Session#handleActivityResult(int, int, Intent) for session to handle login activity result.
  • MySessionStatusCallback :Receive event for cases where session has been opened, closed or opening through session callback. In our example, if session is opened, redirect to signup page. If session is closed, button that has been hidden will be displayed again.

Client secret

Kakao Login provides OAuth client secret functionality for stronger security level.

Client secret can be issued and activated via My application > General > Client Secret menu in developer website. In application side, client secret should be defined in AndroidManifest.xml of your application.

<uses-permission android:name="android.permission.INTERNET" />

<application>
    ...
    <meta-data
        android:name="com.kakao.sdk.ClientSecret"
        android:value="<kakao client secret value>"/>
    ...
</application>

[Result example]

Following is an example to help you understand login procedures.

login_button.png

If kakao talk app with version 4.2.0 or kakao story version of 2.6.0 is installed, window will pop up asking user to choose whether to login through easy login of kakao talk, kakao story or to manually enter login information.

If app with lower version is installed, or app has not been installed previously, window will not pop up as described above but will be directed to a same page as intro 3, which is the case where login with different account has been selected.

choose_account_dialog.png

1. If simple login is chosen using kakaotalk
1-1. In a case where kakao account exists, window for asking access permission will appear.

a_006.png

1-2. In case where kakao account is not connected, window will pop up, asking for userid and password for login. After credentials have been comfirmed, screen on approval and permission screen will appear.

a_007.png a_008.png

2. If simple login is chosen using kakaostory
2-1. If login has been processed, prompt asking for permission as example 1-1 will pop up, asking for permission to grant accesss to resources.
2-2. If account has been logged out, screen 3 will appear.

3. If simple login is chosen using another account. Using web view, window will pop up, asking for userid and password for login. After credentials have been comfirmed, screen on approval and permission screen will appear.

a_009.png a_010.png

Logout

Disconnecting session between app and kakao account in user's app.

Logging in to multiple device is supported. If user login in to multiple devices and log out from one of them, only the device that logged out will be affected(Session disconnected). Logging in to multiple device is supported.


Implement call back with dependency on logout request result (LogoutResponseCallback), and call UserManagement#requestLogout API.

  • onSuccess(long): This is the case where logout has been succeeded. ID of logged out user will be returned as result. In our example, user will be redirected to login window.
  • onFailure(APIErrorResult): This is the case where logout has failed with error received as result. Even with the case of logout failure, session will be deleted. As such, in our example, user will be redirected to login window regardless of whether logout has succeeded or not.Parameter APIErrorResult#getErrorCode(), APIErrorResult#getErrorMessage() will give details on reasons for failure. For details on error code, please refer here.
private void onClickLogout() {
    UserManagement.getInstance().requestLogout(new LogoutResponseCallback() {
        @Override
        protected void onSuccess(final long userId) {
            redirectLoginActivity();
        }

        @Override
        protected void onFailure(final APIErrorResult apiErrorResult) {
            redirectLoginActivity();
        }
    });
}

Unregister App connection

By unregistering from app, this permanently disconnect app and user registered in kakao platform which is simillar to deleting account from app. After unregistration has been completed, recovering account is not possible and can not use kakao platform service any longer. However, user can register with new connection with new data.

When doing unregistering from app, all of user data managed by kakao platform will be deleted. But third party app saved data is not gauranteed to be so by kakao platform service. This must be deleted in third party app(For details, refer to policies and agreement). This is the main difference between deleting account from app and disconnecting account from app.

Implement callback(UnlinkResponseCallback) depending on result of unlinking app, and call UserManagement#requestUnlink.

Since unlicking account with app results to deletion of user information upon success in our example, window for confirming on such activity will pop up.

  • onSuccess(long) : Upon success of unlinking app with account, user ID will be retrieved. In our example, user will be directed to login window.
  • onSessionClosedFailure(APIErrorResult) : Case for failure occuring due to closed session. Error will be returned as result. User will be redirected to login page in our example.
  • onFailure(APIErrorResult) : This is a failure due to reasons beside closed session. In this case, error result will be returned. Unlike logout request, session will be deleted only when "unlking with app" request succeeded.As such, if failure occurs, current session can be reused to re-request. User will be redirected to login window regardless of success or failure. However, if user make login attempt and "unlinking app with account" request has succeeded, signup window will pop up. On failure, login will be processed with the reuse of current session. For reasons for failures can be deteremined through parameter received through APIErrorResult#getErrorCode(), APIErrorResult#getErrorMessage(). For details about error code, refer here.
private void onClickUnlink() {
    final String appendMessage = getString(com.kakao.core.R.string.com_kakao_confirm_unlink);
    new AlertDialog.Builder(this)
        .setMessage(appendMessage)
        .setPositiveButton(getString(com.kakao.core.R.string.com_kakao_ok_button),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    UserManagement.getInstance().requestUnlink(new UnlinkResponseCallback() {
                        @Override
                        protected void onSuccess(final long userId) {
                            redirectLoginActivity();
                        }

                        @Override
                        protected void onSessionClosedFailure(final APIErrorResult errorResult) {
                            redirectLoginActivity();
                        }

                        @Override
                        protected void onFailure(final APIErrorResult errorResult) {
                            Logger.getInstance().d("failed to unlink. msg=" + apiErrorResult);
                            redirectLoginActivity();
                        }
                    });
                    dialog.dismiss();
                }
            })
        .setNegativeButton(getString(com.kakao.core.R.string.com_kakao_cancel_button),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            }).show();

}

Requesting user information

This is a functionality for requesting user information, such as user ID and personal details. In order to use such functionality, user token is needed which can be retrieved after successful login.This is also based on the fact that app is connected.

User ID is user's unique ID by app, issued when connecting with app. Using such id, you can identify user in you app. This value will maintain as long as user does not disconnect app from account.

Additional user information as stated below is provided by using kakao talk and kakaostory service through kakao platform service.

  • nickname: Kakaotalk or kakaostory nickname information
  • profile_image: Kakaotalk or kakaostory profile image URL(size : 480px * 480px ~ 1024px * 1024px)
  • thumbnail_image: Thumbnail profile image URL(size : 110px * 110px, 160px * 213px)

If needed, when connecting with app, specified additional information will be synced with Kakaotalk or KakaoStory service. Even if user has changed user information afterward in Kakaotalk or Kakaostory, such changes won't be affected.

If synchronization with kakaotalk or kakaostory is disabled, additional information will be blanked. Such additional information is interchangeable wtih different data anytime through User information settings. Manual synchronization with user information is also possible using Kakao platform service provided Kakao Talk or 카카오스토리 API. Setting for providing user's additional information by app can be found at Dashboard setting > user management > Setting for connecting app > linking with kakao account menu in developer website. dev_008.png

Implement call back MeResponseCallbackdepending on result of request for user information, and call UserManagement#requestMe(MeResponseCallback) API. If you wish to receive specific properties or receive image url through https, call UserManagement#requestMe(MeResponseCallback, ArrayList<String>, Boolean) API.

  • onSuccess(UserProfile) : This is the case for success of receiving user information, which in return receive user information as object. In our example, user information is shown.
  • onNotSignedUp() : This is failure case for user not signed up. In our example, user will be redirected to signup page.
  • onSessionClosedFailure(APIErrorResult) : This is the case for session being closed, and error result will be returned. User will be redirected to login page in our example.
  • onFailure(APIErrorResult) : This is a call back for failure with reasons beside user not being signed up or session being closed. In our example, error message will be shwon. For reasons for failures can be deteremined through parameter received through APIErrorResult#getErrorCode(), APIErrorResult#getErrorMessage(). For details about error code, refer here.
private void requestMe() {
    UserManagement.getInstance().requestMe(new MeResponseCallback() {
        @Override
        protected void onSuccess(final UserProfile userProfile) {
            // Success.
            showUserProfile(userProfile);
        }

        @Override
        protected void onNotSignedUp() {
            // Redirect to sign up page
            redirectSignupActivity();
        }

        @Override
        protected void onSessionClosedFailure(final APIErrorResult errorResult) {
            // Relogin
            redirectLoginActivity();
        }

        @Override
        protected void onFailure(final APIErrorResult errorResult) {
            // Failure
            Toast.makeText(getApplicationContext(), "failed to update profile. msg = " + errorResult, Toast.LENGTH_LONG).show();
        }
    });
}

Saving user information

Saving user information is a feature to save particular information about user. Beside additional information kakaoplatform service provide, user data can be saved from custom information set in developer site. In order to use such functionality, user token is needed which can be retrieved after successful login.

There are user informations that can not be modified by saving user information method. Such as user id can not be modified. Setting for retrieving additional user information can be found at developers website of dashboard, setting > user management > user information menu. Restrict custom user information column to below 5 in numbers, and restricting each custom user information to below 160 words is recommended. dev_009.png

This is an example code for retrieving user information, nickname and custom information, age. Custom information age category must be defined at dashboard setting > user management menu. Following example code is a code for saving nickname and custom information, age.

Saving user information uses user entered information Map and call back from request for saving user information (UpdateProfileResponseCallback)to call UserManagement#requestUpdateProfile() API.

private void requestUpdateProfile() {
    final Map<String, String> properties = new HashMap<String, String>();
    properties.put("nickname", "mj");
    properties.put("age", "22");

    UserManagement.getInstance().requestUpdateProfile(new UpdateProfileResponseCallback() {
        @Override
        protected void onSuccess(final long userId) {
            UserProfile.updateUserProfile(userProfile, properties);
            if (userProfile != null)
                userProfile.saveUserToCache();
            showProfile();
        }

        @Override
        protected void onSessionClosedFailure(final APIErrorResult errorResult) {
            redirectLoginActivity();
        }

        @Override
        protected void onFailure(final APIErrorResult errorResult) {
            Toast.makeText(getApplicationContext(), "failed to update profile. msg = " + errorResult, Toast.LENGTH_LONG).show();
        }
    }, properties);
}

Error code

Troubleshooting

If there was trouble following getting started or sample app not working properly, refer to Troubleshooting user management을 참고해 보세요.


Last Modified : 2019-07-25