Azure Authentication and Authorization using java

1k views Asked by At

How to authenticate azure using java with azure management or client libraries without directly using azure rest API's? and what are the jars required for this?

Please help with samples.

1

There are 1 answers

1
Carl Zhao On BEST ANSWER

If you want to use JAVA with Azure management for authentication, you can use the following two methods:

1.Create an instance of ApplicationTokenCredentials to supply the service principal credentials to the top-level Azure object from inside your code:

import com.microsoft.azure.credentials.ApplicationTokenCredentials;
import com.microsoft.azure.AzureEnvironment;

// ...

ApplicationTokenCredentials credentials = new ApplicationTokenCredentials(client,
        tenant,
        key,
        AzureEnvironment.AZURE);

Azure azure = Azure
        .configure()
        .withLogLevel(LogLevel.NONE)
        .authenticate(credentials)
        .withDefaultSubscription();

2.File based authentication:

# sample management library properties file
subscription=########-####-####-####-############
client=########-####-####-####-############
key=XXXXXXXXXXXXXXXX
tenant=########-####-####-####-############
managementURI=https\://management.core.windows.net/
baseURL=https\://management.azure.com/
authURL=https\://login.windows.net/
graphURL=https\://graph.windows.net/

please check:here