Class GoogleAuthorizationCodeRequestUrl (1.35.2)

public class GoogleAuthorizationCodeRequestUrl extends AuthorizationCodeRequestUrl

Google-specific implementation of the OAuth 2.0 URL builder for an authorization web page to allow the end user to authorize the application to access their protected resources and that returns an authorization code, as specified in Using OAuth 2.0 for Web Server Applications.

The default for #getResponseTypes() is "code". Use AuthorizationCodeResponseUrl to parse the redirect response after the end user grants/denies the request. Using the authorization code in this response, use GoogleAuthorizationCodeTokenRequest to request the access token.

Sample usage for a web application:


 public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
      String url = new GoogleAuthorizationCodeRequestUrl(
           "812741506391.apps.googleusercontent.com",
           "https://oauth2-login-demo.appspot.com/code",
           Arrays.asList("https://www.googleapis.com/auth/userinfo.email",
                   "https://www.googleapis.com/auth/userinfo.profile"))
           .setState("/profile").build();
      response.sendRedirect(url);
 }
 

Implementation is not thread-safe.

Inheritance

Object > java.util.AbstractMap > com.google.api.client.util.GenericData > com.google.api.client.http.GenericUrl > com.google.api.client.auth.oauth2.AuthorizationRequestUrl > com.google.api.client.auth.oauth2.AuthorizationCodeRequestUrl > GoogleAuthorizationCodeRequestUrl

Constructors

GoogleAuthorizationCodeRequestUrl(GoogleClientSecrets clientSecrets, String redirectUri, Collection<String> scopes)

public GoogleAuthorizationCodeRequestUrl(GoogleClientSecrets clientSecrets, String redirectUri, Collection<String> scopes)
Parameters
NameDescription
clientSecretsGoogleClientSecrets

OAuth 2.0 client secrets JSON model as specified in client_secrets.json file format

redirectUriString

URI that the authorization server directs the resource owner's user-agent back to the client after a successful authorization grant

scopesCollection<String>

scopes (see #setScopes(Collection))

GoogleAuthorizationCodeRequestUrl(String authorizationServerEncodedUrl, String clientId, String redirectUri, Collection<String> scopes)

public GoogleAuthorizationCodeRequestUrl(String authorizationServerEncodedUrl, String clientId, String redirectUri, Collection<String> scopes)
Parameters
NameDescription
authorizationServerEncodedUrlString

authorization server encoded URL

clientIdString

client identifier

redirectUriString

URI that the authorization server directs the resource owner's user-agent back to the client after a successful authorization grant

scopesCollection<String>

scopes (see #setScopes(Collection))

GoogleAuthorizationCodeRequestUrl(String clientId, String redirectUri, Collection<String> scopes)

public GoogleAuthorizationCodeRequestUrl(String clientId, String redirectUri, Collection<String> scopes)
Parameters
NameDescription
clientIdString

client identifier

redirectUriString

URI that the authorization server directs the resource owner's user-agent back to the client after a successful authorization grant

scopesCollection<String>

scopes (see #setScopes(Collection))

Methods

clone()

public GoogleAuthorizationCodeRequestUrl clone()
Returns
TypeDescription
GoogleAuthorizationCodeRequestUrl
Overrides
com.google.api.client.auth.oauth2.AuthorizationCodeRequestUrl.clone()

getAccessType()

public final 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".

Returns
TypeDescription
String

getApprovalPrompt()

public final 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".

Returns
TypeDescription
String

set(String fieldName, Object value)

public GoogleAuthorizationCodeRequestUrl set(String fieldName, Object value)
Parameters
NameDescription
fieldNameString
valueObject
Returns
TypeDescription
GoogleAuthorizationCodeRequestUrl
Overrides
com.google.api.client.auth.oauth2.AuthorizationCodeRequestUrl.set(java.lang.String,java.lang.Object)

setAccessType(String accessType)

public GoogleAuthorizationCodeRequestUrl setAccessType(String accessType)

Sets the access type ("online" to request online access or "offline" to request offline access) or null for the default behavior of "online".

Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

Parameter
NameDescription
accessTypeString
Returns
TypeDescription
GoogleAuthorizationCodeRequestUrl

setApprovalPrompt(String approvalPrompt)

public GoogleAuthorizationCodeRequestUrl setApprovalPrompt(String approvalPrompt)

Sets 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".

Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

Parameter
NameDescription
approvalPromptString
Returns
TypeDescription
GoogleAuthorizationCodeRequestUrl

setClientId(String clientId)

public GoogleAuthorizationCodeRequestUrl setClientId(String clientId)
Parameter
NameDescription
clientIdString
Returns
TypeDescription
GoogleAuthorizationCodeRequestUrl
Overrides
com.google.api.client.auth.oauth2.AuthorizationCodeRequestUrl.setClientId(java.lang.String)

setRedirectUri(String redirectUri)

public GoogleAuthorizationCodeRequestUrl setRedirectUri(String redirectUri)
Parameter
NameDescription
redirectUriString
Returns
TypeDescription
GoogleAuthorizationCodeRequestUrl
Overrides
com.google.api.client.auth.oauth2.AuthorizationCodeRequestUrl.setRedirectUri(java.lang.String)

setResponseTypes(Collection<String> responseTypes)

public GoogleAuthorizationCodeRequestUrl setResponseTypes(Collection<String> responseTypes)
Parameter
NameDescription
responseTypesCollection<String>
Returns
TypeDescription
GoogleAuthorizationCodeRequestUrl
Overrides
com.google.api.client.auth.oauth2.AuthorizationCodeRequestUrl.setResponseTypes(java.util.Collection<java.lang.String>)

setScopes(Collection<String> scopes)

public GoogleAuthorizationCodeRequestUrl setScopes(Collection<String> scopes)
Parameter
NameDescription
scopesCollection<String>
Returns
TypeDescription
GoogleAuthorizationCodeRequestUrl
Overrides
com.google.api.client.auth.oauth2.AuthorizationCodeRequestUrl.setScopes(java.util.Collection<java.lang.String>)

setState(String state)

public GoogleAuthorizationCodeRequestUrl setState(String state)
Parameter
NameDescription
stateString
Returns
TypeDescription
GoogleAuthorizationCodeRequestUrl
Overrides
com.google.api.client.auth.oauth2.AuthorizationCodeRequestUrl.setState(java.lang.String)