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"-
Nested Class Summary
Nested classes/interfaces inherited from interface org.refcodes.mixin.ValidAccessor
org.refcodes.mixin.ValidAccessor.ValidBuilder<B extends org.refcodes.mixin.ValidAccessor.ValidBuilder<B>>, org.refcodes.mixin.ValidAccessor.ValidMutator, org.refcodes.mixin.ValidAccessor.ValidProperty
-
Field Summary
-
Constructor Summary
ConstructorDescriptionOauthToken
(String aAccessToken, String aRefreshToken, String aTokenType, Integer aExpiresIn, String aScope) Creates a new instance of theOauthToken
with 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 theOauthToken
with 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 theOauthToken
with the current time being stored for determining validity of the access token viaisValid()
as ofgetExpiresIn()
.OauthToken
(HttpBodyMap aOauthToken) Creates a new instance of theOauthToken
with the current time being stored for determining validity of the access token viaisValid()
as ofgetExpiresIn()
.OauthToken
(OauthToken aOauthToken) Creates a new instance of theOauthToken
with the current time being stored for determining validity of the access token viaisValid()
as ofgetExpiresIn()
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
dispose()
protected void
fromHttpBodyMap
(HttpBodyMap aOauthToken) Sets the internal fields with the data from theHttpBodyMap
as of theOauthField
definitions.Returns the access token.Returns the time in seconds till the access token (getAccessToken()
) expires.Returns theGrantType
used by this token.Returns the not-before-policy.Returns the time in seconds till the refresh token (getRefreshToken()
) expires.Returns the refresh token.getScope()
Returns the OAuth scope.Returns the session state.Returns the token type.boolean
isValid()
-
Field Details
-
_accessToken
-
_refreshToken
-
_tokenType
-
_expiresIn
-
_refreshExpiresIn
-
_scope
-
_notBeforePolicy
-
_sessionState
-
_grantType
-
_isDisposed
protected boolean _isDisposed
-
-
Constructor Details
-
OauthToken
Creates a new instance of theOauthToken
with 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 theOauthToken
with 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 theOauthToken
with 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 theOauthToken
with 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
- TheGrantType
used 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
Creates a new instance of theOauthToken
with the current time being stored for determining validity of the access token viaisValid()
as ofgetExpiresIn()
.- Parameters:
aOauthToken
- TheHttpBodyMap
containing theOauthToken
data.
-
-
Method Details
-
dispose
public void dispose()- Specified by:
dispose
in interfaceorg.refcodes.mixin.Disposable
-
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
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
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
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
Returns theGrantType
used by this token.- Returns:
- the according
GrantType
.
-
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
Returns the not-before-policy.- Returns:
- the not-before-policy.
-
getSessionState
Returns the session state.- Returns:
- the session state.
-
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 interfaceorg.refcodes.mixin.ValidAccessor
-
fromHttpBodyMap
Sets the internal fields with the data from theHttpBodyMap
as of theOauthField
definitions.- Parameters:
aOauthToken
- TheHttpBodyMap
from which to gather the data.
-