Skip to content

Commit 9a24b5d

Browse files
authored
Init Azure Identity VNext (Azure#44247)
1 parent 6338222 commit 9a24b5d

File tree

54 files changed

+4879
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+4879
-0
lines changed

.vscode/cspell.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@
136136
"sdk/cosmos/azure-cosmos/**",
137137
"sdk/cosmos/azure-cosmos-test/**",
138138
"sdk/identity/azure-identity/**",
139+
"sdk/identity/azure-identity-v2/**",
139140
"sdk/keyvault/azure-security-keyvault-administration/**",
140141
"sdk/keyvault/azure-security-keyvault-certificates/**",
141142
"sdk/keyvault/azure-security-keyvault-jca/**",

eng/versioning/external_dependencies.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ io.reactivex.rxjava2:rxjava;2.2.21
171171
net.java.dev.jna:jna-platform;5.13.0
172172
net.oneandone.reflections8:reflections8;0.11.7
173173
net.jonathangiles.tools:dependencyChecker-maven-plugin;1.0.6
174+
net.bytebuddy:byte-buddy;1.14.10
174175
org.apache.commons:commons-collections4;4.4
175176
org.apache.commons:commons-text;1.10.0
176177
org.apache.maven:maven-plugin-api;3.9.9

eng/versioning/version_client.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ com.azure:azure-health-insights-clinicalmatching;1.0.0-beta.1;1.0.0-beta.2
131131
com.azure:azure-health-insights-cancerprofiling;1.0.0-beta.1;1.0.0-beta.2
132132
com.azure:azure-health-insights-radiologyinsights;1.0.0;1.1.0-beta.1
133133
com.azure:azure-identity;1.15.3;1.16.0-beta.1
134+
com.azure:azure-identity-v2;2.0.0-beta.1;2.0.0-beta.1
134135
com.azure:azure-identity-extensions;1.2.1;1.3.0-beta.1
135136
com.azure:azure-identity-broker;1.1.12;1.2.0-beta.1
136137
com.azure:azure-identity-broker-samples;1.0.0-beta.1;1.0.0-beta.1
@@ -496,6 +497,7 @@ io.clientcore:annotation-processor-test;1.0.0-beta.1;1.0.0-beta.1
496497

497498
unreleased_com.azure:azure-json;1.5.0-beta.1
498499
unreleased_io.clientcore:core;1.0.0-beta.6
500+
unreleased_com.azure:azure-core-v2;2.0.0-beta.1
499501

500502
# Released Beta dependencies: Copy the entry from above, prepend "beta_", remove the current
501503
# version and set the version to the released beta. Released beta dependencies are only valid
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Release History
2+
3+
## 2.0.0-beta.1 (Unreleased)
4+
5+
### Features Added
6+
7+
### Breaking Changes
8+
9+
### Bugs Fixed
10+
11+
### Other Changes
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Azure Identity client library for Java
2+
3+
The Azure Identity V2 library provides [Microsoft Entra ID](https://learn.microsoft.com/entra/fundamentals/whatis) ([formerly Azure Active Directory](https://learn.microsoft.com/entra/fundamentals/new-name)) token authentication support across the Azure SDK.
4+
5+
## Getting started
6+
7+
### Include the package
8+
9+
#### Include the BOM file
10+
11+
#### Include direct dependency
12+
13+
To take dependency on a particular version of the library that isn't present in the BOM, add the direct dependency to your project as follows:
14+
15+
[//]: # ({x-version-update-start;com.azure:azure-identity-v2;dependency})
16+
```xml
17+
<dependency>
18+
<groupId>com.azure</groupId>
19+
<artifactId>azure-identity-v2</artifactId>
20+
<version>2.0.0-beta.1</version>
21+
</dependency>
22+
```
23+
[//]: # ({x-version-update-end})
24+
25+
### Prerequisites
26+
27+
### Authenticate the client
28+
29+
## Key concepts
30+
31+
## Examples
32+
33+
34+
## Troubleshooting
35+
36+
37+
## Next steps
38+
39+
40+
## Contributing
41+
42+
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.
43+
44+
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.
45+
46+
This project has adopted the [Microsoft Open Source Code of Conduct][code_of_conduct]. For more information, see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.
47+
48+
<!-- LINKS -->
49+
[code_of_conduct]: https://opensource.microsoft.com/codeofconduct/
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<parent>
6+
<groupId>com.azure</groupId>
7+
<artifactId>azure-client-sdk-parent-v2</artifactId>
8+
<version>1.0.0-beta.1</version> <!-- {x-version-update;com.azure:azure-client-sdk-parent-v2;current} -->
9+
<relativePath>../../parents/azure-client-sdk-parent-v2</relativePath>
10+
</parent>
11+
12+
<groupId>com.azure</groupId>
13+
<artifactId>azure-identity-v2</artifactId>
14+
<packaging>jar</packaging>
15+
<version>2.0.0-beta.1</version> <!-- {x-version-update;com.azure:azure-identity-v2;current} -->
16+
17+
<name>Microsoft Azure Identity V2 Library</name>
18+
<description>This package contains core types for Azure Java V2 clients.</description>
19+
<url>https://github.com/Azure/azure-sdk-for-java</url>
20+
21+
<licenses>
22+
<license>
23+
<name>The MIT License (MIT)</name>
24+
<url>http://opensource.org/licenses/MIT</url>
25+
<distribution>repo</distribution>
26+
</license>
27+
</licenses>
28+
29+
<distributionManagement>
30+
<site>
31+
<id>azure-java-build-docs</id>
32+
<url>${site.url}/site/${project.artifactId}</url>
33+
</site>
34+
</distributionManagement>
35+
36+
<scm>
37+
<url>https://github.com/Azure/azure-sdk-for-java</url>
38+
<connection>scm:git:https://github.com/Azure/azure-sdk-for-java.git</connection>
39+
<developerConnection>scm:git:https://github.com/Azure/azure-sdk-for-java.git</developerConnection>
40+
</scm>
41+
42+
<properties>
43+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
44+
<legal><![CDATA[[INFO] Any downloads listed may be third party software. Microsoft grants you no rights for third party software.]]></legal>
45+
<jacoco.min.linecoverage>0.10</jacoco.min.linecoverage> <!-- Temporary until full breadth of test coverage is added -->
46+
<jacoco.min.branchcoverage>0.10</jacoco.min.branchcoverage> <!-- Temporary until full breadth of test coverage is added -->
47+
</properties>
48+
49+
<developers>
50+
<developer>
51+
<id>microsoft</id>
52+
<name>Microsoft</name>
53+
</developer>
54+
</developers>
55+
56+
57+
<dependencies>
58+
<dependency>
59+
<groupId>com.azure</groupId>
60+
<artifactId>azure-core-v2</artifactId>
61+
<version>2.0.0-beta.1</version> <!-- {x-version-update;unreleased_com.azure:azure-core-v2;dependency} -->
62+
</dependency>
63+
64+
<dependency>
65+
<groupId>com.microsoft.azure</groupId>
66+
<artifactId>msal4j-persistence-extension</artifactId>
67+
<version>1.3.0</version> <!-- {x-version-update;com.microsoft.azure:msal4j-persistence-extension;external_dependency} -->
68+
</dependency>
69+
70+
<dependency>
71+
<groupId>com.microsoft.azure</groupId>
72+
<artifactId>msal4j</artifactId>
73+
<version>1.19.0</version> <!-- {x-version-update;com.microsoft.azure:msal4j;external_dependency} -->
74+
</dependency>
75+
76+
<dependency>
77+
<groupId>org.junit.jupiter</groupId>
78+
<artifactId>junit-jupiter-api</artifactId>
79+
<version>5.11.2</version> <!-- {x-version-update;org.junit.jupiter:junit-jupiter-api;external_dependency} -->
80+
<scope>test</scope>
81+
</dependency>
82+
83+
<dependency>
84+
<groupId>org.junit.jupiter</groupId>
85+
<artifactId>junit-jupiter-engine</artifactId>
86+
<version>5.11.2</version> <!-- {x-version-update;org.junit.jupiter:junit-jupiter-engine;external_dependency} -->
87+
<scope>test</scope>
88+
</dependency>
89+
90+
<dependency>
91+
<groupId>org.junit.jupiter</groupId>
92+
<artifactId>junit-jupiter-params</artifactId>
93+
<version>5.11.2</version> <!-- {x-version-update;org.junit.jupiter:junit-jupiter-params;external_dependency} -->
94+
<scope>test</scope>
95+
</dependency>
96+
97+
<dependency>
98+
<groupId>org.mockito</groupId>
99+
<artifactId>mockito-inline</artifactId>
100+
<version>4.11.0</version> <!-- {x-version-update;org.mockito:mockito-inline;external_dependency} -->
101+
<scope>test</scope>
102+
</dependency>
103+
104+
<dependency>
105+
<groupId>net.bytebuddy</groupId>
106+
<artifactId>byte-buddy</artifactId>
107+
<version>1.14.10</version><!-- {x-version-update;net.bytebuddy:byte-buddy;external_dependency} -->
108+
<scope>test</scope>
109+
</dependency>
110+
111+
</dependencies>
112+
113+
<build>
114+
<plugins>
115+
<plugin>
116+
<groupId>org.apache.maven.plugins</groupId>
117+
<artifactId>maven-enforcer-plugin</artifactId>
118+
<version>3.5.0</version> <!-- {x-version-update;org.apache.maven.plugins:maven-enforcer-plugin;external_dependency} -->
119+
<configuration>
120+
<rules>
121+
<bannedDependencies>
122+
<includes>
123+
<include>com.microsoft.azure:msal4j:[1.19.0]</include> <!-- {x-include-update;com.microsoft.azure:msal4j;external_dependency} -->
124+
<include>com.microsoft.azure:msal4j-persistence-extension:[1.3.0]</include> <!-- {x-include-update;com.microsoft.azure:msal4j-persistence-extension;external_dependency} -->
125+
</includes>
126+
</bannedDependencies>
127+
</rules>
128+
</configuration>
129+
</plugin>
130+
</plugins>
131+
</build>
132+
133+
</project>
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.azure.identity.v2;
5+
6+
import com.microsoft.aad.msal4j.IAuthenticationResult;
7+
import io.clientcore.core.instrumentation.logging.ClientLogger;
8+
import io.clientcore.core.serialization.json.JsonReader;
9+
import io.clientcore.core.serialization.json.JsonToken;
10+
import io.clientcore.core.serialization.json.JsonWriter;
11+
12+
import java.io.IOException;
13+
import java.io.InputStream;
14+
import java.io.OutputStream;
15+
16+
/**
17+
* <p>Authentication Record represents the account information of the authenticated account.
18+
* This is helpful in scenarios where applications require brokered authentication via
19+
* {@link InteractiveBrowserCredential}.</p>
20+
*
21+
* <p>Authentication record is returned when {@link InteractiveBrowserCredential#authenticate()} api is invoked.
22+
* The returned auth record can be stored/persisted in the user application. Further, this record can be configured on
23+
* the {@link InteractiveBrowserCredentialBuilder#authenticationRecord(AuthenticationRecord)} to proactively indicate
24+
* that a previously authenticated account should be used from the persisted cache instead of authenticating again.</p>
25+
*
26+
* @see InteractiveBrowserCredential
27+
*/
28+
public final class AuthenticationRecord {
29+
30+
static final ClientLogger LOGGER = new ClientLogger(AuthenticationRecord.class);
31+
32+
private String authority;
33+
34+
private String homeAccountId;
35+
36+
private String tenantId;
37+
38+
private String username;
39+
40+
private String clientId;
41+
42+
AuthenticationRecord() {
43+
}
44+
45+
AuthenticationRecord(IAuthenticationResult authenticationResult, String tenantId, String clientId) {
46+
this(authenticationResult.account().environment(), authenticationResult.account().homeAccountId(),
47+
authenticationResult.account().username(), tenantId, clientId);
48+
}
49+
50+
AuthenticationRecord(String authority, String homeAccountId, String userName, String tenantId, String clientId) {
51+
this.authority = authority;
52+
this.homeAccountId = homeAccountId;
53+
this.tenantId = tenantId;
54+
this.username = userName;
55+
this.clientId = clientId;
56+
}
57+
58+
/**
59+
* Get the authority host used to authenticate the account.
60+
*
61+
* @return the authority host.
62+
*/
63+
public String getAuthority() {
64+
return authority;
65+
}
66+
67+
/**
68+
* Get the unique identifier of the account.
69+
*
70+
* @return the account id.
71+
*/
72+
public String getHomeAccountId() {
73+
return homeAccountId;
74+
}
75+
76+
/**
77+
* Get the tenant, which the account authenticated in.
78+
*
79+
* @return the tenant id.
80+
*/
81+
public String getTenantId() {
82+
return tenantId;
83+
}
84+
85+
/**
86+
* Get the client id of the application used for authentication.
87+
*
88+
* @return the client id.
89+
*/
90+
public String getClientId() {
91+
return clientId;
92+
}
93+
94+
/**
95+
* Get the user principal name of the account.
96+
*
97+
* @return the username.
98+
*/
99+
public String getUsername() {
100+
return username;
101+
}
102+
103+
/**
104+
* Serializes the {@link AuthenticationRecord} to the specified {@link OutputStream}
105+
*
106+
* @param outputStream The {@link OutputStream} to which the serialized record will be written to.
107+
*/
108+
public void serialize(OutputStream outputStream) {
109+
try (JsonWriter writer = JsonWriter.toStream(outputStream)) {
110+
writer.writeStartObject();
111+
writer.writeStringField("authority", authority);
112+
writer.writeStringField("homeAccountId", homeAccountId);
113+
writer.writeStringField("tenantId", tenantId);
114+
writer.writeStringField("username", username);
115+
writer.writeStringField("clientId", clientId);
116+
writer.writeEndObject();
117+
} catch (IOException e) {
118+
throw LOGGER.logThrowableAsError(new RuntimeException(e));
119+
}
120+
}
121+
122+
/**
123+
* Deserializes the {@link AuthenticationRecord} from the specified {@link InputStream}
124+
*
125+
* @param inputStream The {@link InputStream} from which the serialized record will be read.
126+
* @return the {@link AuthenticationRecord} object.
127+
*/
128+
public static AuthenticationRecord deserialize(InputStream inputStream) {
129+
try (JsonReader jsonReader = JsonReader.fromStream(inputStream)) {
130+
return jsonReader.readObject(reader -> {
131+
String authority = null;
132+
String homeAccountId = null;
133+
String tenantId = null;
134+
String username = null;
135+
String clientId = null;
136+
while (reader.nextToken() != JsonToken.END_OBJECT) {
137+
String fieldName = reader.getFieldName();
138+
reader.nextToken();
139+
if ("authority".equals(fieldName)) {
140+
authority = reader.getString();
141+
} else if ("homeAccountId".equals(fieldName)) {
142+
homeAccountId = reader.getString();
143+
} else if ("tenantId".equals(fieldName)) {
144+
tenantId = reader.getString();
145+
} else if ("username".equals(fieldName)) {
146+
username = reader.getString();
147+
} else if ("clientId".equals(fieldName)) {
148+
clientId = reader.getString();
149+
} else {
150+
reader.skipChildren();
151+
}
152+
}
153+
return new AuthenticationRecord(authority, homeAccountId, username, tenantId, clientId);
154+
});
155+
} catch (IOException e) {
156+
throw LOGGER.logThrowableAsError(new RuntimeException(e));
157+
}
158+
}
159+
}

0 commit comments

Comments
 (0)