public class OAuth1Generic extends Object
OAuth1NoCallback
for an OAuth1.0 consumer not using a callback, and OAuth1WithCallback
for an OAuth1.0 consumer using a callback.
begin()
to obtain a temporary token and a redirect URL if authoriseUrl
was provided (not null).
authorised(String, String)
with the temporary token obtained in (1), and the verifier (provided as a parameter to the callback, as parsed on the front-end), or null if no callback was used.
OAuthParameters
object that can be used to make requests on the user's behalf. Using the OAuthParameters
make a request to a given URL with a given HTTP request method and body via makeOAuthBackedRequest(String, OAuthParameters, RequestMethod, HttpContent)
.Modifier and Type | Field and Description |
---|---|
protected String |
accessTokenUrl |
protected String |
authoriseUrl |
protected String |
callbackUrl |
protected String |
consumerKey |
protected String |
consumerSecret |
protected String |
requestTokenUrl |
protected TokenMapStrategy |
tokenMapStrategy |
Modifier | Constructor and Description |
---|---|
protected |
OAuth1Generic(String consumerKey,
String consumerSecret,
String requestTokenUrl,
String callbackUrl,
String authoriseUrl,
String accessTokenUrl,
TokenMapStrategy tokenMapStrategy) |
Modifier and Type | Method and Description |
---|---|
protected AuthorisedResult |
authorised(String temporaryToken,
String verifier)
Fetches the token secret corresponding to the temporary token,
then uses the obtained token secret along with the original temporary token and verifier to obtain an access token from the server.
|
protected BeginResult |
begin()
Requests a temporary token and corresponding token secret from the server,
then maps the temporary token to the token secret
and returns the obtained temporary token along with the authenticate URL (redirect URL) if
authoriseUrl is non-null. |
static com.google.api.client.http.HttpResponse |
makeOAuthBackedRequest(String url,
com.google.api.client.auth.oauth.OAuthParameters oAuthParameters,
RequestMethod requestMethod,
com.google.api.client.http.HttpContent httpContent)
Makes a request to the given URL wrapped with a user's OAuth credentials (which includes their access token) obtained from
authorised(String, String) ,
to make a request on a user's behalf. |
@Nonnull protected TokenMapStrategy tokenMapStrategy
protected OAuth1Generic(@Nonnull String consumerKey, @Nonnull String consumerSecret, @Nonnull String requestTokenUrl, @Nullable String callbackUrl, @Nullable String authoriseUrl, @Nonnull String accessTokenUrl, @Nonnull TokenMapStrategy tokenMapStrategy)
consumerKey
- Required identifier portion of the client credentials (equivalent to a username). More information: client_id entry of the OAuthParameters table at https://www.iana.org/assignments/oauth-parameters/oauth-parameters.xhtmlconsumerSecret
- Client-shared secret. More information: client_id entry of the OAuthParameters table at https://www.iana.org/assignments/oauth-parameters/oauth-parameters.xhtmlrequestTokenUrl
- Encoded authorization server URL. More information: request_uri entry of the OAuthParameters table at https://www.iana.org/assignments/oauth-parameters/oauth-parameters.xhtmlcallbackUrl
- Optional absolute URI back to which the server will redirect the resource owner when the Resource Owner Authorization step is completed or null for none. More information: redirect_uri entry of the OAuthParameters table at https://www.iana.org/assignments/oauth-parameters/oauth-parameters.xhtmlauthoriseUrl
- Encoded user authorization URL, or null if only wish to receive the temporary token and build it themselves.accessTokenUrl
- Encoded authorization server URL.tokenMapStrategy
- Strategy to map temporary tokens to token secrets, and fetch the token secret for a temporary token.@Nonnull protected BeginResult begin() throws GetTemporaryTokenException, TokenMapException
authoriseUrl
is non-null.authoriseUrl
is non-null, otherwise null.GetTemporaryTokenException
- If the request to the server for the temporary token failed.TokenMapException
- If mapping the obtained temporary token to the obtained token secret failed.@Nonnull protected AuthorisedResult authorised(@Nonnull String temporaryToken, @Nullable String verifier) throws GetAccessTokenException, TokenMapException
temporaryToken
- The temporary token obtained from begin()
verifier
- The verifier, if a callback is used, otherwise null.OAuthParameters
object used to make OAuth-backed requests on behalf of the access token via makeOAuthBackedRequest(String, OAuthParameters, RequestMethod, HttpContent)
GetAccessTokenException
- If the request to the server for the access token failed.TokenMapException
- If fetching the token secret corresponding to the given temporary token failed.@Nonnull public static com.google.api.client.http.HttpResponse makeOAuthBackedRequest(@Nonnull String url, @Nonnull com.google.api.client.auth.oauth.OAuthParameters oAuthParameters, @Nonnull RequestMethod requestMethod, @Nullable com.google.api.client.http.HttpContent httpContent) throws OAuthBackedRequestException
authorised(String, String)
,
to make a request on a user's behalf.url
- The URL to make the request to.oAuthParameters
- The OAuth credentials corresponding to a user (which includes their access token) obtained from authorised(String, String)
requestMethod
- The HTTP request method (GET, PUT, etc.)httpContent
- The content of the HTTP request body, if applicable (e.g. in a PUT request), otherwise null.HttpResponse.parseAsString()
or HttpResponse.parseAs(Class)
to deserialize the response body.OAuthBackedRequestException
- If building the request, or executing the request to the server, failed.Copyright © 2020. All rights reserved.