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:

    val sdk = YandexAuthSdk.create(YandexAuthOptions(requireContext()))
    
    YandexAuthSdk sdk = YandexAuthSdk.create(new YandexAuthOptions(requireContext()));
    

Step 2. Authorization

  1. Start the authorization:

    val sdk = YandexAuthSdk.create(YandexAuthOptions(requireContext()))
    val launcher = registerForActivityResult(sdk.contract) { result -> handleResult(result) }
    val loginOptions = YandexAuthLoginOptions()
    launcher.launch(loginOptions)
    
    YandexAuthSdk sdk = YandexAuthSdk.create(new YandexAuthOptions(requireContext()));
    ActivityResultLauncher<YandexAuthLoginOptions> launcher =
       registerForActivityResult(sdk.getContract(), result -> handleResult(result));
    YandexAuthLoginOptions loginOptions = new YandexAuthLoginOptions();
    launcher.launch(loginOptions);
    
  2. To handle authorization events, use code like this:

    private fun handleResult(result: YandexAuthResult) {
       when (result) {
          is YandexAuthResult.Success -> onSuccessAuth(result.token)
          is YandexAuthResult.Failure -> onProccessError(result.exception)
          YandexAuthResult.Cancelled -> onCancelled()
       }
    }
    
    private void handleResult(YandexAuthResult result) {
       if (result instanceof YandexAuthResult.Success) {
          onSuccessAuth(((YandexAuthResult.Success) result).getToken());
       } else if (result instanceof YandexAuthResult.Failure) {
          onProccessError(((YandexAuthResult.Failure) result).getException());
       } else {
          onCancelled();
       }
    }
    

Step 3. Obtaining a JSON Web Token

To obtain a JSON Web Token, use the following method:

sdk.getJwt(yandexAuthToken)
sdk.getJwt(yandexAuthToken);

Step 4. Getting user information

You can exchange the obtained token for user information.