Class OAuth2ClientSupport
client filter feature
that
can supports performing of authenticated OAuth requests.
Authorization flow
For more information about authorization flow, seeOAuth2CodeGrantFlow
.
Client feature
Use method feature(String)
to build the feature. OAuth2 client filter feature registers
the support for performing authenticated requests to the
Service Provider. The feature uses an access token to initialize
the internal filter
which will add Authorization
http header containing OAuth 2 authorization information (based
on bearer
tokens).
The internal filter can be controlled by properties put into
the client request
using ClientRequestContext.setProperty(String, Object)
method. The property key
is defined in this class as a static variables
(OAUTH2_PROPERTY_ACCESS_TOKEN
(see its javadoc for usage).
Using the property a specific
access token can be defined for each request.
final Response response = client.target("foo").request() .property(OAUTH2_PROPERTY_ACCESS_TOKEN, "6ab45ab465e46f54d771a").get();
- Since:
- 2.3
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
Key of the property that can be attached to theclient request
usingClientRequestContext.setProperty(String, Object)
and that defines access token that should be used when generating OAuthAuthorization
http header. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic OAuth2CodeGrantFlow.Builder
authorizationCodeGrantFlowBuilder
(ClientIdentifier clientIdentifier, String authorizationUri, String accessTokenUri) Get the builder of theAuthorization Code Grant Flow
.static OAuth2CodeGrantFlow.Builder
facebookFlowBuilder
(ClientIdentifier clientIdentifier, String redirectURI) Get a builder that can be directly used to perform Authorization Code Grant flow defined by Facebook.static javax.ws.rs.core.Feature
Build theclient filter feature
from theaccessToken
that will addAuthorization
http header to the request with the OAuth authorization information.static OAuth2FlowGoogleBuilder
googleFlowBuilder
(ClientIdentifier clientIdentifier, String redirectURI, String scope) Get a builder that can be directly used to perform Authorization Code Grant flow defined by Google.
-
Field Details
-
OAUTH2_PROPERTY_ACCESS_TOKEN
Key of the property that can be attached to theclient request
usingClientRequestContext.setProperty(String, Object)
and that defines access token that should be used when generating OAuthAuthorization
http header. The property will override the setting of the internalfilter
for the current request only. This property can be used only whenOAauth 2 filter feature
is registered into theClient
instance.The value of the property must be a
String
.- See Also:
-
-
Constructor Details
-
OAuth2ClientSupport
private OAuth2ClientSupport()Prevent instantiation.
-
-
Method Details
-
feature
Build theclient filter feature
from theaccessToken
that will addAuthorization
http header to the request with the OAuth authorization information.- Parameters:
accessToken
- Access token to be used in the authorization header ornull
if no default access token should be defined. In this case the token will have to be set for each request usingOAUTH2_PROPERTY_ACCESS_TOKEN
property.- Returns:
- Client feature.
-
authorizationCodeGrantFlowBuilder
public static OAuth2CodeGrantFlow.Builder authorizationCodeGrantFlowBuilder(ClientIdentifier clientIdentifier, String authorizationUri, String accessTokenUri) Get the builder of theAuthorization Code Grant Flow
.- Parameters:
clientIdentifier
- Client identifier (id of application that wants to be approved). Issued by the Service Provider.authorizationUri
- The URI to which the user should be redirected to authorize our application. The URI points to the authorization server and is defined by the Service Provider.accessTokenUri
- The access token URI on which the access token can be requested. The URI points to the authorization server and is defined by the Service Provider.- Returns:
- builder of the
Authorization Code Grant Flow
.
-
googleFlowBuilder
public static OAuth2FlowGoogleBuilder googleFlowBuilder(ClientIdentifier clientIdentifier, String redirectURI, String scope) Get a builder that can be directly used to perform Authorization Code Grant flow defined by Google.- Parameters:
clientIdentifier
- Client identifier (id of application that wants to be approved). Issued by the Service Provider.redirectURI
- URI to which the user (resource owner) should be redirected after he/she grants access to our application ornull
if the application does not support redirection (eg. is not a web server).scope
- The api to which an access is requested (eg. Google tasks).- Returns:
- Google builder instance.
-
facebookFlowBuilder
public static OAuth2CodeGrantFlow.Builder facebookFlowBuilder(ClientIdentifier clientIdentifier, String redirectURI) Get a builder that can be directly used to perform Authorization Code Grant flow defined by Facebook.- Parameters:
clientIdentifier
- Client identifier (id of application that wants to be approved). Issued by the Service Provider.redirectURI
- URI to which the user (resource owner) should be redirected after he/she grants access to our application ornull
if the application does not support redirection (eg. is not a web server).- Returns:
- Builder instance.
-