# OAuthClient

Summary:[Nested Classes](https://developer.android.com/reference/android/support/wearable/authentication/OAuthClient#nestedclasses)\|[Constants](https://developer.android.com/reference/android/support/wearable/authentication/OAuthClient#constants)\|[Methods](https://developer.android.com/reference/android/support/wearable/authentication/OAuthClient#pubmethods)\|[Protected Methods](https://developer.android.com/reference/android/support/wearable/authentication/OAuthClient#promethods)\|[Inherited Methods](https://developer.android.com/reference/android/support/wearable/authentication/OAuthClient#inhmethods)  

# OAuthClient

`
public


class
OAuthClient
`  
`

extends `[Object](http://developer.android.com/reference/java/lang/Object.html)`


``


`

|---|-----------------------------------------------------|
| [java.lang.Object](http://developer.android.com/reference/java/lang/Object.html) ||
| ↳ | android.support.wearable.authentication.OAuthClient |

<br />

*** ** * ** ***

<br />

**This class is deprecated.**   
use`androidx.wear.phone.interactions.authentication.RemoteAuthClient`provided by the[Jetpack Wear Phone Interactions](https://developer.android.com/jetpack/androidx/releases/wear)library instead.

Provides a client for supporting OAuth 2.0 on Wear. The authorization UI will appear on the user's phone.

The following example triggers an authorization session to open on the phone.  


     private OAuthClient mClient;

     @Override
     public void onCreate(Bundle b) {
       super.onCreate(b);
       mClient = OAuthClient.create(this);
       ...
     }

     @Override
     public void onDestroy() {
       mClient.destroy();
       super.onDestroy();
     }

     public void startOAuthFlow() {
       // Construct the redirect_uri used in your OAuth request.
       // OAuthClient.WEAR_REDIRECT_URL ensures the response will be received by Wear OS.
       // The receiving app's package name is required as the 3rd path component in the redirect_uri.
       // This allows Wear to ensure other apps cannot reuse your redirect_uri to receive responses.
       String redirectUri = OAuthClient.WEAR_REDIRECT_URL_PREFIX + "com.package.name";
       // Construct the appropriate request for the OAuth provider you wish to integrate with.
       String requestUrl = "https:// .... &redirect_uri=" + redirectUri;
       // Send it. This will open an authentication UI on the phone.
       mClient.sendAuthorizationRequest(Uri.parse(requestUrl), new MyOAuthCallback());
     }

     private final class MyOAuthCallback extends OAuthClient.Callback {
       @Override
       public void onAuthorizationResponse(Uri requestUrl, Uri resultUrl) {
         // Parse the result token out of the result URL and store it, e.g. in SharedPreferences,
         // so you can use it later. You'll also want to display a success UI.
         ...
       }

       @Override
       public void onAuthorizationError(int errorCode) {
         // Compare against codes available in OAuthClient.ErrorCode
         // You'll also want to display an error UI.
         ...
       }
     }
     
<br />

## Summary

|                                                                                                                                                                                   ### Nested classes                                                                                                                                                                                    ||
|---------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` class`      | [OAuthClient.Callback](https://developer.android.com/reference/android/support/wearable/authentication/OAuthClient.Callback.html) *This class is deprecated. use`androidx.wear.phone.interactions.authentication.RemoteAuthClient`provided by the[Jetpack Wear Phone Interactions](https://developer.android.com/jetpack/androidx/releases/wear)library instead.*        |
| ` @interface` | [OAuthClient.ErrorCode](https://developer.android.com/reference/android/support/wearable/authentication/OAuthClient.ErrorCode.html) *This @interface is deprecated. use`androidx.wear.phone.interactions.authentication.RemoteAuthClient`provided by the[Jetpack Wear Phone Interactions](https://developer.android.com/jetpack/androidx/releases/wear)library instead.* |

|                                                                                                                                                                                                                                                      ### Constants                                                                                                                                                                                                                                                      ||
|------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `int`                                                                  | [ERROR_PHONE_UNAVAILABLE](https://developer.android.com/reference/android/support/wearable/authentication/OAuthClient.html#ERROR_PHONE_UNAVAILABLE) Indicates no phone is connected, or the phone that is connected doesn't support 3p OAuth                                                                                                                                                                                                    |
| `int`                                                                  | [ERROR_UNSUPPORTED](https://developer.android.com/reference/android/support/wearable/authentication/OAuthClient.html#ERROR_UNSUPPORTED) Indicates 3p OAuth isn't supported by Wear OS                                                                                                                                                                                                                                                           |
| [String](http://developer.android.com/reference/java/lang/String.html) | [LEGACY_WEAR_REDIRECT_URL_PREFIX](https://developer.android.com/reference/android/support/wearable/authentication/OAuthClient.html#LEGACY_WEAR_REDIRECT_URL_PREFIX) *This constant is deprecated. Prefer[WEAR_REDIRECT_URL_PREFIX](https://developer.android.com/reference/android/support/wearable/authentication/OAuthClient.html#WEAR_REDIRECT_URL_PREFIX)which is hosted on the Google API domain. This URL will be removed in the future.* |
| [String](http://developer.android.com/reference/java/lang/String.html) | [WEAR_REDIRECT_URL_PREFIX](https://developer.android.com/reference/android/support/wearable/authentication/OAuthClient.html#WEAR_REDIRECT_URL_PREFIX) Browsers will redirect URLs prefixed with this constant to the Wear OS phone app using App Links.                                                                                                                                                                                         |

|                                                                                                                                                                                                                                                                                                         ### Public methods                                                                                                                                                                                                                                                                                                          ||
|---------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` static `[OAuthClient](https://developer.android.com/reference/android/support/wearable/authentication/OAuthClient.html) | ` `[create](https://developer.android.com/reference/android/support/wearable/authentication/OAuthClient.html#create(android.content.Context))`(`[Context](http://developer.android.com/reference/android/content/Context.html)` context) ` Returns a client that can be used to make OAuth authorization requests.                                                                                                                                                                                       |
| ` void`                                                                                                                   | ` `[destroy](https://developer.android.com/reference/android/support/wearable/authentication/OAuthClient.html#destroy())`() ` Frees any resources used by the client, dropping any outstanding requests.                                                                                                                                                                                                                                                                                                 |
| ` void`                                                                                                                   | ` `[sendAuthorizationRequest](https://developer.android.com/reference/android/support/wearable/authentication/OAuthClient.html#sendAuthorizationRequest(android.net.Uri,%20android.support.wearable.authentication.OAuthClient.Callback))`(`[Uri](http://developer.android.com/reference/android/net/Uri.html)` requestUrl, `[OAuthClient.Callback](https://developer.android.com/reference/android/support/wearable/authentication/OAuthClient.Callback.html)` clientCallback) ` Send an OAuth request. |

|                                                          ### Protected methods                                                           ||
|---------|---------------------------------------------------------------------------------------------------------------------------------|
| ` void` | ` `[finalize](https://developer.android.com/reference/android/support/wearable/authentication/OAuthClient.html#finalize())`() ` |

| ### Inherited methods |
|-----------------------|---|
| From class` `[java.lang.Object](http://developer.android.com/reference/java/lang/Object.html)` ` |------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------| | ` `[Object](http://developer.android.com/reference/java/lang/Object.html)          | ` clone() `                                                                               | | ` boolean`                                                                         | ` equals(`[Object](http://developer.android.com/reference/java/lang/Object.html)` arg0) ` | | ` void`                                                                            | ` finalize() `                                                                            | | ` final `[Class](http://developer.android.com/reference/java/lang/Class.html)`<?>` | ` getClass() `                                                                            | | ` int`                                                                             | ` hashCode() `                                                                            | | ` final void`                                                                      | ` notify() `                                                                              | | ` final void`                                                                      | ` notifyAll() `                                                                           | | ` `[String](http://developer.android.com/reference/java/lang/String.html)          | ` toString() `                                                                            | | ` final void`                                                                      | ` wait(long arg0, int arg1) `                                                             | | ` final void`                                                                      | ` wait(long arg0) `                                                                       | | ` final void`                                                                      | ` wait() `                                                                                | ||

## Constants

### ERROR_PHONE_UNAVAILABLE

```
public static final int ERROR_PHONE_UNAVAILABLE
```

Indicates no phone is connected, or the phone that is connected doesn't support 3p OAuth

<br />

Constant Value: 1 (0x00000001)  

### ERROR_UNSUPPORTED

```
public static final int ERROR_UNSUPPORTED
```

Indicates 3p OAuth isn't supported by Wear OS

<br />

Constant Value: 0 (0x00000000)  

### LEGACY_WEAR_REDIRECT_URL_PREFIX

```
public static final String LEGACY_WEAR_REDIRECT_URL_PREFIX
```

<br />

**This constant is deprecated.**   
Prefer[WEAR_REDIRECT_URL_PREFIX](https://developer.android.com/reference/android/support/wearable/authentication/OAuthClient.html#WEAR_REDIRECT_URL_PREFIX)which is hosted on the Google API domain. This URL will be removed in the future.

Browsers will redirect URLs prefixed with this constant to the Wear OS phone app using App Links. To deliver an OAuth response to your Wear app, set the redirect_uri parameter on the OAuth request to this constant, with your app's package name appended.

For example, if your app's package name is com.package.name, you should set the redirect_uri to LEGACY_WEAR_REDIRECT_URL_PREFIX + "com.package.name".

<br />

Constant Value: "https://www.android.com/wear/3p_auth/"  

### WEAR_REDIRECT_URL_PREFIX

```
public static final String WEAR_REDIRECT_URL_PREFIX
```

Browsers will redirect URLs prefixed with this constant to the Wear OS phone app using App Links. To deliver an OAuth response to your Wear app, set the redirect_uri parameter on the OAuth request to this constant, with your app's package name appended.

For example, if your app's package name is com.package.name, you should set the redirect_uri to WEAR_REDIRECT_URL_PREFIX + "com.package.name".

<br />

Constant Value: "https://wear.googleapis.com/3p_auth/"

## Public methods

### create

```
public static OAuthClient create (Context context)
```

Returns a client that can be used to make OAuth authorization requests.

<br />

|         Parameters          ||
|-----------|------------------|
| `context` | `Context` <br /> |

|                                                         Returns                                                         ||
|-----------------------------------------------------------------------------------------------------------------|--------|
| [OAuthClient](https://developer.android.com/reference/android/support/wearable/authentication/OAuthClient.html) | <br /> |

### destroy

```
public void destroy ()
```

Frees any resources used by the client, dropping any outstanding requests. The client cannot be used to make requests thereafter.

<br />

### sendAuthorizationRequest

```
public void sendAuthorizationRequest (Uri requestUrl, 
                OAuthClient.Callback clientCallback)
```

Send an OAuth request. This will cause an authorization UI to be presented on the user's phone. This request is asynchronous; the callback provided will be be notified when the request completes.

<br />

|                                                                                                                                             Parameters                                                                                                                                             ||
|------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `requestUrl`     | `Uri`: URL that will be opened in browser on phone. The OAuth response should redirect to the Wear OS companion. See[WEAR_REDIRECT_URL_PREFIX](https://developer.android.com/reference/android/support/wearable/authentication/OAuthClient.html#WEAR_REDIRECT_URL_PREFIX) <br /> |
| `clientCallback` | `OAuthClient.Callback` <br />                                                                                                                                                                                                                                                    |

## Protected methods

### finalize

```
protected void finalize ()
```

<br />

<br />

|                                     Throws                                      ||
|------------------------------------------------------------------------------|---|
| [Throwable](http://developer.android.com/reference/java/lang/Throwable.html) |   |