Provides clients for creating machine-to-machine and exchanging on-behalf-of tokens.
Add the following dependency:
<dependency>
<groupId>no.nav.common</groupId>
<artifactId>token-client</artifactId>
<version>NEWEST_VERSION</version>
</dependency>
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");
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>");
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>");