DISCLAIMER: The samples in this readme are for azure-authentication-msi-token-provider. This SDK has been deprecated.
Please use azure-identity for authentication support. If you have existing code that uses the library, please use the Migration Guide to migrate to azure-identity
.
The "msi-auth-token-provider" jar is a library that enables :
- Azure VMs and container instances and
- Web Apps (functions included) Retrieve authentication tokens for system/user assigned managed identities.
This is a lightweight library that does not have many dependencies.
Take a dependency on the library in your pom file like the following
<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 following 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 a 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).