Usage

To obtain tokens, follow these steps:

Step 1. Initialization

  1. Add this code to your app's build.gradle file:

    android {
          defaultConfig {
          manifestPlaceholders = [YANDEX_CLIENT_ID:"<app ID_clientID>"]
       }
    }
    
  2. Use the following code for initialization:

    final YandexAuthSdk sdk = new YandexAuthSdk(requireContext(), new YandexAuthOptions(requireContext()));
    

Step 2. Authorization

  1. To start authorization, use this method:

    final YandexAuthLoginOptions.Builder loginOptionsBuilder =  new YandexAuthLoginOptions.Builder();
    final Intent intent = sdk.createLoginIntent(loginOptionsBuilder.build());
    
  2. 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.