The "msi-auth-token-provider" jar is a library that enables :
- Azure VMs and container instances and
- Web Apps (funcitons included) Retrieve authentication tokens for syatem/user assigned managed identities.
This is a light weight library that does not have many dependencies.
Take a dependency on the jar in you pom file like follows
<dependencies>
<dependency>
<groupId>com.microsoft.azure.msi_auth_token_provider</groupId>
<artifactId>azure-authentication-msi-token-provider</artifactId>
<version>1.0.0-beta</version>
</dependency>
</dependencies>
Add the folowing import statement to get in all the classes in the jar
import com.microsoft.azure.msiAuthTokenProvider.*;
Use the following code to get the auth token for System assigned identity :
...
MSICredentials credsProvider = MSICredentials.getMSICredentials();
MSIToken token = credsProvider.getToken(null);
String tokenValue = token.accessToken();
...
Use the following code to get the auth token for an User assigned identity :
...
MSICredentials credsProvider = MSICredentials.getMSICredentials();
credsProvider.updateClientId(clientId);
MSIToken token = credsProvider.getToken(null);
String tokenValue = token.accessToken();
...
Where clientId
is retrieved from the User Assigned Identity (This is currently only supported from within the portal).
Use the following code to get the auth token for an User assigned identity :
...
MSICredentials credsProvider = MSICredentials.getMSICredentials();
credsProvider.updateObjectId(objectId);
MSIToken token = credsProvider.getToken(null);
String tokenValue = token.accessToken();
...
Where objectId
is retrieved from the User Assigned Identity (This is currently only supported from within the portal).