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.StringACCESS_TOKENprivate java.lang.StringaccessTokenprivate static java.lang.StringCREATED_ATprivate java.time.InstantcreatedAtprivate static java.lang.StringEXPIRES_INprivate intexpiresInprivate IOAuthParametersoauthParametersprivate static java.lang.StringREFRESH_TOKENprivate java.lang.StringrefreshTokenprivate static java.lang.StringSCOPEprivate java.lang.String[]scopesprivate static java.lang.StringTOKEN_TYPEprivate java.lang.StringtokenType
-
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.StringgetBearerToken()Get the OAuth 2.0 bearer tokenOAuthVersiongetOAuthType()Get the auth type of this tokenIOAuthParametersgetParameters()Get the OAuth parameters(package private) OAuth20Tokenrefresh()Refresh the OAuth 2.0 token(package private) booleanshouldRefresh()Check if the token should be refreshedvoidsign(HttpClient client)Sign a clientjava.lang.StringtoPreferencesString()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:IOAuthTokenSign a client- Specified by:
signin 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
nullif the token type is not a bearer type.
-
toPreferencesString
public java.lang.String toPreferencesString()
Description copied from interface:IOAuthTokenGet 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:
toPreferencesStringin interfaceIOAuthToken- Returns:
- The preferences string
-
getOAuthType
public OAuthVersion getOAuthType()
Description copied from interface:IOAuthTokenGet the auth type of this token- Specified by:
getOAuthTypein interfaceIOAuthToken- Returns:
- The auth type
-
getParameters
public IOAuthParameters getParameters()
Description copied from interface:IOAuthTokenGet the OAuth parameters- Specified by:
getParametersin interfaceIOAuthToken- Returns:
- The OAuth parameters
-
shouldRefresh
boolean shouldRefresh()
Check if the token should be refreshed- Returns:
trueif the token should be refreshed
-
refresh
OAuth20Token refresh()
Refresh the OAuth 2.0 token- Returns:
- The new token to use
-
-