---
metadata:
  - name: generator
    content: Diplodoc Platform v5.44.0
alternate:
  - https://yandex.com/dev/id/doc/en/mobileauthsdk/android/archive/2.5.1/sdk-android-use.md
  - https://yandex.com/dev/id/doc/ru/mobileauthsdk/android/archive/2.5.1/sdk-android-use.md
---
> **Documentation Index:** Fetch the complete configuration index at https://yandex.com/dev/id/doc/en/llms.txt

# Using the SDK

To obtain tokens, follow these steps:

## Step 1. Initialization {#initialisation}

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

   ```java
   android {
         defaultConfig {
         manifestPlaceholders = [YANDEX_CLIENT_ID:"<app ID_clientID>"]
      }
   }
   ```

   * You can find the app's **Client ID** in [its properties](https://yandex.com/dev/id/doc/en/register-client.md#app-params).

1. Use the following code for initialization:

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

## Step 2. Authorization {#authorization}

1. To enable authorization, use the following method:

   ```java
   final YandexAuthLoginOptions.Builder loginOptionsBuilder =  new YandexAuthLoginOptions.Builder();
   final Intent intent = sdk.createLoginIntent(loginOptionsBuilder.build());
   ```

1. To get authorization events, override the following method:

   ```java
   @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 {#jwt}

To obtain a [JSON Web Token](https://yandex.com/dev/id/doc/en/tokens/jwt.md), use the following method:

```java
sdk.getJwt(yandexAuthToken);
```

## Step 4. Getting information about the user {#user-info}

You can exchange the obtained token for [user information](https://yandex.com/dev/id/doc/en/user-information.md).

## Useful links {#useful-links}

* [Exchanging the token for information about the user](https://yandex.com/dev/id/doc/en/user-information.md)
* [Method guide](https://yandex.com/dev/id/doc/en/mobileauthsdk/android/archive/2.5.1/sdk-android-methods.md)
* [Error codes](https://yandex.com/dev/id/doc/en/mobileauthsdk/android/archive/2.5.1/sdk-android-errors.md)
