Class OAuth2ClientFeature

java.lang.Object
org.glassfish.jersey.client.oauth2.OAuth2ClientFeature
All Implemented Interfaces:
javax.ws.rs.core.Feature

class OAuth2ClientFeature extends Object implements javax.ws.rs.core.Feature
OAuth2 client filter feature registers the support for performing authenticated requests to the Service Provider. The feature does not perform Authorization Flow (see OAuth2CodeGrantFlow for details how to use Authorization Flow and retrieve Access Token). The feature uses access to initialize the internal filter which will add Authorization http header containing OAuth 2 authorization information including (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 (OAuth2ClientSupport.OAUTH2_PROPERTY_ACCESS_TOKEN (see its javadoc for usage). Using the property a specific access token can be defined for each request.

Example of using specific access token for one request:
 final Response response = client.target("foo").request()
           .property(OAUTH2_PROPERTY_ACCESS_TOKEN, "6ab45ab465e46f54d771a").get();
 
Since:
2.3
  • Field Details

  • Constructor Details

    • OAuth2ClientFeature

      public OAuth2ClientFeature(String accessToken)
      Create a new feature initialized for the access token.
      Parameters:
      accessToken - Access token.
    • OAuth2ClientFeature

      public OAuth2ClientFeature()
      Create a new filter feature with no default access token. The token will have to be specified by OAuth2ClientSupport.OAUTH2_PROPERTY_ACCESS_TOKEN for each request otherwise no Authorization http header will be added.
    • OAuth2ClientFeature

      OAuth2ClientFeature(OAuth2ClientFilter filter)
      Create a new feature with the given filter.
      Parameters:
      filter - Filter instance.
  • Method Details

    • configure

      public boolean configure(javax.ws.rs.core.FeatureContext context)
      Specified by:
      configure in interface javax.ws.rs.core.Feature