Class OAuth2ClientSupport
- java.lang.Object
-
- org.glassfish.jersey.client.oauth2.OAuth2ClientSupport
-
public final class OAuth2ClientSupport extends Object
Main class to build the Authorization Flow instances andclient filter featurethat 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 internalfilterwhich will addAuthorizationhttp header containing OAuth 2 authorization information (based onbearertokens).The internal filter can be controlled by properties put into the
Example of using specific access token for one request:client requestusingClientRequestContext.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
- Author:
- Miroslav Fuksa
-
-
Field Summary
Fields Modifier and Type Field Description static StringOAUTH2_PROPERTY_ACCESS_TOKENKey of the property that can be attached to theclient requestusingClientRequestContext.setProperty(String, Object)and that defines access token that should be used when generating OAuthAuthorizationhttp header.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static OAuth2CodeGrantFlow.BuilderauthorizationCodeGrantFlowBuilder(ClientIdentifier clientIdentifier, String authorizationUri, String accessTokenUri)Get the builder of theAuthorization Code Grant Flow.static OAuth2CodeGrantFlow.BuilderfacebookFlowBuilder(ClientIdentifier clientIdentifier, String redirectURI)Get a builder that can be directly used to perform Authorization Code Grant flow defined by Facebook.static Featurefeature(String accessToken)Build theclient filter featurefrom theaccessTokenthat will addAuthorizationhttp header to the request with the OAuth authorization information.static OAuth2FlowGoogleBuildergoogleFlowBuilder(ClientIdentifier clientIdentifier, String redirectURI, 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 String OAUTH2_PROPERTY_ACCESS_TOKEN
Key of the property that can be attached to theclient requestusingClientRequestContext.setProperty(String, Object)and that defines access token that should be used when generating OAuthAuthorizationhttp header. The property will override the setting of the internalfilterfor the current request only. This property can be used only whenOAauth 2 filter featureis registered into theClientinstance.The value of the property must be a
String.- See Also:
- Constant Field Values
-
-
Method Detail
-
feature
public static Feature feature(String accessToken)
Build theclient filter featurefrom theaccessTokenthat will addAuthorizationhttp header to the request with the OAuth authorization information.- Parameters:
accessToken- Access token to be used in the authorization header ornullif no default access token should be defined. In this case the token will have to be set for each request usingOAUTH2_PROPERTY_ACCESS_TOKENproperty.- 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 ornullif 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 ornullif the application does not support redirection (eg. is not a web server).- Returns:
- Builder instance.
-
-