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()
No-args constructor
|
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
|
boolean |
equals(Object obj) |
StravaAthlete |
getAthlete() |
List<AuthorisationScope> |
getScopes() |
<T extends StravaService> |
getService(Class<T> class1)
Gets the service implementation of the required class from the token
|
HashMap<Class<? extends StravaService>,StravaService> |
getServices() |
String |
getToken() |
String |
getTokenType() |
int |
hashCode() |
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
|
void |
setAthlete(StravaAthlete athlete) |
void |
setScopes(List<AuthorisationScope> scopes) |
void |
setServices(HashMap<Class<? extends StravaService>,StravaService> services) |
void |
setToken(String token) |
void |
setTokenType(String tokenType) |
String |
toString() |
public Token()
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 boolean equals(Object obj)
equals in class ObjectObject.equals(java.lang.Object)public StravaAthlete getAthlete()
public List<AuthorisationScope> getScopes()
public <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 HashMap<Class<? extends StravaService>,StravaService> getServices()
public String getToken()
public String getTokenType()
public int hashCode()
hashCode in class ObjectObject.hashCode()public 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_PRIVATEpublic 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 void removeService(Class<? extends StravaService> class1)
Removes the service from the Token's store
class1 - The class of token to be removedpublic void setAthlete(StravaAthlete athlete)
athlete - the athlete to setpublic void setScopes(List<AuthorisationScope> scopes)
scopes - the scopes to setpublic void setServices(HashMap<Class<? extends StravaService>,StravaService> services)
services - the services to setpublic void setToken(String token)
token - the token to setpublic void setTokenType(String tokenType)
tokenType - the tokenType to setpublic String toString()
toString in class ObjectObject.toString()Copyright © 2016 Dan Shannon. All rights reserved.