# Package com.google.api.client.auth.oauth (1.39.0)

<button class="button button-with-icon cloud-select-dropdown__button " aria-haspopup="true">Version latest</button>

- [1.39.0 (latest)](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.oauth)
- [1.38.2](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/1.38.2/com.google.api.client.auth.oauth)
- [1.37.0](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/1.37.0/com.google.api.client.auth.oauth)
- [1.36.0](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/1.36.0/com.google.api.client.auth.oauth)
- [1.34.1](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/1.34.1/com.google.api.client.auth.oauth)
- [1.33.3](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/1.33.3/com.google.api.client.auth.oauth)
- [1.32.1](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/1.32.1/com.google.api.client.auth.oauth)
[com.google.api.client.util.Beta](https://cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.util.Beta.html)   

OAuth 1.0 authorization as specified in [RFC 5849:
The OAuth 1.0 Protocol](http://tools.ietf.org/html/rfc5849) (see detailed package specification).

There are a few features not supported by this implementation:

- `PLAINTEXT` signature algorithm
- `"application/x-www-form-urlencoded"` HTTP request body
- `"oauth_*"` parameters specified in the HTTP request URL (instead assumes they are specified in the `Authorization` header)

Before using this library, you may need to set up your application as follows:

1. For web applications, you may need to first register your application with the authorization server. It may provide two pieces of information you need:
   - OAuth Consumer Key: use this as the `consumerKey` on every OAuth request, for example in com.google.api.client.auth.oauth.AbstractOAuthGetToken#consumerKey.
   - OAuth Consumer Secret: use this as the com.google.api.client.auth.oauth.OAuthHmacSigner#clientSharedSecret when using the `"HMAC-SHA1"` signature method.
2. For an installed application, an unregistered web application, or a web application running on localhost, you must use the `"HMAC-SHA1"` signature method. The documentation for the authorization server will need to provide you with the `consumerKey` and `
   clientSharedSecret` to use.
3. For the `"HMAC-SHA1"` signature method, use [com.google.api.client.auth.oauth.OAuthHmacSigner](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.oauth.OAuthHmacSigner).
4. For the `"RSA-SHA1"` signature method, use [com.google.api.client.auth.oauth.OAuthRsaSigner](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.oauth.OAuthRsaSigner).

After the set up has been completed, the typical application flow is:

1. Request a temporary credentials token from the Authorization server using [com.google.api.client.auth.oauth.OAuthGetTemporaryToken](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.oauth.OAuthGetTemporaryToken). A callback URL should be specified for web applications, but does not need to be specified for installed applications.
2. Direct the end user to an authorization web page to allow the end user to authorize the temporary token using using [com.google.api.client.auth.oauth.OAuthAuthorizeTemporaryTokenUrl](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.oauth.OAuthAuthorizeTemporaryTokenUrl).
3. After the user has granted the authorization:
   - For web applications, the user's browser will be redirected to the callback URL which may be parsed using [com.google.api.client.auth.oauth.OAuthCallbackUrl](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.oauth.OAuthCallbackUrl).
   - For installed applications, see the authorization server's documentation for figuring out the verification code.
4. Request to exchange the temporary token for a long-lived access token from the Authorization server using [com.google.api.client.auth.oauth.OAuthGetAccessToken](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.oauth.OAuthGetAccessToken). This access token must be stored.
5. Use the stored access token to authorize HTTP requests to protected resources by setting the com.google.api.client.auth.oauth.OAuthParameters#token and using [com.google.api.client.auth.oauth.OAuthParameters](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.oauth.OAuthParameters) as the com.google.api.client.http.HttpRequestInitializer.

## Classes

### [AbstractOAuthGetToken](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.oauth.AbstractOAuthGetToken)

Beta   

Generic OAuth 1.0a URL to request a temporary or long-lived token from an authorization server.

### [OAuthAuthorizeTemporaryTokenUrl](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.oauth.OAuthAuthorizeTemporaryTokenUrl)

Beta   

OAuth 1.0a URL builder for an authorization web page to allow the end user to authorize the
temporary token.

The [#temporaryToken](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.oauth.OAuthAuthorizeTemporaryTokenUrl#com_google_api_client_auth_oauth_OAuthAuthorizeTemporaryTokenUrl_temporaryToken) should be set from the [OAuthCredentialsResponse#token](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.oauth.OAuthCredentialsResponse#com_google_api_client_auth_oauth_OAuthCredentialsResponse_token)
returned by OAuthGetTemporaryToken#execute(). Use #build() to build the
authorization URL. If a [OAuthGetTemporaryToken#callback](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.oauth.OAuthGetTemporaryToken#com_google_api_client_auth_oauth_OAuthGetTemporaryToken_callback) was specified, after the end user
grants the authorization, the authorization server will redirect to that callback URL. To parse
the response, use [OAuthCallbackUrl](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.oauth.OAuthCallbackUrl).

### [OAuthCallbackUrl](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.oauth.OAuthCallbackUrl)

Beta   

Generic URL that parses the callback URL after a temporary token has been authorized by the end
user.

The [#verifier](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.oauth.OAuthCallbackUrl#com_google_api_client_auth_oauth_OAuthCallbackUrl_verifier) is required in order to exchange the authorized temporary token for a
long-lived access token in [OAuthGetAccessToken#verifier](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.oauth.OAuthGetAccessToken#com_google_api_client_auth_oauth_OAuthGetAccessToken_verifier).

### [OAuthCredentialsResponse](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.oauth.OAuthCredentialsResponse)

Beta   

Data to parse a success response to a request for temporary or token credentials.

### [OAuthGetAccessToken](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.oauth.OAuthGetAccessToken)

Beta   

Generic OAuth 1.0a URL to request to exchange the temporary credentials token (or "request
token") for a long-lived credentials token (or "access token") from an authorization server.

Use #execute() to execute the request. The long-lived access token acquired with this
request is found in [OAuthCredentialsResponse#token](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.oauth.OAuthCredentialsResponse#com_google_api_client_auth_oauth_OAuthCredentialsResponse_token) . This token must be stored. It may
then be used to authorize HTTP requests to protected resources by using [OAuthParameters](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.oauth.OAuthParameters).

### [OAuthGetTemporaryToken](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.oauth.OAuthGetTemporaryToken)

Beta   

Generic OAuth 1.0a URL to request a temporary credentials token (or "request token") from an
authorization server.

Use #execute() to execute the request. The temporary token acquired with this request
is found in [OAuthCredentialsResponse#token](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.oauth.OAuthCredentialsResponse#com_google_api_client_auth_oauth_OAuthCredentialsResponse_token). This temporary token is used in [OAuthAuthorizeTemporaryTokenUrl#temporaryToken](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.oauth.OAuthAuthorizeTemporaryTokenUrl#com_google_api_client_auth_oauth_OAuthAuthorizeTemporaryTokenUrl_temporaryToken) to direct the end user to an authorization page
to allow the end user to authorize the temporary token.

### [OAuthHmacSha256Signer](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.oauth.OAuthHmacSha256Signer)

OAuth `"HMAC-SHA256"` signature method.

### [OAuthHmacSigner](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.oauth.OAuthHmacSigner)

Beta   

OAuth `"HMAC-SHA1"` signature method.

### [OAuthParameters](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.oauth.OAuthParameters)

Beta   

OAuth 1.0a parameter manager.

The only required non-computed fields are [#signer](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.oauth.OAuthParameters#com_google_api_client_auth_oauth_OAuthParameters_signer) and [#consumerKey](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.oauth.OAuthParameters#com_google_api_client_auth_oauth_OAuthParameters_consumerKey). Use [#token](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.oauth.OAuthParameters#com_google_api_client_auth_oauth_OAuthParameters_token) to specify token or temporary credentials.

Sample usage, taking advantage that this class implements HttpRequestInitializer:


     public static HttpRequestFactory createRequestFactory(HttpTransport transport) {
     OAuthParameters parameters = new OAuthParameters();
     // ...
     return transport.createRequestFactory(parameters);
     }
     
If you have a custom request initializer, take a look at the sample usage for HttpExecuteInterceptor, which this class also implements.

### [OAuthRsaSigner](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.oauth.OAuthRsaSigner)

Beta   

OAuth `"RSA-SHA1"` signature method.

The private key may be loaded using the utilities in SecurityUtils.

## Interfaces

### [OAuthSigner](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.oauth.OAuthSigner)

Beta   

OAuth signature method.