The account and user software development kit (SDK) provides account-related features, such as registration, logon, logout, account retrieval, session management, and human-machine verification. The SDK also offers UI integration and customization.
Dependent SDK | Overview |
API channel | Provides API channel capabilities. |
Initialization
For information about initialization, see SDK initialization.
Built-in accounts
Built-in accounts is a feature provided by IoT Platform that is ready to use after client integration. It includes the following features.
Basic features
Basic features include registration, logon, logout, password retrieval, and account closure.
Registration
After you call the logon page, the options for registration and password retrieval are displayed. No additional development is required.
Logon
The platform supports two logon methods: by account and by email. After you call the logon page, both methods become available.
LoginBusiness.login(new ILoginCallback() { @Override public void onLoginSuccess() { Log.i(TAG,"Logon successful"); } @Override public void onLoginFailed(int code, String error) { Log.i(TAG,"Logon failed"); } });Logout
LoginBusiness.logout(new ILogoutCallback() { @Override public void onLogoutSuccess() { Log.i(TAG,"Log out successful"); } @Override public void onLogoutFailed(int code, String error) { Log.i(TAG,"Log out failed"); } });Forgot your password?
After you call the logon page, the options for registration and password retrieval are displayed. No additional development is required.
Account closure
When an account is closed, all devices attached to it are automatically detached. For more information, see Close an account.
Modifying personal information
Map<String, Object> map = new LinkedHashMap<>(); map.put("displayName", newName); OpenAccountUIService oas = OpenAccountSDK.getService(OpenAccountUIService.class); oas.updateProfile(getApplicationContext(), map, new LoginCallback() { @Override public void onSuccess(OpenAccountSession openAccountSession) { } @Override public void onFailure(int i, String s) { } });Modifying the profile picture
First, store the profile picture in the cloud and obtain its URL. Then, you can update the profile picture as follows:
Map<String, Object> map = new LinkedHashMap<>(); map.put("avatarUrl", avatarUrl); OpenAccountUIService oas = OpenAccountSDK.getService(OpenAccountUIService.class); oas.updateProfile(getApplicationContext(), map, new LoginCallback() { @Override public void onSuccess(OpenAccountSession openAccountSession) { } @Override public void onFailure(int i, String s) { } });Refreshing a session
LoginBusiness.refreshSession(true, new IRefreshSessionCallback() { @Override public void onRefreshSuccess() { Log.i(TAG,"Session refreshed successfully"); } @Override public void onRefreshFailed() { Log.i(TAG,"Failed to refresh session"); } });Retrieving a session ID
Add the following code to retrieve the current session ID:
LoginBusiness.getSessionId();Retrieving user information
Add the following code to retrieve information about the current user:
LoginBusiness.getUserInfo();Switching the Open Account language
When you switch the SDK language in your Android app, the Open Account (OA) language is also switched automatically. No additional development is required. For more information about how to switch the SDK language, see General-purpose SDK.
Customizing the logon page
You can customize your logon page by referring to the postInit method of the `SDKInitHelper` class in the demo application code. For more information about how to obtain the demo application source code, see Create your own app.
Customizing the UI
For more information, see Customize the OA UI for an Android app.
Third-party accounts
Before you integrate third-party accounts, confirm that the default account page (the built-in account system) supports registration and logon. You must also ensure that the SDK is initialized. For more information about SDK initialization, see SDK initialization.
To connect with your own accounts, use the OAuth 2.0 protocol. For more information about the configuration flow, see User account development guide.
After a user successfully logs on to your server with a third-party account, retrieve the Authorization Code (for more information, see User account development guide). Then, call the following method to complete the authentication.
LoginBusiness.authCodeLogin(authCode, new ILoginCallback() {
@Override
public void onLoginSuccess() {
}
@Override
public void onLoginFailed(int i, String s) {
Log.d(TAG, "code: " + i + ", str: " + s);
}
});To call the logon or logout APIs, invoke the LoginBusiness.login and LoginBusiness.logout methods.