com.paypal.base.rest
Class OAuthTokenCredential

java.lang.Object
  extended by com.paypal.base.rest.OAuthTokenCredential
All Implemented Interfaces:
ICredential

public final class OAuthTokenCredential
extends Object
implements ICredential

OAuthTokenCredential is used for generation of OAuth Token used by PayPal REST API service. ClientID and ClientSecret are required by the class to generate OAuth Token, the resulting token is of the form "Bearer xxxxxx". The class has two constructors, one of it taking an additional configuration map used for dynamic configuration. When using the constructor with out configuration map the endpoint is fetched from the configuration that is used during initialization. See PayPalResource for configuring the system. When using a configuration map the class expects an entry by the name "oauth.EndPoint" or "service.EndPoint" to retrieve the value of the endpoint for the OAuth Service. If either are not present the configuration should have a entry by the name "mode" with values sandbox or live wherein the corresponding endpoints are default to PayPal endpoints.

Author:
kjayakumar

Constructor Summary
OAuthTokenCredential(String clientID, String clientSecret)
           
OAuthTokenCredential(String clientID, String clientSecret, Map<String,String> configurationMap)
          Configuration Constructor for dynamic configuration
 
Method Summary
 long expiresIn()
          Specifies how long this token can be used for placing API calls.
 String getAccessToken()
          Computes Access Token by placing a call to OAuth server using ClientID and ClientSecret.
 String getAuthorizationHeader()
          Computes Access Token by doing a Base64 encoding on the ClientID and ClientSecret.
protected  String getRequestPayload()
          Returns the request payload for OAuth Service.
static void setOAUTH_TOKEN_PATH(String oauthTokenPath)
          Sets the URI path for the OAuth Token service.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OAuthTokenCredential

public OAuthTokenCredential(String clientID,
                            String clientSecret)
Parameters:
clientID - Client ID for the OAuth
clientSecret - Client Secret for OAuth

OAuthTokenCredential

public OAuthTokenCredential(String clientID,
                            String clientSecret,
                            Map<String,String> configurationMap)
Configuration Constructor for dynamic configuration

Parameters:
clientID - Client ID for the OAuth
clientSecret - Client Secret for OAuth
configurationMap - Dynamic configuration map which should have an entry for 'oauth.EndPoint' or 'service.EndPoint'. If either are not present then there should be entry for 'mode' with values sandbox/live, wherein PayPals endpoints are used.
Method Detail

setOAUTH_TOKEN_PATH

public static void setOAUTH_TOKEN_PATH(String oauthTokenPath)
Sets the URI path for the OAuth Token service. If not set it defaults to "/v1/oauth2/token"

Parameters:
oauthTokenPath - the URI part to set

getAccessToken

public String getAccessToken()
                      throws PayPalRESTException
Computes Access Token by placing a call to OAuth server using ClientID and ClientSecret. The token is appended to the token type (Bearer).

Returns:
the accessToken
Throws:
PayPalRESTException

getAuthorizationHeader

public String getAuthorizationHeader()
                              throws PayPalRESTException
Computes Access Token by doing a Base64 encoding on the ClientID and ClientSecret. The token is appended to the String "Basic ".

Returns:
the accessToken
Throws:
PayPalRESTException

expiresIn

public long expiresIn()
Specifies how long this token can be used for placing API calls. The remaining lifetime is given in seconds.

Returns:
remaining lifetime of this access token in seconds

getRequestPayload

protected String getRequestPayload()
Returns the request payload for OAuth Service. Override this method to alter the payload

Returns:
Payload as String


Copyright © 2015. All Rights Reserved.