public class Token extends Object
The token acts as the bearer of authentication within each request to the Strava API.
A token is used to acquire an implementation of each of the service objects that sub-class StravaServiceImpl
Tokens are acquired through the OAuth process; this implementation of the API does not provide a purely programmatic way to acquire a token as that would
kind of destroy the point(!) - although once a user has given their permission to the application via the OAuth process, you can use
AuthorisationService.tokenExchange(Integer, String, String, AuthorisationScope...) to acquire a token at that point in the process.
The application will now be able to make requests on the user’s behalf using the access_token query string parameter (GET) or POST/PUT body, or the Authorization header. This is done auto-magically by javastrava.
Applications should check for a 401 Unauthorized response. Access for those tokens has been revoked by the user.
| Constructor and Description |
|---|
Token(TokenResponse tokenResponse,
AuthorisationScope... scopes)
Default constructor is based on the
TokenResponse structure received from AuthorisationService.tokenExchange(Integer, String, String, AuthorisationScope...) |
| Modifier and Type | Method and Description |
|---|---|
void |
addService(Class<? extends StravaService> class1,
StravaService service)
Adds a service implementation into the Token's store
|
<T extends StravaService> |
getService(Class<T> class1)
Gets the service implementation of the required class from the token
|
boolean |
hasViewPrivate()
Validates that the toke has view private access (according to the scopes that it was granted on creation at least; it is quite possible that permissions have subsequently been revoked by the user)
|
boolean |
hasWriteAccess()
Validates that the token has write access (according to the scopes that it was granted on creation at least; it is quite possible that permissions have subsequently been revoked by the user)
|
void |
removeService(Class<? extends StravaService> class1)
Removes the service from the Token's store
|
public Token(TokenResponse tokenResponse, AuthorisationScope... scopes)
Default constructor is based on the TokenResponse structure received from AuthorisationService.tokenExchange(Integer, String, String, AuthorisationScope...)
tokenResponse - The response as received from AuthorisationService.tokenExchange(Integer, String, String, AuthorisationScope...)scopes - The list of authorisation scopes to be associated with the tokenpublic void addService(Class<? extends StravaService> class1, StravaService service)
Adds a service implementation into the Token's store
class1 - The class of the service implementationservice - The service implementationpublic <T extends StravaService> T getService(Class<T> class1)
Gets the service implementation of the required class from the token
T - The class being returnedclass1 - The class to returnpublic void removeService(Class<? extends StravaService> class1)
Removes the service from the Token's store
class1 - The class of token to be removedpublic boolean hasWriteAccess()
Validates that the token has write access (according to the scopes that it was granted on creation at least; it is quite possible that permissions have subsequently been revoked by the user)
true if the token contains the AuthorisationScope.WRITEpublic boolean hasViewPrivate()
Validates that the toke has view private access (according to the scopes that it was granted on creation at least; it is quite possible that permissions have subsequently been revoked by the user)
true if the token contains the AuthorisationScope.VIEW_PRIVATECopyright © 2015 Dan Shannon. All rights reserved.