Class OAuth2ClientSupport
- java.lang.Object
-
- org.glassfish.jersey.client.oauth2.OAuth2ClientSupport
-
public final class OAuth2ClientSupport extends java.lang.Object
Main class to build the Authorization Flow instances andclient 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 internalfilter
which will addAuthorization
http header containing OAuth 2 authorization information (based onbearer
tokens).The internal filter can be controlled by properties put into the
Example of using specific access token for one request:client request
usingClientRequestContext.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
Fields Modifier and Type Field Description static java.lang.String
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.
-
Constructor Summary
Constructors Modifier Constructor Description private
OAuth2ClientSupport()
Prevent instantiation.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static OAuth2CodeGrantFlow.Builder
authorizationCodeGrantFlowBuilder(ClientIdentifier clientIdentifier, java.lang.String authorizationUri, java.lang.String accessTokenUri)
Get the builder of theAuthorization Code Grant Flow
.static OAuth2CodeGrantFlow.Builder
facebookFlowBuilder(ClientIdentifier clientIdentifier, java.lang.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
feature(java.lang.String accessToken)
Build theclient filter feature
from theaccessToken
that will addAuthorization
http header to the request with the OAuth authorization information.static OAuth2FlowGoogleBuilder
googleFlowBuilder(ClientIdentifier clientIdentifier, java.lang.String redirectURI, java.lang.String scope)
Get a builder that can be directly used to perform Authorization Code Grant flow defined by Google.
-
-
-
Field Detail
-
OAUTH2_PROPERTY_ACCESS_TOKEN
public static final java.lang.String 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:
- Constant Field Values
-
-
Method Detail
-
feature
public static javax.ws.rs.core.Feature feature(java.lang.String accessToken)
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, java.lang.String authorizationUri, java.lang.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, java.lang.String redirectURI, java.lang.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, java.lang.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.
-
-