Skip to content

Latest commit

 

History

History
64 lines (45 loc) · 2.02 KB

README.md

File metadata and controls

64 lines (45 loc) · 2.02 KB

Build

OAuthTokenFilter

The OAuthTokenFilter is a JAX-RS client filter that handles OAuth2 authorization. It

  • filters your requests to a service,
  • adds a OAuth2-Token to your requests,
  • stores the token,
  • checks the token for validity
  • and refreshes the token when necessary.

Installing / Getting started

To include the OAuthTokenFilter in your project, simply add it as a Maven Dependency.

<dependency>
  <groupId>de.otto.oauthtokenfilter</groupId>
  <artifactId>oauth-token-filter</artifactId>
  <version>2.0.1</version>
</dependency>

Initial Configuration

Upon using your ClientBuilder, call

import de.otto.oauthtokenfilter.OAuthTokenFilter;
import jakarta.ws.rs.client.ClientBuilder;
...

ClientBuilder.newBuilder()
 .register(OAuthTokenFilter.builder()
   .username("<yourUsername>")
    .password("<yourPassword>")
    .loginurl("<yourLoginURL>")
    .clientId("<yourClientId>")
    .clientSecret("<yourClientSecret>")
    .tokenLifetimeInSeconds("<yourTokenLifetimeInSeconds>")
    .grant_type("<api_grant_type>")    
    .client(ClientBuilder.newClient());    
    .build())
  .build();

After that, all requests generated by that client will have the proper Authorization Header generated. If the OAuth-server you're working with doesn't need certain values, you can simply leave them out. If you do not specify "grant_type", it will default to "password".

Developing

If you'd like to work on the project, you can do so by running:

git clone https://github.com/otto-de/oauth-token-filter.git

Contributing

If you'd like to contribute, please fork the repository and use a feature branch. Pull requests are warmly welcome.

Please follow Google Style formatting.

License

The code in this project is licensed under Apache 2.0 license.