Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update TRC in Azure Core #24436

Merged
merged 2 commits into from
Sep 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sdk/core/azure-core-experimental/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Features Added

### Breaking Changes
- Removed `TokenRequestContenxtExperimental` class that allows to configure TenantId Challenges.

### Bugs Fixed

Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
exports com.azure.core.experimental.implementation;
exports com.azure.core.experimental.http;
exports com.azure.core.experimental.http.policy;
exports com.azure.core.experimental.credential;

uses com.azure.core.experimental.serializer.AvroSerializerProvider;
}
1 change: 1 addition & 0 deletions sdk/core/azure-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 1.21.0-beta.1 (Unreleased)

### Features Added
- Added `setTenantId` and `getTenantId` methods to `TokenRequestContext` class that allows to configure TenantId Challenges.

### Breaking Changes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
public class TokenRequestContext {
private final List<String> scopes;
private String claims;
private String tenantId;

/**
* Creates a token request instance.
Expand Down Expand Up @@ -77,4 +78,24 @@ public TokenRequestContext setClaims(String claims) {
public String getClaims() {
return this.claims;
}

/**
* Set the tenant id to be used for the authentication request.
*
* @param tenantId the tenant to be used when requesting the token.
* @return the updated TokenRequestContext itself
*/
public TokenRequestContext setTenantId(String tenantId) {
this.tenantId = tenantId;
return this;
}

/**
* Get the tenant id to be used for the authentication request.
*
* @return the configured tenant id.
*/
public String getTenantId() {
return this.tenantId;
}
}
7 changes: 1 addition & 6 deletions sdk/identity/azure-identity/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,7 @@
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core</artifactId>
<version>1.20.0</version> <!-- {x-version-update;com.azure:azure-core;dependency} -->
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core-experimental</artifactId>
<version>1.0.0-beta.18</version> <!-- {x-version-update;com.azure:azure-core-experimental;dependency} -->
<version>1.21.0-beta.1</version> <!-- {x-version-update;unreleased_com.azure:azure-core;dependency} -->
</dependency>
<dependency>
<groupId>com.azure</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public T httpClient(HttpClient client) {

/**
* Allows to override the tenant being used in the authentication request
* via {@link com.azure.core.experimental.credential.TokenRequestContextExperimental#setTenantId(String)}.
* via {@link com.azure.core.credential.TokenRequestContext#setTenantId(String)}.
*
* @return An updated instance of this builder.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import com.azure.core.credential.TokenRequestContext;
import com.azure.core.exception.ClientAuthenticationException;
import com.azure.core.experimental.credential.TokenRequestContextExperimental;
import com.azure.core.util.CoreUtils;
import com.azure.core.util.logging.ClientLogger;
import com.azure.identity.implementation.IdentityClientOptions;
Expand All @@ -24,13 +23,7 @@ private IdentityUtil() { }
public static String resolveTenantId(String currentTenantId, TokenRequestContext requestContext,
IdentityClientOptions options) {

String contextTenantId;
if (requestContext instanceof TokenRequestContextExperimental) {
TokenRequestContextExperimental experimental = ((TokenRequestContextExperimental) requestContext);
contextTenantId = experimental.getTenantId();
} else {
return currentTenantId;
}
String contextTenantId = requestContext.getTenantId();

if (!options.isMultiTenantAuthenticationAllowed()) {
if (contextTenantId != null && !currentTenantId.equals(contextTenantId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

module com.azure.identity {
requires transitive com.azure.core;
requires transitive com.azure.core.experimental;

requires msal4j;
requires msal4j.persistence.extension;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

package com.azure.identity.util;

import com.azure.core.credential.TokenRequestContext;
import com.azure.core.exception.ClientAuthenticationException;
import com.azure.core.experimental.credential.TokenRequestContextExperimental;
import com.azure.identity.implementation.IdentityClientOptions;
import com.azure.identity.implementation.util.IdentityUtil;
import org.junit.Assert;
Expand All @@ -20,7 +20,7 @@ public class IdentityUtilTests {
public void testMultiTenantAuthenticationEnabled() throws Exception {
String currentTenant = "tenant";
String newTenant = "tenant-new";
TokenRequestContextExperimental trc = new TokenRequestContextExperimental()
TokenRequestContext trc = new TokenRequestContext()
.setScopes(Arrays.asList("http://vault.azure.net/.default"))
.setTenantId(newTenant);
IdentityClientOptions options = new IdentityClientOptions();
Expand All @@ -33,7 +33,7 @@ public void testMultiTenantAuthenticationEnabled() throws Exception {
public void testMultiTenantAuthenticationDisabled() throws Exception {
String currentTenant = "tenant";
String newTenant = "tenant-new";
TokenRequestContextExperimental trc = new TokenRequestContextExperimental()
TokenRequestContext trc = new TokenRequestContext()
.setScopes(Arrays.asList("http://vault.azure.net/.default"))
.setTenantId("newTenant");
IdentityClientOptions options = new IdentityClientOptions();
Expand Down