# OAuthRequest.Builder

Artifact: [androidx.wear:wear-phone-interactions](https://developer.android.com/jetpack/androidx/releases/wear) [View Source](https://cs.android.com/search?q=file:androidx/wear/phone/interactions/authentication/OAuthRequest.kt+class:androidx.wear.phone.interactions.authentication.OAuthRequest.Builder) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear#1.0.0)

*** ** * ** ***


```
public final class OAuthRequest.Builder
```

<br />

*** ** * ** ***

Builder for constructing new instance of OAuth request.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/wear/phone/interactions/authentication/OAuthRequest.Builder#Builder(android.content.Context)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/Context.html context)` |

| ### Public methods |
|---|---|
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/phone/interactions/authentication/OAuthRequest` | `@https://developer.android.com/reference/androidx/annotation/RequiresApi(value = 26) https://developer.android.com/reference/androidx/wear/phone/interactions/authentication/OAuthRequest.Builder#build()()` Build the request instance specified by this builder |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/phone/interactions/authentication/OAuthRequest.Builder` | `https://developer.android.com/reference/androidx/wear/phone/interactions/authentication/OAuthRequest.Builder#setAuthProviderUrl(android.net.Uri)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/net/Uri.html authProviderUrl)` Set the url of the auth provider site. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/phone/interactions/authentication/OAuthRequest.Builder` | `https://developer.android.com/reference/androidx/wear/phone/interactions/authentication/OAuthRequest.Builder#setClientId(kotlin.String)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html clientId)` Set the client id of this OAuth request. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/phone/interactions/authentication/OAuthRequest.Builder` | `https://developer.android.com/reference/androidx/wear/phone/interactions/authentication/OAuthRequest.Builder#setCodeChallenge(androidx.wear.phone.interactions.authentication.CodeChallenge)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/phone/interactions/authentication/CodeChallenge codeChallenge)` Set the code challenge for authentication with PKCE (proof key for code exchange). |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/phone/interactions/authentication/OAuthRequest.Builder` | `https://developer.android.com/reference/androidx/wear/phone/interactions/authentication/OAuthRequest.Builder#setRedirectUrl(android.net.Uri)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/net/Uri.html redirectUrl)` Set the redirect url the companion app registered to, so that the response will be routed from the auth server back to the companion. |

## Public constructors

### Builder

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear#1.0.0)

```
public Builder(@NonNull Context context)
```

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/Context.html context` | The Context of the app sending the auth request. |

## Public methods

### build

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear#1.0.0)

```
@RequiresApi(value = 26)
public final @NonNull OAuthRequest build()
```

Build the request instance specified by this builder

### setAuthProviderUrl

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear#1.0.0)

```
public final @NonNull OAuthRequest.Builder setAuthProviderUrl(@NonNull Uri authProviderUrl)
```

Set the url of the auth provider site. Appending query parameters in this uri is optional, it is recommended to let the builder append query parameters automatically through the use of setters (no setter is required for the builder to append the redirect_uri).

### setClientId

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear#1.0.0)

```
public final @NonNull OAuthRequest.Builder setClientId(@NonNull String clientId)
```

Set the client id of this OAuth request. With this setter called. the builder appends the "client_id" to the requestUrl.

### setCodeChallenge

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear#1.0.0)

```
public final @NonNull OAuthRequest.Builder setCodeChallenge(@NonNull CodeChallenge codeChallenge)
```

Set the code challenge for authentication with PKCE (proof key for code exchange). With this setter called, the builder appends the "code_challenge", "code_challenge_method" and "response_type" queries to the requestUrl.

### setRedirectUrl

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear#1.0.0)

```
public final @NonNull OAuthRequest.Builder setRedirectUrl(@NonNull Uri redirectUrl)
```

Set the redirect url the companion app registered to, so that the response will be routed from the auth server back to the companion.

Calling this method is optional. If the redirect URL is not specified, it will be automatically set to `https://developer.android.com/reference/androidx/wear/phone/interactions/authentication/OAuthRequest#WEAR_REDIRECT_URL_PREFIX()` or `https://developer.android.com/reference/androidx/wear/phone/interactions/authentication/OAuthRequest#WEAR_REDIRECT_URL_PREFIX_CN()` for rest of the world or China, respectively.

Note, the app package name should NOT be included here, it will be appended to the end of redirect_uri automatically in `https://developer.android.com/reference/androidx/wear/phone/interactions/authentication/OAuthRequest.Builder#build()`.