Skip to content

Latest commit

 

History

History
47 lines (35 loc) · 1.47 KB

README.md

File metadata and controls

47 lines (35 loc) · 1.47 KB

Token Client

Provides clients for creating machine-to-machine and exchanging on-behalf-of tokens.

How to use

Add the following dependency:

<dependency>
    <groupId>no.nav.common</groupId>
    <artifactId>token-client</artifactId>
    <version>NEWEST_VERSION</version>
</dependency>

Creating Azure AD machine-to-machine token

When running on NAIS and the application is configured with Azure AD:

AzureAdMachineToMachineTokenClient tokenClient = AzureAdTokenClientBuilder.builder()
            .withNaisDefaults()
            .buildMachineToMachineTokenClient();
    
String accessToken = tokenClient.createMachineToMachineToken("api://<cluster>.<namespace>.<application>/.default");

Exchanging Azure AD on-behalf-of token

When running on NAIS and the application is configured with Azure AD:

AzureAdOnBehalfOfTokenClient tokenClient = AzureAdTokenClientBuilder.builder()
        .withNaisDefaults()
        .buildOnBehalfOfTokenClient();

String accessToken = tokenClient.exchangeOnBehalfOfToken("api://<cluster>.<namespace>.<application>/.default", "<access_token>");

Exchanging TokenX on-behalf-of token

When running on NAIS and the application is configured with TokenX:

TokenXOnBehalfOfTokenClient tokenClient = TokenXTokenClientBuilder.builder()
        .withNaisDefaults()
        .buildOnBehalfOfTokenClient(); 

String accessToken = tokenClient.exchangeOnBehalfOfToken("<cluster>:<namespace>:<application>", "<access_token>");