Skip to content

malkomich/oauth2-token-client

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
src
 
 
 
 
 
 
 
 
 
 

OAuth2 Token Client

Overview

OAuth2 token client, to implement OAuth2 security in our REST clients.

Requisites

  • Java 8+
  • Maven 3+

Install

Gradle

	dependencies {
	    compile 'com.github.malkomich:oauth2-token-client:0.0.1'
	}

Maven

	<dependency>
	    <groupId>com.github.malkomich</groupId>
	    <artifactId>oauth2-token-client</artifactId>
	    <version>0.0.1</version>
	</dependency>

Usage

Initialize client:
OAuth2Client oAuth2Client = OAuth2Client
    .withConfig(oAuth2Config) // Initialize OAuth2Config from your config files
    .build();
Generate token:
String token = Optional.ofNullable(oAuth2Client.accessToken())
    .map(AccessToken::getAccessToken)
    .map("Bearer "::concat)
    .orElseThrow(() -> new AccessDeniedException());
Include the Authorization header:
// Spring WebClient
clientRequest.header(HttpHeaders.AUTHORIZATION, token);
// Feign Client
requestTemplate.header(HttpHeaders.AUTHORIZATION, token);
// Vert.x WebClient
webClient.putHeader(HttpHeaders.AUTHORIZATION.toString(), token)
// or any other Framework or client you may use

License

Apache License

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages