Class GoogleBrowserClientRequestUrl (2.0.0)

public class GoogleBrowserClientRequestUrl extends BrowserClientRequestUrl

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 the access token to a browser client using a scripting language such as JavaScript, as specified in Using OAuth 2.0 for Client-side Applications.

The default for #getResponseTypes() is "token".

Sample usage for a web application:


 public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
   String url = new GoogleBrowserClientRequestUrl("812741506391.apps.googleusercontent.com",
       "https://oauth2-login-demo.appspot.com/oauthcallback", 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.BrowserClientRequestUrl > GoogleBrowserClientRequestUrl

Constructors

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

public GoogleBrowserClientRequestUrl(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))

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

public GoogleBrowserClientRequestUrl(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 GoogleBrowserClientRequestUrl clone()
Returns
TypeDescription
GoogleBrowserClientRequestUrl
Overrides
com.google.api.client.auth.oauth2.BrowserClientRequestUrl.clone()

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 GoogleBrowserClientRequestUrl set(String fieldName, Object value)
Parameters
NameDescription
fieldNameString
valueObject
Returns
TypeDescription
GoogleBrowserClientRequestUrl
Overrides
com.google.api.client.auth.oauth2.BrowserClientRequestUrl.set(java.lang.String,java.lang.Object)

setApprovalPrompt(String approvalPrompt)

public GoogleBrowserClientRequestUrl 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
GoogleBrowserClientRequestUrl

setClientId(String clientId)

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

setRedirectUri(String redirectUri)

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

setResponseTypes(Collection<String> responseTypes)

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

setScopes(Collection<String> scopes)

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

setState(String state)

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