public final class OAuthClientFilter extends ClientFilter
Note: This filter signs the request based on its request parameters. For this reason, you should invoke this filter after any others that modify any request parameters.
Example 1:
// baseline OAuth parameters for access to resource OAuthParameters params = new OAuthParameters().signatureMethod("HMAC-SHA1"). consumerKey("key").setToken("accesskey"); // OAuth secrets to access resource OAuthSecrets secrets = new OAuthSecrets().consumerSecret("secret").setTokenSecret("accesssecret"); // if parameters and secrets remain static, filter can be added to each web resource OAuthClientFilter filter = new OAuthClientFilter(client.getProviders(), params, secrets); // OAuth test server WebResource resource = client.resource("http://term.ie/oauth/example/request_token.php"); resource.addFilter(filter); String response = resource.get(String.class);
Example 2 (handling authorization flow):
OAuthClientFilter filter = new OAuthClientFilter( client.getProviders(), new OAuthParameters().consumerKey("key"), new OAuthSecrets().consumerSecret("secret"), "http://request.token.uri", "http://access.token.uri", "http://authorization.uri", new OAuthClientFilter.AuthHandler() {
Modifier and Type | Class and Description |
---|---|
static interface |
OAuthClientFilter.AuthHandler
Implementation of this interface should be passed to the filter constructor
to handle user authorization requests and respond to obtaining a new access token
(e.g.
|
Constructor and Description |
---|
OAuthClientFilter(javax.ws.rs.ext.Providers providers,
OAuthParameters parameters,
OAuthSecrets secrets)
Constructs a new OAuth client filter with the specified providers.
|
OAuthClientFilter(javax.ws.rs.ext.Providers providers,
OAuthParameters parameters,
OAuthSecrets secrets,
String requestTokenUri,
String accessTokenUri,
String authorizationUri,
OAuthClientFilter.AuthHandler handler)
Constructs a new OAuth client filter providing URI's for requesting
request and access tokens and authorization.
|
Modifier and Type | Method and Description |
---|---|
ClientResponse |
handle(ClientRequest request)
Note: This method automatically sets the nonce and timestamp.
|
getNext
public OAuthClientFilter(javax.ws.rs.ext.Providers providers, OAuthParameters parameters, OAuthSecrets secrets)
providers
- the registered providers from Client.getProviders()
method.parameters
- the OAuth parameters to be used in signing requests.secrets
- the OAuth secrets to be used in signing requests.public OAuthClientFilter(javax.ws.rs.ext.Providers providers, OAuthParameters parameters, OAuthSecrets secrets, String requestTokenUri, String accessTokenUri, String authorizationUri, OAuthClientFilter.AuthHandler handler)
providers
- the registered providers from Client.getProviders()
method.parameters
- the OAuthParameters to be used in signing requests.secrets
- the OAuth secrets to be used in signing requests.requestTokenUri
- URI for requesting new request tokens.accessTokenUri
- URI for requesting access tokens.authorizationUri
- URI for requesting authorization of request tokens.handler
- Implementation of AuthHandler this filter calls to obtain user authorization
and notify the application of a new access token obtained. If null is passed,
instead of invoking the handler for user authorization when needed,
UnauthorizedRequestException
is thrown by the filter.public ClientResponse handle(ClientRequest request) throws ClientHandlerException
handle
in interface ClientHandler
handle
in class ClientFilter
request
- the HTTP request.ClientHandlerException
- if the client
handler fails to process the request or response.Copyright © 2013 Oracle Corporation. All rights reserved.