Step3. Authentication

    Step3. Authentication


    Article summary

    Shoplive uses user information for the following purposes:

    • Displaying user names and messages in chat functions

    • Saving logs based on user ID when clicking pop-ups (notices, banners, coupons, etc.)

    • Saving logs based on user ID when clicking on products or liking them

    • Saving other user action logs based on user ID

    Shoplive Player can receive user information using easy authentication and JWT authentication methods.

    • Guest: Available without login

    • Simple Authentication: Fast and simple authentication 

    • JWT Authentication: Authentication applied through a security authentication token (JWT)

    For more detail, please refer to JWT token guide.


    Guest mode

    • Shoplive player can run without any user authentication

    • Guest user still can set user name 

    // User without login info
    class YourActivity: Activity() {
        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
            setContentView(R.layout.activity_your)
    
            playButton.setOnClickListener {
                ShopLive.play(this, ShopLivePlayerData(campaignKey).apply {
                    keepWindowStateOnPlayExecuted = false
                    referrer = "referrer"
                })
            }        
        }
    }
    
    
    // Setting user name for user without login info
    class YourActivity: Activity() {
        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
            setContentView(R.layout.activity_your)
    
            // 사용자 이름 사용
            val user = ShopLiveUser().apply {
                userName = "{USER_NAME}"
            }
            ShopLive.setUser(user)
    
            playButton.setOnClickListener {
                ShopLive.play(this, ShopLivePlayerData(campaignKey).apply {
                    keepWindowStateOnPlayExecuted = false
                    referrer = "referrer"
                })
            }        
        }
    }

    Chatting

    • If guest chat is not allowed, selecting the chat button will not trigger a response.

    • If a guest nickname is not set as mandatory, the guest nickname will be assgined randomly.

    • If a guest nickname is set as mandatory and the chat button is pressed, a popup for setting the guest nickname will appear. You must set a guest nickname to connect to the chat.

    • Admin User Guide


    Fast & simple authentication

    • You can link user accounts of the service through the feature of setting the user's ID and login user nickname

    • You can set user ID, name, age, gender, user score, and other custom data information.

    class YourActivity: Activity() {
        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
            setContentView(R.layout.activity_your)
    
            // *userId is required field 
            val user = ShopLiveUser().apply {
                userId = "{USER_ID}"
                userName = "{USER_NAME}"
                gender = ShopLiveUserGender.Male
                age = 25
                userScore = 20
            }
            ShopLive.setUser(user)
    
            playButton.setOnClickListener {
                ShopLive.play(this, ShopLivePlayerData(campaignKey).apply {
                    keepWindowStateOnPlayExecuted = false
                    referrer = "referrer"
                })
            }          
        }
    }


    JWT Authentication

    Using the security authentication token (JWT) issued with the broadcast key (Campaign Key) provided by Shoplive Admin, you can set user ID, name, and other information in the Shoplive Android SDK.

    class YourActivity: Activity() {
        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
            setContentView(R.layout.activity_your)
    
            // set JWT for authentication
            ShopLive.setAuthToken("{jwt}")
    
            playButton.setOnClickListener {
                ShopLive.play(this, ShopLivePlayerData(campaignKey).apply {
                    keepWindowStateOnPlayExecuted = false
                    referrer = "referrer"
                })
            }
        }
    }


    Change a user name

    When a user changes their username in the Shoplive Player, the Shoplive Android SDK uses the onSetUserName function to relay the change to the client.

    override fun onSetUserName(jsonObject: JSONObject) {
        super.onSetUserName(jsonObject)
        Log.d(TAG, "userId=${jsonObject.get("userId")}, userName=${jsonObject.get("userName")}")
    }


    Switch from a guest account to a logged-in user account

    From Shoplive admin page > Broadcast detail page > Chatting settings,  you can turn off Guest chatting to disable chatting feature for guest users . in this case user may want to login and you want the process user authentication while user is already on player

    In this case, use LOGIN_REQUIRED callback to catch such incident and route user to your own login process. once done, runShoplive Player again to switch to logged-in account.

    override fun onReceivedCommand(context: Context, command: String, data: JSONObject) {
        when(command) {
            "LOGIN_REQUIRED" -> {
                /*
                    1. Route to login process
                    2. once done, rerun the player with auth info
                 */
            }
        }
    }