Usage
To obtain tokens, follow these steps:
Step 1. Initialization
-
Add this code to your app's
build.gradle
file:android { defaultConfig { manifestPlaceholders = [YANDEX_CLIENT_ID:"<app ID_clientID>"] } }
- You can find the app's Client ID in its properties.
-
Use the following code for initialization:
final YandexAuthSdk sdk = new YandexAuthSdk(requireContext(), new YandexAuthOptions(requireContext()));
Step 2. Authorization
-
To start authorization, use this method:
final YandexAuthLoginOptions.Builder loginOptionsBuilder = new YandexAuthLoginOptions.Builder(); final Intent intent = sdk.createLoginIntent(loginOptionsBuilder.build());
-
To get 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); }
Step 3. Obtaining a JSON Web Token
To obtain a JSON Web Token, use the following method:
sdk.getJwt(yandexAuthToken);
Step 4. Getting user information
You can exchange the obtained token for user information.
Useful resources
Was the article helpful?
Previous
Next