Using the SDK
Set up your app to receive tokens by following these steps:
1. Initialization
In your app's build.gradle
, add:
android {
defaultConfig {
manifestPlaceholders = [YANDEX_CLIENT_ID:"<Client id of you application>"]
}
}
Use this code for initialization:
final YandexAuthSdk sdk = new YandexAuthSdk(requireContext(), new YandexAuthOptions.Builder(requireContext())
.enableLogging() // Only in testing builds
.build());
2. Authorization
To enable authorization, use the following method:
final YandexAuthLoginOptions.Builder loginOptionsBuilder = new YandexAuthLoginOptions.Builder();
final Intent intent = sdk.createLoginIntent(loginOptionsBuilder.build());
To receive authorization events, override the following method:
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
if (requestCode == REQUEST_LOGIN_SDK) {
try {
final YandexAuthToken yandexAuthToken = sdk.extractToken(resultCode, data);
if (yandexAuthToken != null) {
// Success auth
}
} catch (YandexAuthException e) {
// Process error
}
return;
}
super.onActivityResult(requestCode, resultCode, data);
}
3. Getting a JSON Web Token
To get a JSON Web Token, use the following method:
sdk.getJwt(yandexAuthToken);
Error codes
Error codes are described in the Error codes section.