Skip to content

scalepoint-tech/oauth-token-java-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OAuth Token Endpoint Client for Java

Description

Client helper for OAuth 2.0 Token endpoint. Supports "Client Credentials" flow with "client_secret", RS256 JWT "client_assertion" and custom grants.

Features

This library only interacts with token endpoint and receives access_token. It is not designed to be used for flows involving authorization endpoint

If you need support for other grant types or authentication methods, please check some other implementations.

Getting started

Install with Maven:

<dependency>
    <groupId>com.scalepoint</groupId>
    <artifactId>oauth-token-client</artifactId>
    <version>1.1.1</version>
</dependency>

Obtaining access token from token endpoint is as simple as this:

private_key_jwt
ClientCredentialsGrantTokenClient tokenClient = new ClientCredentialsGrantTokenClient(
                                tokenEndpointUri,
                                new JwtBearerClientAssertionCredentials(
                                    tokenEndpointUri,
                                    clientId,
                                    keyPair
                          ));

String accessToken = tokenClient.getToken("scope1", "scope2");

Check here for how you can load "keyPair" from .jks or .pfx file containing only one certificate and key for test purposes.

client_secret
ClientCredentialsGrantTokenClient tokenClient = new ClientCredentialsGrantTokenClient(
                                tokenEndpointUri,
                                new ClientSecretCredentials(clientId, clientSecret)
                          );

String accessToken = tokenClient.getToken("scope1", "scope2");