- java.lang.Object
-
- org.refcodes.web.OauthToken
-
- All Implemented Interfaces:
org.refcodes.mixin.Disposable,org.refcodes.mixin.Disposable.Disposedable,org.refcodes.mixin.DisposedAccessor,org.refcodes.mixin.ValidAccessor
public class OauthToken extends Object implements org.refcodes.mixin.ValidAccessor, org.refcodes.mixin.Disposable.Disposedable
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"
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.refcodes.mixin.Disposable
org.refcodes.mixin.Disposable.Disposedable
-
-
Field Summary
Fields Modifier and Type Field Description protected String_accessTokenprotected Integer_expiresInprotected GrantType_grantTypeprotected String_notBeforePolicyprotected Integer_refreshExpiresInprotected String_refreshTokenprotected String_scopeprotected String_sessionStateprotected String_tokenType
-
Constructor Summary
Constructors Constructor Description OauthToken(String aAccessToken, String aRefreshToken, String aTokenType, Integer aExpiresIn, String aScope)Creates a new instance of theOauthTokenwith the current time being stored for determining validity of the access token viaisValid()as ofgetExpiresIn().OauthToken(String aAccessToken, String aRefreshToken, String aTokenType, String aNotBeforePolicy, Integer aExpiresIn, Integer aRefreshExpiresIn, String aScope, String aSessionState)Creates a new instance of theOauthTokenwith the current time being stored for determining validity of the access token viaisValid()as ofgetExpiresIn().OauthToken(String aAccessToken, String aRefreshToken, String aTokenType, GrantType aGrantType, String aNotBeforePolicy, Integer aExpiresIn, Integer aRefreshExpiresIn, String aScope, String aSessionState)Creates a new instance of theOauthTokenwith the current time being stored for determining validity of the access token viaisValid()as ofgetExpiresIn().OauthToken(HttpBodyMap aOauthToken)Creates a new instance of theOauthTokenwith the current time being stored for determining validity of the access token viaisValid()as ofgetExpiresIn().OauthToken(OauthToken aOauthToken)Creates a new instance of theOauthTokenwith the current time being stored for determining validity of the access token viaisValid()as ofgetExpiresIn().
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddispose()protected voidfromHttpBodyMap(HttpBodyMap aOauthToken)Sets the internal fields with the data from theHttpBodyMapas of theOauthFielddefinitions.StringgetAccessToken()Returns the access token.IntegergetExpiresIn()Returns the time in seconds till the access token (getAccessToken()) expires.GrantTypegetGrantType()Returns theGrantTypeused by this token.StringgetNotBeforePolicy()Returns the not-before-policy.IntegergetRefreshExpiresIn()Returns the time in seconds till the refresh token (getRefreshToken()) expires.StringgetRefreshToken()Returns the refresh token.StringgetScope()Returns the OAuth scope.StringgetSessionState()Returns the session state.StringgetTokenType()Returns the token type.booleanisDisposed()booleanisValid()
-
-
-
Field Detail
-
_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
-
-
Constructor Detail
-
OauthToken
public OauthToken(OauthToken aOauthToken)
Creates a new instance of theOauthTokenwith the current time being stored for determining validity of the access token viaisValid()as ofgetExpiresIn().- 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 theOauthTokenwith the current time being stored for determining validity of the access token viaisValid()as ofgetExpiresIn().- Parameters:
aAccessToken- The access tokenaRefreshToken- The refresh tokenaTokenType- The token typeaExpiresIn- The expires-time in secondsaScope- 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 theOauthTokenwith the current time being stored for determining validity of the access token viaisValid()as ofgetExpiresIn().- Parameters:
aAccessToken- The access tokenaRefreshToken- The refresh tokenaTokenType- The token typeaNotBeforePolicy- The not-before-policy.aExpiresIn- The expires-time in secondsaRefreshExpiresIn- The refresh's expires-time in secondsaScope- The scopeaSessionState- 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 theOauthTokenwith the current time being stored for determining validity of the access token viaisValid()as ofgetExpiresIn().- Parameters:
aAccessToken- The access tokenaRefreshToken- The refresh tokenaTokenType- The token typeaGrantType- TheGrantTypeused for this tolen.aNotBeforePolicy- The not-before-policy.aExpiresIn- The expires-time in secondsaRefreshExpiresIn- The refresh's expires-time in secondsaScope- The scopeaSessionState- The session state.
-
OauthToken
public OauthToken(HttpBodyMap aOauthToken)
Creates a new instance of theOauthTokenwith the current time being stored for determining validity of the access token viaisValid()as ofgetExpiresIn().- Parameters:
aOauthToken- TheHttpBodyMapcontaining theOauthTokendata.
-
-
Method Detail
-
dispose
public void dispose()
- Specified by:
disposein interfaceorg.refcodes.mixin.Disposable
-
isDisposed
public boolean isDisposed()
- Specified by:
isDisposedin interfaceorg.refcodes.mixin.DisposedAccessor
-
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 theGrantTypeused 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:
isValidin interfaceorg.refcodes.mixin.ValidAccessor
-
fromHttpBodyMap
protected void fromHttpBodyMap(HttpBodyMap aOauthToken)
Sets the internal fields with the data from theHttpBodyMapas of theOauthFielddefinitions.- Parameters:
aOauthToken- TheHttpBodyMapfrom which to gather the data.
-
-