com.google.api.client.googleapis.auth.oauth2
Class GoogleBrowserClientRequestUrl

java.lang.Object
  extended by java.util.AbstractMap<String,Object>
      extended by com.google.api.client.util.GenericData
          extended by com.google.api.client.http.GenericUrl
              extended by com.google.api.client.auth.oauth2.AuthorizationRequestUrl
                  extended by com.google.api.client.auth.oauth2.BrowserClientRequestUrl
                      extended by com.google.api.client.googleapis.auth.oauth2.GoogleBrowserClientRequestUrl
All Implemented Interfaces:
Cloneable, Map<String,Object>

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 (Experimental).

The default for AuthorizationRequestUrl.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.

Since:
1.7
Author:
Yaniv Inbar

Nested Class Summary
 
Nested classes/interfaces inherited from class com.google.api.client.util.GenericData
GenericData.Flags
 
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Constructor Summary
GoogleBrowserClientRequestUrl(GoogleClientSecrets clientSecrets, String redirectUri, Iterable<String> scopes)
           
GoogleBrowserClientRequestUrl(String clientId, String redirectUri, Iterable<String> scopes)
           
 
Method Summary
 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".
 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".
 GoogleBrowserClientRequestUrl setClientId(String clientId)
           
 GoogleBrowserClientRequestUrl setRedirectUri(String redirectUri)
           
 GoogleBrowserClientRequestUrl setResponseTypes(Iterable<String> responseTypes)
           
 GoogleBrowserClientRequestUrl setResponseTypes(String... responseTypes)
           
 GoogleBrowserClientRequestUrl setScopes(Iterable<String> scopes)
           
 GoogleBrowserClientRequestUrl setScopes(String... scopes)
           
 GoogleBrowserClientRequestUrl setState(String state)
           
 
Methods inherited from class com.google.api.client.auth.oauth2.AuthorizationRequestUrl
getClientId, getRedirectUri, getResponseTypes, getScopes, getState
 
Methods inherited from class com.google.api.client.http.GenericUrl
appendRawPath, build, buildAuthority, buildRelativeUrl, clone, equals, getAll, getFirst, getFragment, getHost, getPathParts, getPort, getRawPath, getScheme, hashCode, setFragment, setHost, setPathParts, setPort, setRawPath, setScheme, toPathParts, toString
 
Methods inherited from class com.google.api.client.util.GenericData
entrySet, get, getClassInfo, getUnknownKeys, put, putAll, remove, set, setUnknownKeys
 
Methods inherited from class java.util.AbstractMap
clear, containsKey, containsValue, isEmpty, keySet, size, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

GoogleBrowserClientRequestUrl

public GoogleBrowserClientRequestUrl(String clientId,
                                     String redirectUri,
                                     Iterable<String> scopes)
Parameters:
clientId - client identifier
redirectUri - URI that the authorization server directs the resource owner's user-agent back to the client after a successful authorization grant
scopes - scopes (see setScopes(Iterable))

GoogleBrowserClientRequestUrl

public GoogleBrowserClientRequestUrl(GoogleClientSecrets clientSecrets,
                                     String redirectUri,
                                     Iterable<String> scopes)
Parameters:
clientSecrets - OAuth 2.0 client secrets JSON model as specified in client_secrets.json file format
redirectUri - URI that the authorization server directs the resource owner's user-agent back to the client after a successful authorization grant
scopes - scopes (see setScopes(Iterable))
Method Detail

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


setApprovalPrompt

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.


setResponseTypes

public GoogleBrowserClientRequestUrl setResponseTypes(String... responseTypes)
Overrides:
setResponseTypes in class BrowserClientRequestUrl

setResponseTypes

public GoogleBrowserClientRequestUrl setResponseTypes(Iterable<String> responseTypes)
Overrides:
setResponseTypes in class BrowserClientRequestUrl

setRedirectUri

public GoogleBrowserClientRequestUrl setRedirectUri(String redirectUri)
Overrides:
setRedirectUri in class BrowserClientRequestUrl

setScopes

public GoogleBrowserClientRequestUrl setScopes(String... scopes)
Overrides:
setScopes in class BrowserClientRequestUrl

setScopes

public GoogleBrowserClientRequestUrl setScopes(Iterable<String> scopes)
Overrides:
setScopes in class BrowserClientRequestUrl

setClientId

public GoogleBrowserClientRequestUrl setClientId(String clientId)
Overrides:
setClientId in class BrowserClientRequestUrl

setState

public GoogleBrowserClientRequestUrl setState(String state)
Overrides:
setState in class BrowserClientRequestUrl


Copyright © 2010-2012 Google. All Rights Reserved.