Interface TokenStrategy
- All Known Implementing Classes:
SimpleTokenStrategy
public interface TokenStrategy
Manages and validates OAuth tokens and token secrets.
SimpleTokenStrategy
is a basic implementation, but you can implement
this interface to generate and validate OAuth tokens your own way.- Author:
- Samuel Padgett
-
Method Summary
Modifier and TypeMethodDescriptionvoid
generateAccessToken
(OAuthRequest oAuthRequest) Generates an access token and token secret and sets it in the accessor in theOAuthRequest
.void
generateRequestToken
(OAuthRequest oAuthRequest) Generates a request token and token secret and sets it in the accessor in theOAuthRequest
.generateVerificationCode
(HttpServletRequest httpRequest, String requestToken) Generates an "unguessable" OAuth verification code.getCallback
(HttpServletRequest httpRequest, String requestToken) Gets the OAuth callback associated with this consumer for OAuth 1.0a authentication flows.getTokenSecret
(HttpServletRequest httpRequest, String token) Gets the token secret for token to validate signatures.boolean
isRequestTokenAuthorized
(HttpServletRequest httpRequest, String requestToken) Checks with the request token has been authorized by the end user.void
markRequestTokenAuthorized
(HttpServletRequest httpRequest, String requestToken) Indicates that a user has typed in a valid ID and password, and that the request token can now be exchanged for an access token.void
validateAccessToken
(OAuthRequest oAuthRequest) Validates that the access token is valid, throwing an exception if not.validateRequestToken
(HttpServletRequest httpRequest, net.oauth.OAuthMessage message) Validates that the request token is valid, throwing an exception if not.void
validateVerificationCode
(OAuthRequest oAuthRequest) Validates that the verification code is recognized and associated with the request token.
-
Method Details
-
generateRequestToken
Generates a request token and token secret and sets it in the accessor in theOAuthRequest
.- Parameters:
oAuthRequest
- the OAuth request- Throws:
IOException
- on errors reading from the request messagenet.oauth.OAuthException
- on OAuth problems- See Also:
-
validateRequestToken
String validateRequestToken(HttpServletRequest httpRequest, net.oauth.OAuthMessage message) throws net.oauth.OAuthException, IOException Validates that the request token is valid, throwing an exception if not. Returns the consumer key so that the authorization page can display information about the consumer. The token strategy must track what request tokens belong to what consumers since the consumer key is not guaranteed to be in the request.- Parameters:
httpRequest
- the HTTP requestmessage
- the OAuth message- Returns:
- the consumer key associated with the request
- Throws:
net.oauth.OAuthException
- if the tokens are not validIOException
- on I/O errors
-
getCallback
String getCallback(HttpServletRequest httpRequest, String requestToken) throws net.oauth.OAuthException Gets the OAuth callback associated with this consumer for OAuth 1.0a authentication flows. Returns null if the consumer did not specify a callback when asking for a request token.- Parameters:
httpRequest
- the HTTP requestrequestToken
- the request token- Returns:
- the callback URL
- Throws:
net.oauth.OAuthException
- on OAuth problems
-
markRequestTokenAuthorized
void markRequestTokenAuthorized(HttpServletRequest httpRequest, String requestToken) throws net.oauth.OAuthException Indicates that a user has typed in a valid ID and password, and that the request token can now be exchanged for an access token.- Parameters:
httpRequest
- the servlet requestrequestToken
- the request token string- Throws:
net.oauth.OAuthException
- if the token is not valid- See Also:
-
isRequestTokenAuthorized
boolean isRequestTokenAuthorized(HttpServletRequest httpRequest, String requestToken) throws net.oauth.OAuthException Checks with the request token has been authorized by the end user.- Parameters:
httpRequest
- the servlet requestrequestToken
- the request token- Returns:
- answers if the request token is authorized and can be exchanged for an access token
- Throws:
net.oauth.OAuthException
- on OAuth problems- See Also:
-
generateVerificationCode
String generateVerificationCode(HttpServletRequest httpRequest, String requestToken) throws net.oauth.OAuthException Generates an "unguessable" OAuth verification code. The consumer must supply the verification code when exchanging the request token for an access token. This is specific to OAuth 1.0a.- Parameters:
httpRequest
- the HTTP requestrequestToken
- the request token- Returns:
- a verification code
- Throws:
net.oauth.OAuthException
- on OAuth problems (e.g., the request token is invalid)
-
validateVerificationCode
void validateVerificationCode(OAuthRequest oAuthRequest) throws net.oauth.OAuthException, IOException Validates that the verification code is recognized and associated with the request token. This must be called before the request token is exchanged for the access token in an OAuth 1.0a authentication flow.- Parameters:
oAuthRequest
- the OAuth request- Throws:
net.oauth.OAuthException
- on OAuth problems (e.g., the request token is invalid)IOException
- on I/O errors
-
generateAccessToken
Generates an access token and token secret and sets it in the accessor in theOAuthRequest
. Clears any request tokens set.- Parameters:
oAuthRequest
- the OAuth request- Throws:
net.oauth.OAuthException
- on OAuth problemsIOException
- on I/O errors- See Also:
-
validateAccessToken
Validates that the access token is valid, throwing an exception if not.- Parameters:
oAuthRequest
- the OAuth request- Throws:
net.oauth.OAuthException
- if the token is invalidIOException
- on I/O errors
-
getTokenSecret
Gets the token secret for token to validate signatures.- Parameters:
httpRequest
- the HTTP requesttoken
- the token string, either a request token or access token- Returns:
- the token secret
- Throws:
net.oauth.OAuthException
- on OAuth problems (e.g., the token is invalid)
-