org.restlet.ext.oauth
Class AccessTokenServerResource

java.lang.Object
  extended by org.restlet.resource.Resource
      extended by org.restlet.resource.ServerResource
          extended by org.restlet.ext.oauth.OAuthServerResource
              extended by org.restlet.ext.oauth.AccessTokenServerResource
All Implemented Interfaces:
OAuthResourceDefs

public class AccessTokenServerResource
extends OAuthServerResource

Server resource used to acquire an OAuth token. A code, or refresh token can be exchanged for a working token. Implements OAuth 2.0 (RFC6749) Example. Attach an AccessTokenServerResource

 {
      @code
      public Restlet createInboundRoot(){
              ...
              root.attach("/token", AccessTokenServerResource.class);
              ...
      }
 }
 

Author:
Shotaro Uchida , Kristoffer Gronowski
See Also:
OAuth 2.0 (3.2. Token Endpoint)

Field Summary
 
Fields inherited from class org.restlet.ext.oauth.OAuthServerResource
clients, PARAMETER_DEFAULT_SCOPE, tokens
 
Fields inherited from interface org.restlet.ext.oauth.OAuthResourceDefs
ACCESS_TOKEN, CLIENT_ID, CLIENT_SECRET, CODE, ERROR, ERROR_DESC, ERROR_URI, EXPIRES_IN, GRANT_TYPE, PASSWORD, REDIR_URI, REFRESH_TOKEN, RESPONSE_TYPE, SCOPE, STATE, TOKEN_TYPE, TOKEN_TYPE_BEARER, TOKEN_TYPE_MAC, USERNAME
 
Constructor Summary
AccessTokenServerResource()
           
 
Method Summary
protected  void doCatch(Throwable t)
          Handle errors as described in 5.2 Error Response.
protected  void ensureGrantTypeAllowed(org.restlet.ext.oauth.internal.Client client, GrantType grantType)
           
protected  org.restlet.ext.oauth.internal.Client getAuthenticatedClient()
           
protected  org.restlet.ext.oauth.internal.Client getClient(Form params)
          Get request parameter "client_id".
protected  String getCode(Form params)
          Get request parameter "code".
protected  GrantType getGrantType(Form params)
          Get request parameter "grant_type".
protected  String getPassword(Form params)
          Get request parameter "password".
protected  String getRedirectURI(Form params)
          Get request parameter "redirect_uri".
protected  String getRefreshToken(Form params)
          Get request parameter "refresh_token".
protected  String getUsername(Form params)
          Get request parameter "username".
 Representation requestToken(Representation input)
          Handles the Post request.
protected  Representation responseTokenRepresentation(org.restlet.ext.oauth.internal.Token token, String[] requestedScope)
          Response JSON document with valid token.
 
Methods inherited from class org.restlet.ext.oauth.OAuthServerResource
addCacheDirective, doInit, getScope, getState, responseErrorRepresentation
 
Methods inherited from class org.restlet.resource.ServerResource
abort, commit, delete, delete, describeVariants, doConditionalHandle, doError, doHandle, doHandle, doNegotiatedHandle, get, get, getAttribute, getInfo, getInfo, getOnSent, getPreferredVariant, getRole, getVariants, getVariants, handle, hasAnnotations, head, head, isAnnotated, isAutoCommitting, isCommitted, isConditional, isExisting, isInRole, isNegotiated, options, options, patch, patch, post, post, put, put, redirectPermanent, redirectPermanent, redirectSeeOther, redirectSeeOther, redirectTemporary, redirectTemporary, setAllowedMethods, setAnnotated, setAttribute, setAutoCommitting, setChallengeRequests, setCommitted, setConditional, setCookieSettings, setDimensions, setExisting, setLocationRef, setLocationRef, setNegotiated, setOnSent, setProxyChallengeRequests, setServerInfo, setStatus, setStatus, setStatus, setStatus, updateAllowedMethods, updateDimensions
 
Methods inherited from class org.restlet.resource.Resource
doError, doRelease, getAllowedMethods, getApplication, getChallengeRequests, getChallengeResponse, getClientInfo, getConditions, getConnegService, getContext, getConverterService, getCookies, getCookieSettings, getDimensions, getHostRef, getLocationRef, getLogger, getMatrix, getMatrixValue, getMaxForwards, getMetadataService, getMethod, getOriginalRef, getProtocol, getProxyChallengeRequests, getProxyChallengeResponse, getQuery, getQueryValue, getRanges, getReference, getReferrerRef, getRequest, getRequestAttributes, getRequestCacheDirectives, getRequestEntity, getResponse, getResponseAttributes, getResponseCacheDirectives, getResponseEntity, getRootRef, getServerInfo, getStatus, getStatusService, init, isConfidential, isLoggable, release, setApplication, setQueryValue, setRequest, setResponse, toObject, toRepresentation, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AccessTokenServerResource

public AccessTokenServerResource()
Method Detail

getAuthenticatedClient

protected org.restlet.ext.oauth.internal.Client getAuthenticatedClient()
                                                                throws OAuthException
Throws:
OAuthException

getClient

protected org.restlet.ext.oauth.internal.Client getClient(Form params)
                                                   throws OAuthException
Description copied from class: OAuthServerResource
Get request parameter "client_id".

Overrides:
getClient in class OAuthServerResource
Returns:
Throws:
OAuthException

ensureGrantTypeAllowed

protected void ensureGrantTypeAllowed(org.restlet.ext.oauth.internal.Client client,
                                      GrantType grantType)
                               throws OAuthException
Throws:
OAuthException

requestToken

@Post(value="form:json")
public Representation requestToken(Representation input)
                            throws OAuthException,
                                   JSONException
Handles the Post request. The client MUST use the HTTP "POST" method when making access token requests. (3.2. Token Endpoint)

Parameters:
input - HTML form formated token request per oauth-v2 spec.
Returns:
JSON response with token or error.
Throws:
OAuthException
JSONException

doCatch

protected void doCatch(Throwable t)
Handle errors as described in 5.2 Error Response.

Overrides:
doCatch in class ServerResource
Parameters:
t -

getGrantType

protected GrantType getGrantType(Form params)
                          throws OAuthException
Get request parameter "grant_type".

Parameters:
params -
Returns:
Throws:
OAuthException

getCode

protected String getCode(Form params)
                  throws OAuthException
Get request parameter "code".

Parameters:
params -
Returns:
Throws:
OAuthException

getRedirectURI

protected String getRedirectURI(Form params)
                         throws OAuthException
Get request parameter "redirect_uri".

Parameters:
params -
Returns:
Throws:
OAuthException

getUsername

protected String getUsername(Form params)
                      throws OAuthException
Get request parameter "username".

Parameters:
params -
Returns:
Throws:
OAuthException

getPassword

protected String getPassword(Form params)
                      throws OAuthException
Get request parameter "password".

Parameters:
params -
Returns:
Throws:
OAuthException

getRefreshToken

protected String getRefreshToken(Form params)
                          throws OAuthException
Get request parameter "refresh_token".

Parameters:
params -
Returns:
Throws:
OAuthException

responseTokenRepresentation

protected Representation responseTokenRepresentation(org.restlet.ext.oauth.internal.Token token,
                                                     String[] requestedScope)
                                              throws JSONException
Response JSON document with valid token. The format of the JSON document is according to 5.1. Successful Response.

Parameters:
token - The token generated by the client.
requestedScope - The scope originally requested by the client.
Returns:
The token representation as described in RFC6749 5.1.
Throws:
ResourceException
JSONException


Copyright © 2005-2014 Restlet.