public class GoogleAuthorizationCodeFlow
extends com.google.api.client.auth.oauth2.AuthorizationCodeFlow
This is designed to simplify the flow in which an end-user authorizes the application to access their protected data, and then the application has access to their data based on an access token and a refresh token to refresh that access token when it expires.
The first step is to call AuthorizationCodeFlow.loadCredential(String)
based on the known user ID to check if
the end-user's credentials are already known. If not, call newAuthorizationUrl()
and
direct the end-user's browser to an authorization page. The web browser will then redirect to the
redirect URL with a "code"
query parameter which can then be used to request an access
token using newTokenRequest(String)
. Finally, use
AuthorizationCodeFlow.createAndStoreCredential(TokenResponse, String)
to store and obtain a credential for
accessing protected resources.
The default for the approval_prompt
and access_type
parameters is null
.
For web applications that means "approval_prompt=auto&access_type=online"
and for
installed applications that means "approval_prompt=force&access_type=offline"
. To
override the default, you need to explicitly call GoogleAuthorizationCodeFlow.Builder.setApprovalPrompt(String)
and
GoogleAuthorizationCodeFlow.Builder.setAccessType(String)
.
Modifier and Type | Class and Description |
---|---|
static class |
GoogleAuthorizationCodeFlow.Builder
Google authorization code flow builder.
|
Modifier | Constructor and Description |
---|---|
protected |
GoogleAuthorizationCodeFlow(com.google.api.client.auth.oauth2.Credential.AccessMethod method,
com.google.api.client.http.HttpTransport transport,
com.google.api.client.json.JsonFactory jsonFactory,
com.google.api.client.http.GenericUrl tokenServerUrl,
com.google.api.client.http.HttpExecuteInterceptor clientAuthentication,
String clientId,
String authorizationServerEncodedUrl,
com.google.api.client.auth.oauth2.CredentialStore credentialStore,
com.google.api.client.http.HttpRequestInitializer requestInitializer,
String scopes,
String accessType,
String approvalPrompt)
Deprecated.
(scheduled to be removed in 1.15) Use
GoogleAuthorizationCodeFlow(Builder) |
protected |
GoogleAuthorizationCodeFlow(GoogleAuthorizationCodeFlow.Builder builder) |
|
GoogleAuthorizationCodeFlow(com.google.api.client.http.HttpTransport transport,
com.google.api.client.json.JsonFactory jsonFactory,
String clientId,
String clientSecret,
Iterable<String> scopes) |
Modifier and Type | Method and Description |
---|---|
String |
getAccessType()
Returns the access type (
"online" to request online access or "offline" to
request offline access) or null for the default behavior of "online" . |
String |
getApprovalPrompt()
Returns the approval prompt behavior (
"auto" to request auto-approval or
"force" to force the approval UI to show) or null for the default behavior of
"auto" . |
GoogleAuthorizationCodeRequestUrl |
newAuthorizationUrl() |
GoogleAuthorizationCodeTokenRequest |
newTokenRequest(String authorizationCode) |
createAndStoreCredential, getAuthorizationServerEncodedUrl, getClientAuthentication, getClientId, getClock, getCredentialStore, getJsonFactory, getMethod, getRequestInitializer, getScopes, getTokenServerEncodedUrl, getTransport, loadCredential
public GoogleAuthorizationCodeFlow(com.google.api.client.http.HttpTransport transport, com.google.api.client.json.JsonFactory jsonFactory, String clientId, String clientSecret, Iterable<String> scopes)
transport
- HTTP transportjsonFactory
- JSON factoryclientId
- client identifierclientSecret
- client secretscopes
- list of scopes to be joined by a space separator (or a single value containing
multiple space-separated scopes)protected GoogleAuthorizationCodeFlow(GoogleAuthorizationCodeFlow.Builder builder)
builder
- Google authorization code flow builder@Deprecated protected GoogleAuthorizationCodeFlow(com.google.api.client.auth.oauth2.Credential.AccessMethod method, com.google.api.client.http.HttpTransport transport, com.google.api.client.json.JsonFactory jsonFactory, com.google.api.client.http.GenericUrl tokenServerUrl, com.google.api.client.http.HttpExecuteInterceptor clientAuthentication, String clientId, String authorizationServerEncodedUrl, com.google.api.client.auth.oauth2.CredentialStore credentialStore, com.google.api.client.http.HttpRequestInitializer requestInitializer, String scopes, String accessType, String approvalPrompt)
GoogleAuthorizationCodeFlow(Builder)
method
- method of presenting the access token to the resource server (for example
BearerToken.authorizationHeaderAccessMethod()
)transport
- HTTP transportjsonFactory
- JSON factorytokenServerUrl
- token server URLclientAuthentication
- client authentication or null
for none (see
TokenRequest.setClientAuthentication(HttpExecuteInterceptor)
)clientId
- client identifierauthorizationServerEncodedUrl
- authorization server encoded URLcredentialStore
- credential persistence store or null
for nonerequestInitializer
- HTTP request initializer or null
for nonescopes
- space-separated list of scopes or null
for noneaccessType
- access type ("online"
to request online access or "offline"
to request offline access) or null
for the default behaviorapprovalPrompt
- Prompt for consent behavior ("auto"
to request auto-approval or
"force"
to force the approval UI to show) or null
for the default
behaviorpublic GoogleAuthorizationCodeTokenRequest newTokenRequest(String authorizationCode)
newTokenRequest
in class com.google.api.client.auth.oauth2.AuthorizationCodeFlow
public GoogleAuthorizationCodeRequestUrl newAuthorizationUrl()
newAuthorizationUrl
in class com.google.api.client.auth.oauth2.AuthorizationCodeFlow
public final String getApprovalPrompt()
"auto"
to request auto-approval or
"force"
to force the approval UI to show) or null
for the default behavior of
"auto"
.public final String getAccessType()
"online"
to request online access or "offline"
to
request offline access) or null
for the default behavior of "online"
.Copyright © 2010-2013 Google. All Rights Reserved.