# SignInClient

public interface **SignInClient** implements [HasApiKey](https://developers.google.com/android/reference/com/google/android/gms/common/api/HasApiKey)\<[SignInOptions](https://developers.google.com/android/reference/com/google/android/gms/auth/api/identity/SignInOptions)\> A client for the sign-in API.

The Sign-In APIs can be used for both sign-in and sign-up scenarios. The two scenarios
share the same flow in the code, but different `https://developers.google.com/android/reference/com/google/android/gms/auth/api/identity/BeginSignInRequest`
should be provided in different scenarios.

The Sign-In APIs guide the user through credential selection before returning an instance
of `https://developers.google.com/android/reference/com/google/android/gms/auth/api/identity/SignInCredential`
containing the data for sign-in or sign-up.

The recommended process for retrieving credentials using this API is as follows:

1. Get a new API client instance by calling `https://developers.google.com/android/reference/com/google/android/gms/auth/api/identity/Identity#getSignInClient(android.app.Activity)`.
2. Call `https://developers.google.com/android/reference/com/google/android/gms/auth/api/identity/SignInClient#beginSignIn(com.google.android.gms.auth.api.identity.BeginSignInRequest)`, supplying the constructed `https://developers.google.com/android/reference/com/google/android/gms/auth/api/identity/BeginSignInRequest` as an input.
3. If the request is successful, at least one matching credential is available. Launch the `https://developer.android.com/reference/android/app/PendingIntent.html` from the `https://developers.google.com/android/reference/com/google/android/gms/auth/api/identity/BeginSignInResult` of the operation to display the UI that guides the user through sign-in. The result of sign-in will be returned in `https://developer.android.com/reference/android/app/Activity.html#onActivityResult(int,%20int,%20android.content.Intent)`; calling `https://developers.google.com/android/reference/com/google/android/gms/auth/api/identity/SignInClient#getSignInCredentialFromIntent(android.content.Intent)` will either return the `https://developers.google.com/android/reference/com/google/android/gms/auth/api/identity/SignInCredential` if the operation was successful, or throw an `https://developers.google.com/android/reference/com/google/android/gms/common/api/ApiException` that indicates the reason for failure.
4. If the request is unsuccessful, no matching credential was found on the device that can be used to sign the user in. No further action needs to be taken.

When the user signs out of your application, please make sure to call `https://developers.google.com/android/reference/com/google/android/gms/auth/api/identity/SignInClient#signOut()`.

## The usage of `https://developers.google.com/android/reference/com/google/android/gms/auth/api/identity/BeginSignInRequest`

Different `https://developers.google.com/android/reference/com/google/android/gms/auth/api/identity/BeginSignInRequest`
should be used for sign-in and sign-up.

### Sign an existing user in

Two types of credentials are supported in `https://developers.google.com/android/reference/com/google/android/gms/auth/api/identity/SignInCredential`:
Google ID token and password. To give users more options to choose from when selecting a
credential to sign in with, and by extension, increase your app's sign-in rate, it is
strongly recommended that applications support both Google ID token and password
credentials:

1. If your application supports username/password login, configure an instance of `https://developers.google.com/android/reference/com/google/android/gms/auth/api/identity/BeginSignInRequest.PasswordRequestOptions` in the request.
2. If your application supports federated sign-in using Google ID tokens, configure an instance of `https://developers.google.com/android/reference/com/google/android/gms/auth/api/identity/BeginSignInRequest.GoogleIdTokenRequestOptions` accordingly - be sure to supply your server client ID (you can find this in your Google API console project).

   For the sign-in scenario, it is strongly recommended to set `https://developers.google.com/android/reference/com/google/android/gms/auth/api/identity/BeginSignInRequest.GoogleIdTokenRequestOptions.Builder#setFilterByAuthorizedAccounts(boolean)` to
   `true` so only the Google accounts that the user has authorized before will
   show up in the credential list. This can help prevent a new account being created when
   the user has an existing account registered with the application.

For example, an app that supports password login and federated sign-in with Google would
construct a request as follows:

    BeginSignInRequest request = BeginSignInRequest.builder()
         .setPasswordRequestOptions(
             PasswordRequestOptions.builder()
                 .setSupported(true)
                 .build())
         .setGoogleIdTokenRequestOptions(
             GoogleIdTokenRequestOptions.builder()
                 .setSupported(true)
                 // Set filterByAuthorizedAccounts = true to avoid duplicated accounts being created
                 .setFilterByAuthorizedAccounts(true)
                 .setServerClientId("serverClientID")
                 .build())
         .build();
     
### Sign up a new user

For the sign-up scenario, only Google ID token credentials should be used. The
`https://developers.google.com/android/reference/com/google/android/gms/auth/api/identity/BeginSignInRequest.GoogleIdTokenRequestOptions` may look like the following:

    BeginSignInRequest request = BeginSignInRequest.builder()
         .setGoogleIdTokenRequestOptions(
             GoogleIdTokenRequestOptions.builder()
                 .setSupported(true)
                 .setFilterByAuthorizedAccounts(false)
                 .setServerClientId("serverClientID")
                 .build())
         .build();
     
### Public Method Summary

|---|---|
| abstract Task\<[BeginSignInResult](https://developers.google.com/android/reference/com/google/android/gms/auth/api/identity/BeginSignInResult)\> | [beginSignIn](https://developers.google.com/android/reference/com/google/android/gms/auth/api/identity/SignInClient#beginSignIn(com.google.android.gms.auth.api.identity.BeginSignInRequest))([BeginSignInRequest](https://developers.google.com/android/reference/com/google/android/gms/auth/api/identity/BeginSignInRequest) signInRequest) *This method is deprecated. Use [Credential Manager](https://developer.android.com/training/sign-in/passkeys) instead.* |
| abstract [String](https://developer.android.com/reference/java/lang/String.html) | [getPhoneNumberFromIntent](https://developers.google.com/android/reference/com/google/android/gms/auth/api/identity/SignInClient#getPhoneNumberFromIntent(android.content.Intent))([Intent](https://developer.android.com/reference/android/content/Intent.html) data) Retrieves the Phone Number from the `https://developer.android.com/reference/android/content/Intent.html` returned upon a successful Phone Number Hint request, throwing an `https://developers.google.com/android/reference/com/google/android/gms/common/api/ApiException` if no phone number is available or the input `https://developer.android.com/reference/android/content/Intent.html` is null. |
| abstract Task\<[PendingIntent](https://developer.android.com/reference/android/app/PendingIntent.html)\> | [getPhoneNumberHintIntent](https://developers.google.com/android/reference/com/google/android/gms/auth/api/identity/SignInClient#getPhoneNumberHintIntent(com.google.android.gms.auth.api.identity.GetPhoneNumberHintIntentRequest))([GetPhoneNumberHintIntentRequest](https://developers.google.com/android/reference/com/google/android/gms/auth/api/identity/GetPhoneNumberHintIntentRequest) getPhoneNumberHintIntentRequest) Gets the `https://developer.android.com/reference/android/app/PendingIntent.html` that initiates the Phone Number Hint flow. |
| abstract [SignInCredential](https://developers.google.com/android/reference/com/google/android/gms/auth/api/identity/SignInCredential) | [getSignInCredentialFromIntent](https://developers.google.com/android/reference/com/google/android/gms/auth/api/identity/SignInClient#getSignInCredentialFromIntent(android.content.Intent))([Intent](https://developer.android.com/reference/android/content/Intent.html) data) *This method is deprecated. Use [Credential Manager](https://developer.android.com/training/sign-in/passkeys) instead.* |
| abstract Task\<[PendingIntent](https://developer.android.com/reference/android/app/PendingIntent.html)\> | [getSignInIntent](https://developers.google.com/android/reference/com/google/android/gms/auth/api/identity/SignInClient#getSignInIntent(com.google.android.gms.auth.api.identity.GetSignInIntentRequest))([GetSignInIntentRequest](https://developers.google.com/android/reference/com/google/android/gms/auth/api/identity/GetSignInIntentRequest) getSignInIntentRequest) *This method is deprecated. Use [Credential Manager](https://developer.android.com/training/sign-in/passkeys) instead.* |
| abstract Task\<[Void](https://developer.android.com/reference/java/lang/Void.html)\> | [signOut](https://developers.google.com/android/reference/com/google/android/gms/auth/api/identity/SignInClient#signOut())() *This method is deprecated. Use [Credential Manager](https://developer.android.com/training/sign-in/passkeys) instead.* |

## Public Methods

#### public abstract Task\<[BeginSignInResult](https://developers.google.com/android/reference/com/google/android/gms/auth/api/identity/BeginSignInResult)\>
**beginSignIn** ([BeginSignInRequest](https://developers.google.com/android/reference/com/google/android/gms/auth/api/identity/BeginSignInRequest) signInRequest)

**This method is deprecated.**   

Use [Credential Manager](https://developer.android.com/training/sign-in/passkeys)
instead.
Initiates the retrieval of a credential that can assist the caller in signing a user
in to their application.

If the request cannot be honored, an exception will be set on the returned
`https://developers.google.com/android/reference/com/google/android/gms/tasks/Task`. In all
other cases, a `https://developers.google.com/android/reference/com/google/android/gms/auth/api/identity/BeginSignInResult`
will be returned.

##### Parameters

| signInRequest | configuration for the sign-in operation |
|---|---|

##### Returns

- `https://developers.google.com/android/reference/com/google/android/gms/tasks/Task` which eventually contains the result of the initialization

#### public abstract [String](https://developer.android.com/reference/java/lang/String.html) **getPhoneNumberFromIntent** ([Intent](https://developer.android.com/reference/android/content/Intent.html) data)

Retrieves the Phone Number from the `https://developer.android.com/reference/android/content/Intent.html`
returned upon a successful Phone Number Hint request, throwing an `https://developers.google.com/android/reference/com/google/android/gms/common/api/ApiException`
if no phone number is available or the input `https://developer.android.com/reference/android/content/Intent.html` is
null.

##### Throws

| [ApiException](https://developers.google.com/android/reference/com/google/android/gms/common/api/ApiException) |   |
|---|---|

#### public abstract Task\<[PendingIntent](https://developer.android.com/reference/android/app/PendingIntent.html)\>
**getPhoneNumberHintIntent** ([GetPhoneNumberHintIntentRequest](https://developers.google.com/android/reference/com/google/android/gms/auth/api/identity/GetPhoneNumberHintIntentRequest) getPhoneNumberHintIntentRequest)

Gets the `https://developer.android.com/reference/android/app/PendingIntent.html`
that initiates the Phone Number Hint flow.

If there is no phone number on the device, an exception will be set on the returned
`https://developers.google.com/android/reference/com/google/android/gms/tasks/Task`. In all
other cases, a `https://developer.android.com/reference/android/app/PendingIntent.html`
will be returned.

##### Returns

- `https://developers.google.com/android/reference/com/google/android/gms/tasks/Task` which can be used to start the Phone Number Hint flow.

#### public abstract [SignInCredential](https://developers.google.com/android/reference/com/google/android/gms/auth/api/identity/SignInCredential)
**getSignInCredentialFromIntent** ([Intent](https://developer.android.com/reference/android/content/Intent.html) data)

**This method is deprecated.**   

Use [Credential Manager](https://developer.android.com/training/sign-in/passkeys)
instead.
Retrieves the `https://developers.google.com/android/reference/com/google/android/gms/auth/api/identity/SignInCredential`
from the `https://developer.android.com/reference/android/content/Intent.html`
returned upon successful sign-in, throwing an `https://developers.google.com/android/reference/com/google/android/gms/common/api/ApiException`
if no credential is present.

##### Throws

| [ApiException](https://developers.google.com/android/reference/com/google/android/gms/common/api/ApiException) |   |
|---|---|

#### public abstract Task\<[PendingIntent](https://developer.android.com/reference/android/app/PendingIntent.html)\>
**getSignInIntent** ([GetSignInIntentRequest](https://developers.google.com/android/reference/com/google/android/gms/auth/api/identity/GetSignInIntentRequest) getSignInIntentRequest)

**This method is deprecated.**   

Use [Credential Manager](https://developer.android.com/training/sign-in/passkeys)
instead.
Gets the `https://developer.android.com/reference/android/app/PendingIntent.html`
that initiates the Google Sign-in flow.

If the request cannot be honored, an exception will be set on the returned
`https://developers.google.com/android/reference/com/google/android/gms/tasks/Task`. In all
other cases, a `https://developer.android.com/reference/android/app/PendingIntent.html`
will be returned.

##### Parameters

| getSignInIntentRequest | configuration for Google Sign-in flow |
|---|---|

##### Returns

- `https://developers.google.com/android/reference/com/google/android/gms/tasks/Task` which eventually contains the `https://developer.android.com/reference/android/app/PendingIntent.html` to start the Google Sign-in flow.

#### public abstract Task\<[Void](https://developer.android.com/reference/java/lang/Void.html)\> **signOut** ()

**This method is deprecated.**   

Use [Credential Manager](https://developer.android.com/training/sign-in/passkeys)
instead.
Resets internal state related to sign-in.

This method should be invoked when a user signs out of your app.

##### Returns

- `https://developers.google.com/android/reference/com/google/android/gms/tasks/Task` which eventually terminates in success or failure