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

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.AuthorizationCodeRequestUrl
                      extended by com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeRequestUrl
All Implemented Interfaces:
Cloneable, Map<String,Object>

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

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

Since:
1.7
Author:
Yaniv Inbar

Nested Class Summary
 
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
GoogleAuthorizationCodeRequestUrl(GoogleClientSecrets clientSecrets, String redirectUri, Iterable<String> scopes)
           
GoogleAuthorizationCodeRequestUrl(String clientId, String redirectUri, Iterable<String> scopes)
           
 
Method Summary
 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 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".
 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".
 GoogleAuthorizationCodeRequestUrl setClientId(String clientId)
           
 GoogleAuthorizationCodeRequestUrl setRedirectUri(String redirectUri)
           
 GoogleAuthorizationCodeRequestUrl setResponseTypes(Iterable<String> responseTypes)
           
 GoogleAuthorizationCodeRequestUrl setResponseTypes(String... responseTypes)
           
 GoogleAuthorizationCodeRequestUrl setScopes(Iterable<String> scopes)
           
 GoogleAuthorizationCodeRequestUrl setScopes(String... scopes)
           
 GoogleAuthorizationCodeRequestUrl 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, 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, 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

GoogleAuthorizationCodeRequestUrl

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

GoogleAuthorizationCodeRequestUrl

public GoogleAuthorizationCodeRequestUrl(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 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.


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


setAccessType

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.


setResponseTypes

public GoogleAuthorizationCodeRequestUrl setResponseTypes(String... responseTypes)
Overrides:
setResponseTypes in class AuthorizationCodeRequestUrl

setResponseTypes

public GoogleAuthorizationCodeRequestUrl setResponseTypes(Iterable<String> responseTypes)
Overrides:
setResponseTypes in class AuthorizationCodeRequestUrl

setRedirectUri

public GoogleAuthorizationCodeRequestUrl setRedirectUri(String redirectUri)
Overrides:
setRedirectUri in class AuthorizationCodeRequestUrl

setScopes

public GoogleAuthorizationCodeRequestUrl setScopes(String... scopes)
Overrides:
setScopes in class AuthorizationCodeRequestUrl

setScopes

public GoogleAuthorizationCodeRequestUrl setScopes(Iterable<String> scopes)
Overrides:
setScopes in class AuthorizationCodeRequestUrl

setClientId

public GoogleAuthorizationCodeRequestUrl setClientId(String clientId)
Overrides:
setClientId in class AuthorizationCodeRequestUrl

setState

public GoogleAuthorizationCodeRequestUrl setState(String state)
Overrides:
setState in class AuthorizationCodeRequestUrl


Copyright © 2010-2012 Google. All Rights Reserved.