Class OauthToken

java.lang.Object
org.refcodes.web.OauthToken
All Implemented Interfaces:
org.refcodes.mixin.Disposable, org.refcodes.mixin.ValidAccessor

public class OauthToken extends Object implements org.refcodes.mixin.ValidAccessor, org.refcodes.mixin.Disposable
An OAuth-Token contains all relevant information to access a protected resource and refresh the the access token. "If the request for an access token is valid, the authorization server needs to generate an access token (and optional refresh token) and return these to the client, typically along with some additional properties about the authorization." HTTP/1.1 200 OK Content-Type: application/json Cache-Control: no-store Pragma: no-cache { "access_token":"MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3", "token_type":"bearer", "expires_in":3600, "refresh_token":"IwOGYzYTlmM2YxOTQ5MGE3YmNmMDFkNTVk", "scope":"create" } See "https://www.oauth.com/oauth2-servers/access-tokens/access-token-response"
  • Field Details

    • _accessToken

      protected String _accessToken
    • _refreshToken

      protected String _refreshToken
    • _tokenType

      protected String _tokenType
    • _expiresIn

      protected Integer _expiresIn
    • _refreshExpiresIn

      protected Integer _refreshExpiresIn
    • _scope

      protected String _scope
    • _notBeforePolicy

      protected String _notBeforePolicy
    • _sessionState

      protected String _sessionState
    • _grantType

      protected GrantType _grantType
    • _isDisposed

      protected boolean _isDisposed
  • Constructor Details

    • OauthToken

      public OauthToken(OauthToken aOauthToken)
      Creates a new instance of the OauthToken with the current time being stored for determining validity of the access token via isValid() as of getExpiresIn().
      Parameters:
      aOauthToken - The OAuth data to use.
    • OauthToken

      public OauthToken(String aAccessToken, String aRefreshToken, String aTokenType, Integer aExpiresIn, String aScope)
      Creates a new instance of the OauthToken with the current time being stored for determining validity of the access token via isValid() as of getExpiresIn().
      Parameters:
      aAccessToken - The access token
      aRefreshToken - The refresh token
      aTokenType - The token type
      aExpiresIn - The expires-time in seconds
      aScope - The scope
    • OauthToken

      public OauthToken(String aAccessToken, String aRefreshToken, String aTokenType, String aNotBeforePolicy, Integer aExpiresIn, Integer aRefreshExpiresIn, String aScope, String aSessionState)
      Creates a new instance of the OauthToken with the current time being stored for determining validity of the access token via isValid() as of getExpiresIn().
      Parameters:
      aAccessToken - The access token
      aRefreshToken - The refresh token
      aTokenType - The token type
      aNotBeforePolicy - The not-before-policy.
      aExpiresIn - The expires-time in seconds
      aRefreshExpiresIn - The refresh's expires-time in seconds
      aScope - The scope
      aSessionState - The session state.
    • OauthToken

      public OauthToken(String aAccessToken, String aRefreshToken, String aTokenType, GrantType aGrantType, String aNotBeforePolicy, Integer aExpiresIn, Integer aRefreshExpiresIn, String aScope, String aSessionState)
      Creates a new instance of the OauthToken with the current time being stored for determining validity of the access token via isValid() as of getExpiresIn().
      Parameters:
      aAccessToken - The access token
      aRefreshToken - The refresh token
      aTokenType - The token type
      aGrantType - The GrantType used for this tolen.
      aNotBeforePolicy - The not-before-policy.
      aExpiresIn - The expires-time in seconds
      aRefreshExpiresIn - The refresh's expires-time in seconds
      aScope - The scope
      aSessionState - The session state.
    • OauthToken

      public OauthToken(HttpBodyMap aOauthToken)
      Creates a new instance of the OauthToken with the current time being stored for determining validity of the access token via isValid() as of getExpiresIn().
      Parameters:
      aOauthToken - The HttpBodyMap containing the OauthToken data.
  • Method Details

    • dispose

      public void dispose()
      Specified by:
      dispose in interface org.refcodes.mixin.Disposable
    • getAccessToken

      public String getAccessToken()
      Returns the access token. "The access token string as issued by the authorization server." See "https://www.oauth.com/oauth2-servers/access-tokens/access-token-response"
      Returns:
      the access token.
    • getRefreshToken

      public String getRefreshToken()
      Returns the refresh token. "The access token string as issued by the authorization server." See "https://www.oauth.com/oauth2-servers/access-tokens/access-token-response"
      Returns:
      the refresh token.
    • getScope

      public String getScope()
      Returns the OAuth scope. "If the scope the user granted is identical to the scope the app requested, this parameter is optional. If the granted scope is different from the requested scope, such as if the user modified the scope, then this parameter is required." See "https://www.oauth.com/oauth2-servers/access-tokens/access-token-response"
      Returns:
      the OAuth scope.
    • getTokenType

      public String getTokenType()
      Returns the token type. "The type of token this is, typically just the string bearer" See "https://www.oauth.com/oauth2-servers/access-tokens/access-token-response"
      Returns:
      the token type.
    • getGrantType

      public GrantType getGrantType()
      Returns the GrantType used by this token.
      Returns:
      the according GrantType.
    • getExpiresIn

      public Integer getExpiresIn()
      Returns the time in seconds till the access token (getAccessToken()) expires. "If the access token expires, the server should reply with the duration of time the access token is granted for." See "https://www.oauth.com/oauth2-servers/access-tokens/access-token-response"
      Returns:
      the Expires-In time in seconds
    • getNotBeforePolicy

      public String getNotBeforePolicy()
      Returns the not-before-policy.
      Returns:
      the not-before-policy.
    • getSessionState

      public String getSessionState()
      Returns the session state.
      Returns:
      the session state.
    • getRefreshExpiresIn

      public Integer getRefreshExpiresIn()
      Returns the time in seconds till the refresh token (getRefreshToken()) expires.
      Returns:
      the Expires-In time in seconds
    • isValid

      public boolean isValid()
      Specified by:
      isValid in interface org.refcodes.mixin.ValidAccessor
    • fromHttpBodyMap

      protected void fromHttpBodyMap(HttpBodyMap aOauthToken)
      Sets the internal fields with the data from the HttpBodyMap as of the OauthField definitions.
      Parameters:
      aOauthToken - The HttpBodyMap from which to gather the data.