-
Notifications
You must be signed in to change notification settings - Fork 1
Authenticating a user
The Community Android SDK supports browsing through Khoros Communities irrespective of being a logged-in or an anonymous guest. However, to participate in the community activities like posting a question or blog article, replying to a post, or giving kudos to a post, a user must be a signed-in, registered community member.
The SDK supports Lithium Registration and LithiumSSO authentication options. After a user authenticates through one of these options and receives the corresponding access keys, the SDK makes calls to the Community REST APIs on behalf of the logged-in user using those keys.
An anonymous user will receive a 401 error (Unauthorized) if the user attempts to perform an action that he or she does not have permission to do. We show an example of how to check for a 401 error and how to start the login flow when attempting to perform an unauthorized action in our Tutorial guide.
As we've described in Getting Started, the authentication flow is launched explicitly in your code. You may include it in your initialization code, or trigger the flow at some point after you have initialized the SDK, such as when the user attempts to perform an action like replying to a message or giving a kudo. See Initializing the SDK for the initialization instructions.
The Community Android SDK supports the following user authentication options:
- Lithium Registration
- LithiumSSO token authentication
- Custom SSO - Contact Khoros Services for custom SSO integrations
Lithium Registration is the most basic authentication method and is configured in Community Admin. A Community user creates an account by providing an email, username, and password. Khoros stores all account information. Password management actions such as Forgot Password or Password Reset are done through the platform.
A username, email, and password are required when creating an account, although Khoros Services might have added additional, required registration fields requested by your Community team during launch. You can learn more about Lithium Registration in API Authentication Overview in the Khoros Developer Documentation Portal and Set registration options in the Khoros Communities Documentation Knowledge Base.
LithiumSSO uses a token created using the Community API LithiumSSOClient
class. (See LithiumSSO token authentication in the Developer Documentation Portal for sample token-generation code.) After creating the token, store the token as a String in a variable.
In addition to the SSO developer documentation mentioned above, also see About Single Sign-On and Configure SSO options in the Li Docs Knowledge Base.
The SDK includes the following utility method on LiSDKManager
for user authentication:
-
LiSDKManager.getInstance().isUserLoggedIn()
- Check whether the user is logged in
The Support UI login flow with Lithium Registration takes the user to the LiLoginActivity
(li_login_activity.xml)
where he or she enters a username and password. When using SSO with the Support UI, authentication occurs in the background.
You initiate the authentication/login flow using one of the login
methods on LiSDKManager
. If your community uses SSO, be sure to use a method that takes the SSO token.
When using Firebase Cloud Messaging, you must pass the device token ID used to register that device for notification. Do not pass a device token ID if using any other notification service -- Khoros will simply register the subscription event and your subscription service will handle the notification.
login(android.content.Context context)
login(android.content.Context context, java.lang.String ssoToken)
The lia-core
and lia-ui
libraries use the same login
methods.
When making the below calls, as callback after login operation being successful or failure, A BroardcastReceiver needs to be registered with "lithium.sdk.auth.HANDLE_AUTHORIZATION_RESPONSE" action in the Intent Filter. And in the onReceive of the receiver.
boolean result = intent.getBooleanExtra(LiCoreSDKConstants.LOGIN_RESULT, false);
if (result) {
// Login success
} else {
// Login failed
}
When using Lithium Registration
LiSDKManager.getInstance().login(context);
When using LithiumSSO
LiSDKManager.getInstance().login(context, "<SSO Token>");
If a user needs to switch the login or log out of the community, there is an option to logout, which necessarily stops any notifications being sent to that device for that particular user.
Logout is done using
LiSDKManager.getInstance().logout(context, callback);
This is an asynchronous call, the result is sent back to the callback object.