Skip to content

Commit e34e382

Browse files
Avery-DunnSomkaPeRomanNosachovSantiago Gonzalezsangonzal
authored
1.8.1 release (#327)
* Exception Improvements (#254) * Add null checks for MsalException error code references * Better exception handling for invalid tokens * Better exception handling for invalid tokens * Sync with changes to Azure-Samples/ms-identity-java-desktop (#259) * extra scopes for consent during authorizaion * typo * minor * HTTPClient default timeouts (#264) * Add default timeouts for DefaultHttpClient * Handle 'stay signed in' confirmation page in DeviceCodeIT tests * Small best-practices changes * append extra scopes as suffix * 1.6.2 release (#268) * fixing integ test * Tenant Profiles (#263) * Classes for tenant profile functionality * Implement tenant profile feature * Tests for tenant profile feature * Simplify tenant profile class structure * 1.6.2 release * Classes for tenant profile redesign * Tests for tenant profile redesign * Adjust sample cached ID tokens to have realistic headers * Redesign how Tenant Pofiles are added to Accounts * New error code for JWT parse exceptions * Add claims and tenant profiles fields to Account * Remove annotation excluding realm field from comparisons * Use more generic token * Remove ID token claims field from Account * Minor changes for clarity * Adjust tests for tenant profile design refactor * Refactor tenant profile structure * Minor fixes * Minor fixes * Minor fixes * Simplify tenant profile class Co-authored-by: SomkaPe <[email protected]> * Improve HTTP client timeouts (#275) * 1.6.2 release (#269) * 1.6.2 release * Make DefaultHttpClient timeouts settable * Refactor timeout names Co-authored-by: SomkaPe <[email protected]> * Bewaters certchain (#276) * Support for certificate chain * 1.7.0 release (#277) * Update DefaultHttpClient.java * Fixed parsing ClientInfo: on some accounts, the server response contained characters that are incorrect for Base64 encoding, but acceptable for Base64URL (#282) * sendX5c api (#285) * refactoring (#287) * refactoring * refactoring * refactoring * Add AcquireTokenSilent tests for B2C and ADFS2019, refactor duplicate code in tests (#293) * Add public constants for cloud endpoints (#298) * Add public constants for cloud endpoints * Add license header * Added javadocs * Removed unneeded test * Make IAccount serializable (#297) * Make IAccount objects serializable * Make AuthenticationResult objects not serializable * Add tenant profile/id claims to auth result (#300) * Add tenant profile/id claims to auth result * Minor fix * treat null password as default one - empty string (#304) * treat null password as default one - empty string * Support for refresh_in (#305) * Support for refresh_in * Tests for refresh_in * Add extra null check * Add test for refreshOn cache persistence * refresh on is optional field (#312) * refresh on optional field * 1.8.0 Release (#313) 1.8.0 release * Fix spelling mistake in Prompt.java * Remove use of Nimbus Oauth2 SDK's CommonContentTypes (#322) * Remove use of Nimbus Oauth2 SDK's CommonContentTypes * Add enum for HTTP content-type constants * Remove use of javax.mail.internet.ContentType * Support for claims request parameter (#315) * ClaimsRequest classes * Support for claims request parameter * Tests for claims request * Use Jackson library for JSON processing * Change access level of userinfo and access_token claims * Better merge tests * Remove ability to set claims in userinfo field * Refactor claims field naming * 1.8.1 release (#326) * Version number updates for 1.8.1 release * Minor rewording Co-authored-by: SomkaPe <[email protected]> Co-authored-by: Roman Nosachev <[email protected]> Co-authored-by: Santiago Gonzalez <[email protected]> Co-authored-by: Santiago Gonzalez <[email protected]>
1 parent cacad3d commit e34e382

Some content is hidden

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

43 files changed

+385
-51
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Quick links:
1616
The library supports the following Java environments:
1717
- Java 8 (or higher)
1818

19-
Current version - 1.8.0
19+
Current version - 1.8.1
2020

2121
You can find the changes for each version in the [change log](https://github.com/AzureAD/microsoft-authentication-library-for-java/blob/master/changelog.txt).
2222

@@ -28,13 +28,13 @@ Find [the latest package in the Maven repository](https://mvnrepository.com/arti
2828
<dependency>
2929
<groupId>com.microsoft.azure</groupId>
3030
<artifactId>msal4j</artifactId>
31-
<version>1.8.0</version>
31+
<version>1.8.1</version>
3232
</dependency>
3333
```
3434
### Gradle
3535

3636
```
37-
compile group: 'com.microsoft.azure', name: 'msal4j', version: '1.8.0'
37+
compile group: 'com.microsoft.azure', name: 'msal4j', version: '1.8.1'
3838
```
3939

4040
## Usage

changelog.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
Version 1.8.1
2+
=============
3+
- New ClaimsRequest class to allow ID token claims to be requested as part of any token request
4+
- Remove use of nimbusds.oauth2.sdk CommonContentTypes
5+
16
Version 1.8.0
27
=============
38
- ITenantProfile added to IAuthenticationResult for easier access to ID token claims

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>com.microsoft.azure</groupId>
55
<artifactId>msal4j</artifactId>
6-
<version>1.8.0</version>
6+
<version>1.8.1</version>
77
<packaging>jar</packaging>
88
<name>msal4j</name>
99
<description>

src/main/java/com/microsoft/aad/msal4j/AbstractMsalAuthorizationGrant.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,10 @@ abstract class AbstractMsalAuthorizationGrant {
3434
String getScopes() {
3535
return scopes;
3636
}
37+
38+
ClaimsRequest claims;
39+
40+
ClaimsRequest getClaims() {
41+
return claims;
42+
}
3743
}

src/main/java/com/microsoft/aad/msal4j/AcquireTokenByAuthorizationGrantSupplier.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ AuthenticationResult execute() throws Exception {
4848
(IntegratedWindowsAuthorizationGrant) authGrant;
4949
msalRequest.msalAuthorizationGrant =
5050
new OAuthAuthorizationGrant(getAuthorizationGrantIntegrated(
51-
integratedAuthGrant.getUserName()), integratedAuthGrant.getScopes());
51+
integratedAuthGrant.getUserName()), integratedAuthGrant.getScopes(), integratedAuthGrant.getClaims());
5252
}
5353

5454
if (requestAuthority == null) {

src/main/java/com/microsoft/aad/msal4j/AcquireTokenByInteractiveFlowSupplier.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ private AuthenticationResult acquireTokenWithAuthorizationCode(AuthorizationResu
149149
.builder(authorizationResult.code(), interactiveRequest.interactiveRequestParameters().redirectUri())
150150
.scopes(interactiveRequest.interactiveRequestParameters().scopes())
151151
.codeVerifier(interactiveRequest.verifier())
152+
.claims(interactiveRequest.interactiveRequestParameters().claims())
152153
.build();
153154

154155
AuthorizationCodeRequest authCodeRequest = new AuthorizationCodeRequest(

src/main/java/com/microsoft/aad/msal4j/AuthorizationCodeParameters.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ public class AuthorizationCodeParameters implements IApiParameters {
4141
*/
4242
private Set<String> scopes;
4343

44+
/**
45+
* Claims to be requested through the OIDC claims request parameter, allowing requests for standard and custom claims
46+
*/
47+
private ClaimsRequest claims;
48+
4449
/**
4550
* Code verifier used for PKCE. For more details, see https://tools.ietf.org/html/rfc7636
4651
*/

src/main/java/com/microsoft/aad/msal4j/AuthorizationCodeRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ private static AbstractMsalAuthorizationGrant createMsalGrant(AuthorizationCodeP
3030
new AuthorizationCode(parameters.authorizationCode()),parameters.redirectUri());
3131
}
3232

33-
return new OAuthAuthorizationGrant(authorizationGrant, parameters.scopes());
33+
return new OAuthAuthorizationGrant(authorizationGrant, parameters.scopes(), parameters.claims());
3434
}
3535
}

src/main/java/com/microsoft/aad/msal4j/AuthorizationRequestUrlParameters.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,15 @@ private AuthorizationRequestUrlParameters(Builder builder){
8181
requestParameters.put("claims", Collections.singletonList(builder.claimsChallenge));
8282
}
8383

84+
if(builder.claimsRequest != null){
85+
String claimsRequest = builder.claimsRequest.formatAsJSONString();
86+
//If there are other claims (such as part of a claims challenge), merge them with this claims request.
87+
if (requestParameters.get("claims") != null) {
88+
claimsRequest = JsonHelper.mergeJSONString(claimsRequest, requestParameters.get("claims").get(0));
89+
}
90+
requestParameters.put("claims", Collections.singletonList(claimsRequest));
91+
}
92+
8493
if(builder.codeChallenge != null){
8594
this.codeChallenge = builder.codeChallenge;
8695
requestParameters.put("code_challenge", Collections.singletonList(builder.codeChallenge));
@@ -154,6 +163,7 @@ public static class Builder {
154163
private Set<String> extraScopesToConsent;
155164
private Set<String> claims;
156165
private String claimsChallenge;
166+
private ClaimsRequest claimsRequest;
157167
private String codeChallenge;
158168
private String codeChallengeMethod;
159169
private String state;
@@ -202,22 +212,17 @@ public Builder extraScopesToConsent(Set<String> val){
202212
* In cases where Azure AD tenant admin has enabled conditional access policies, and the
203213
* policy has not been met,{@link MsalServiceException} will contain claims that need be
204214
* consented to.
205-
*
206-
* Deprecated in favor of {@link #claimsChallenge(String)}
207215
*/
208-
@Deprecated
209-
public Builder claims(Set<String> val){
210-
this.claims = val;
216+
public Builder claimsChallenge(String val){
217+
this.claimsChallenge = val;
211218
return self();
212219
}
213220

214221
/**
215-
* In cases where Azure AD tenant admin has enabled conditional access policies, and the
216-
* policy has not been met,{@link MsalServiceException} will contain claims that need be
217-
* consented to.
222+
* Claims to be requested through the OIDC claims request parameter, allowing requests for standard and custom claims
218223
*/
219-
public Builder claimsChallenge(String val){
220-
this.claimsChallenge = val;
224+
public Builder claims(ClaimsRequest val){
225+
this.claimsRequest = val;
221226
return self();
222227
}
223228

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.microsoft.aad.msal4j;
5+
6+
import com.fasterxml.jackson.databind.ObjectMapper;
7+
import com.fasterxml.jackson.databind.node.ObjectNode;
8+
import lombok.Getter;
9+
import lombok.Setter;
10+
import java.util.ArrayList;
11+
import java.util.List;
12+
13+
/**
14+
* Represents the claims request parameter as an object
15+
*
16+
* @see <a href="https://openid.net/specs/openid-connect-core-1_0-final.html#ClaimsParameter">https://openid.net/specs/openid-connect-core-1_0-final.html#ClaimsParameter</a>
17+
*/
18+
public class ClaimsRequest {
19+
20+
@Getter
21+
@Setter
22+
List<RequestedClaim> idTokenRequestedClaims = new ArrayList<>();
23+
24+
List<RequestedClaim> userInfoRequestedClaims = new ArrayList<>();
25+
List<RequestedClaim> accessTokenRequestedClaims = new ArrayList<>();
26+
27+
/**
28+
* Inserts a claim into the list of claims to be added to the "id_token" section of an OIDC claims request
29+
*
30+
* @param claim the name of the claim to be requested
31+
* @param requestedClaimAdditionalInfo additional information about the claim being requested
32+
*/
33+
public void requestClaimInIdToken(String claim, RequestedClaimAdditionalInfo requestedClaimAdditionalInfo) {
34+
idTokenRequestedClaims.add(new RequestedClaim(claim, requestedClaimAdditionalInfo));
35+
}
36+
37+
/**
38+
* Inserts a claim into the list of claims to be added to the "access_token" section of an OIDC claims request
39+
*
40+
* @param claim the name of the claim to be requested
41+
* @param requestedClaimAdditionalInfo additional information about the claim being requested
42+
*/
43+
protected void requestClaimInAccessToken(String claim, RequestedClaimAdditionalInfo requestedClaimAdditionalInfo) {
44+
accessTokenRequestedClaims.add(new RequestedClaim(claim, requestedClaimAdditionalInfo));
45+
}
46+
47+
/**
48+
* Converts the ClaimsRequest object to a JSON-formatted String which follows the specification for the OIDC claims request parameter
49+
*
50+
* @return a String following JSON formatting
51+
*/
52+
public String formatAsJSONString() {
53+
ObjectMapper mapper = new ObjectMapper();
54+
ObjectNode rootNode = mapper.createObjectNode();
55+
56+
if (!idTokenRequestedClaims.isEmpty()) {
57+
rootNode.set("id_token", convertClaimsToObjectNode(idTokenRequestedClaims));
58+
}
59+
if (!userInfoRequestedClaims.isEmpty()) {
60+
rootNode.set("userinfo", convertClaimsToObjectNode(userInfoRequestedClaims));
61+
}
62+
if (!accessTokenRequestedClaims.isEmpty()) {
63+
rootNode.set("access_token", convertClaimsToObjectNode(accessTokenRequestedClaims));
64+
}
65+
66+
return mapper.valueToTree(rootNode).toString();
67+
}
68+
69+
private ObjectNode convertClaimsToObjectNode(List<RequestedClaim> claims) {
70+
ObjectMapper mapper = new ObjectMapper();
71+
ObjectNode claimsNode = mapper.createObjectNode();
72+
73+
for (RequestedClaim claim: claims) {
74+
claimsNode.setAll((ObjectNode) mapper.valueToTree(claim));
75+
}
76+
return claimsNode;
77+
}
78+
}

0 commit comments

Comments
 (0)