Class OAuth20Token
- java.lang.Object
-
- org.openstreetmap.josm.data.oauth.OAuth20Token
-
- All Implemented Interfaces:
IOAuthToken
public final class OAuth20Token extends java.lang.Object implements IOAuthToken
Token holder for OAuth 2.0- Since:
- 18650
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.String
ACCESS_TOKEN
private java.lang.String
accessToken
private static java.lang.String
CREATED_AT
private java.time.Instant
createdAt
private static java.lang.String
EXPIRES_IN
private int
expiresIn
private IOAuthParameters
oauthParameters
private static java.lang.String
REFRESH_TOKEN
private java.lang.String
refreshToken
private static java.lang.String
SCOPE
private java.lang.String[]
scopes
private static java.lang.String
TOKEN_TYPE
private java.lang.String
tokenType
-
Constructor Summary
Constructors Constructor Description OAuth20Token(IOAuthParameters oauthParameters, java.io.Reader bufferedReader)
OAuth20Token(IOAuthParameters oauthParameters, java.lang.String json)
Create a new OAuth token
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
getBearerToken()
Get the OAuth 2.0 bearer tokenOAuthVersion
getOAuthType()
Get the auth type of this tokenIOAuthParameters
getParameters()
Get the OAuth parameters(package private) OAuth20Token
refresh()
Refresh the OAuth 2.0 token(package private) boolean
shouldRefresh()
Check if the token should be refreshedvoid
sign(HttpClient client)
Sign a clientjava.lang.String
toPreferencesString()
Get the preferences string of this auth token.
-
-
-
Field Detail
-
ACCESS_TOKEN
private static final java.lang.String ACCESS_TOKEN
- See Also:
- Constant Field Values
-
CREATED_AT
private static final java.lang.String CREATED_AT
- See Also:
- Constant Field Values
-
EXPIRES_IN
private static final java.lang.String EXPIRES_IN
- See Also:
- Constant Field Values
-
REFRESH_TOKEN
private static final java.lang.String REFRESH_TOKEN
- See Also:
- Constant Field Values
-
SCOPE
private static final java.lang.String SCOPE
- See Also:
- Constant Field Values
-
TOKEN_TYPE
private static final java.lang.String TOKEN_TYPE
- See Also:
- Constant Field Values
-
accessToken
private final java.lang.String accessToken
-
tokenType
private final java.lang.String tokenType
-
expiresIn
private final int expiresIn
-
refreshToken
private final java.lang.String refreshToken
-
scopes
private final java.lang.String[] scopes
-
createdAt
private final java.time.Instant createdAt
-
oauthParameters
private final IOAuthParameters oauthParameters
-
-
Constructor Detail
-
OAuth20Token
public OAuth20Token(IOAuthParameters oauthParameters, java.lang.String json) throws OAuth20Exception
Create a new OAuth token- Parameters:
oauthParameters
- The parameters for the OAuth tokenjson
- The stored JSON for the token- Throws:
OAuth20Exception
- If the JSON creates an invalid token
-
OAuth20Token
OAuth20Token(IOAuthParameters oauthParameters, java.io.Reader bufferedReader) throws OAuth20Exception
- Throws:
OAuth20Exception
-
-
Method Detail
-
sign
public void sign(HttpClient client) throws OAuthException
Description copied from interface:IOAuthToken
Sign a client- Specified by:
sign
in interfaceIOAuthToken
- Parameters:
client
- The client to sign- Throws:
OAuthException
- if the OAuth token type is unknown (AKA we don't know how to handle it)
-
getBearerToken
public java.lang.String getBearerToken()
Get the OAuth 2.0 bearer token- Returns:
- The bearer token. May return
null
if the token type is not a bearer type.
-
toPreferencesString
public java.lang.String toPreferencesString()
Description copied from interface:IOAuthToken
Get the preferences string of this auth token. This should match the expected return body from the authentication server. For OAuth, this is typically JSON.- Specified by:
toPreferencesString
in interfaceIOAuthToken
- Returns:
- The preferences string
-
getOAuthType
public OAuthVersion getOAuthType()
Description copied from interface:IOAuthToken
Get the auth type of this token- Specified by:
getOAuthType
in interfaceIOAuthToken
- Returns:
- The auth type
-
getParameters
public IOAuthParameters getParameters()
Description copied from interface:IOAuthToken
Get the OAuth parameters- Specified by:
getParameters
in interfaceIOAuthToken
- Returns:
- The OAuth parameters
-
shouldRefresh
boolean shouldRefresh()
Check if the token should be refreshed- Returns:
true
if the token should be refreshed
-
refresh
OAuth20Token refresh()
Refresh the OAuth 2.0 token- Returns:
- The new token to use
-
-