-
Notifications
You must be signed in to change notification settings - Fork 2k
Getting Started
Download via Maven snapshot repo:
<repositories>
<repository>
<id>adx-snapshots</id>
<name>Azure ADX Snapshots</name>
<url>http://adxsnapshots.azurewebsites.net/</url>
<layout>default</layout>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
...
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
or Gradle:
repositories {
maven { url "http://adxsnapshots.azurewebsites.net/" }
....
}
...
dependencies {
compile 'com.microsoft.azure:azure:1.0.0-SNAPSHOT'
....
}
Creating a service client is simple. Every Azure Resource Manager client provides 4 constructors to use with simple parameters.
ComputeManagementClient client;
// Default environment, no credentials
client = new ComputeManagementClientImpl();
// Custom environment with AzureChinaCloud endpoint
String chinaCloudEndpoint = "https://management.chinacloudapi.cn/";
client = new ComputeManagementClientImpl(chinaCloudEndpoint);
// Default environment with credentials
ApplicationTokenCredentials credentials = new ApplicationTokenCredentials(
"client-id", "tenant-id", "secret", null);
client = new ComputeManagementClientImpl(credentials);
// Custom environment with credentials
client = new ComputeManagementClientImpl(chinaCloudEndpoint, credentials);
// Fully customized, with HTTP client and Retrofit modifiable
client = new ComputeManagementClientImpl(
chinaCloudEndpoint,
credentials,
new OkHttpClient.Builder(),
new Retrofit.Builder());
Please see Authentication for more information about creating credentials.
Azure SDK for Java does not provide direct authentication to Azure. However, interceptors pluggable into the OkHttp client have been provided for injecting tokens into HTTP requests.
We provide separate libraries for authenticating through Azure Active Directory. They are azure-client-authentication
and azure-android-client-authentication
, for JDK and Android respectively. They are pluggable into the interceptors we provide in the SDK to feed the tokens.
In azure-client-authentication
, 2 authentication credentials are provided:
UserTokenCredentials credentials = new UserTokenCredentials(
"client-id",
"tenant-id/domain",
"username",
"password",
"client-redirect-uri",
AzureEnvironment.Azure);
Information about client ID, and client redirect URI are retrieved from your application in the Azure Active Directory.
This scenario is useful for interactive apps running on JDK. However, as of ADAL4j 1.1.2 two-factor-auth has not been supported yet.
ApplicationTokenCredentials credentials = new ApplicationTokenCredentials(
"client-id",
"tenant-id/domain",
"secret",
AzureEnvironment.Azure);
Information about client ID, and client redirect URI are retrieved from your application in the Azure Active Directory.
This scenario is useful for most service principal based authentications. For a reference on setting up a service principal from the command line see Authenticating a service principal with Azure Resource Manager or Unattended Authentication. For a more robust explanation of authentication in Azure, see Developer’s guide to auth with Azure Resource Manager API.
In azure-android-client-authentication
, only UserTokenCredentials
is provided because interactive flow is supported for authentication on Android.
// Simpler constructor
UserTokenCredentials credentials = new UserTokenCredentials(
getApplicationContext(),
"client-id",
"tenant-id/domain",
"client-redirect-uri");
// Detailed constructor
UserTokenCredentials credentials = new UserTokenCredentials(
getApplicationContext(),
"client-id",
"tenant-id/domain",
"client-redirect-uri",
PromptBehavior.Always,
AzureEnvironment.Azure);
An android Activity
object is required for the 1st argument, simply for shared preference access. When authentication is needed, a login window will prompt and ask for credentials. Once the authentication is done, it goes back to the previous activity from which the login window is prompted.
Two factor auth is supported on Android.
- Frequently Asked Questions
- Azure Identity Examples
- Configuration
- Performance Tuning
- Android Support
- Unit Testing
- Test Proxy Migration
- Azure Json Migration
- New Checkstyle and Spotbugs pattern migration
- Protocol Methods
- TypeSpec-Java Quickstart
- Getting Started Guidance
- Adding a Module
- Building
- Writing Performance Tests
- Working with AutoRest
- Deprecation
- BOM guidelines
- Release process
- Access helpers