Login with the Auto-Saved Credentials
In this approach, your application performs the re-login with the access token and credentials that are automatically stored by the SDK. The access token and credentials are auto-saved by the SDK when a user login or refresh is executed.
Kii SDK will store the following user credentials in the Keychain (not in iCloud Keychain) each time when you successfully log in or refresh user.
- User ID
- Email address
- Phone number
- Display name
- Access Token
- Expiration period of the access token
- Refresh token
The information is deleted only when the logout is executed.
Kii SDK will store the user credentials in the Keychain as an item with kSecClassKey for kSecClass and "KiiSDK/user_credentials" for kSecAttrApplicationLabel. If your application uses the Keychain to store information, please make sure not to conflict with the credentials stored by Kii SDK. Please read Keychain Services Programming Guide from Apple for the details.
The following sample code shows how to login with these credentials.
You can login by executing the
authenticate(storedCredentials:_:) method if the credentials are stored in the Keychain. This method just restores the login state from the Keychain and does not access the server. To get the latest user information from the server, you need to execute the
The stored credentials are deleted from the Keychain when you execute the
logOut() method. Executing the
authenticate(storedCredentials:_:) method after the logout will throw an exception.
An error will be thrown if reading the stored credentials from the Keychain fails for some reasons. Please consider handling such a case by letting users logs in with their password.
Whether the user logs in again or not, the credentials including the access token are saved every time when the user logs in or gets refreshed.
You can also let pseudo users log in with the
authenticate(storedCredentials:_:) method by calling the
refresh(_:) method of the
KiiUser class just after each pseudo user is created.
When you design your mobile app, make sure to implement serialization and screen transition logics. See Title screen in Kii Balance tutorial for some references.