-
Notifications
You must be signed in to change notification settings - Fork 148
Support for claims request parameter #315
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
43035bd
ClaimsRequest classes
Avery-Dunn 973c366
Support for claims request parameter
Avery-Dunn 133c1d4
Tests for claims request
Avery-Dunn 54c4eb7
Use Jackson library for JSON processing
Avery-Dunn c26c78f
Change access level of userinfo and access_token claims
Avery-Dunn a566f48
Better merge tests
Avery-Dunn 88c03ec
Remove ability to set claims in userinfo field
Avery-Dunn c36fb7e
Refactor claims field naming
Avery-Dunn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package com.microsoft.aad.msal4j; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.node.ObjectNode; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Represents the claims request parameter as an object | ||
* | ||
* @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> | ||
*/ | ||
public class ClaimsRequest { | ||
|
||
@Getter | ||
@Setter | ||
List<RequestedClaim> idTokenRequestedClaims = new ArrayList<>(); | ||
|
||
List<RequestedClaim> userInfoRequestedClaims = new ArrayList<>(); | ||
List<RequestedClaim> accessTokenRequestedClaims = new ArrayList<>(); | ||
|
||
/** | ||
* Inserts a claim into the list of claims to be added to the "id_token" section of an OIDC claims request | ||
* | ||
* @param claim the name of the claim to be requested | ||
* @param requestedClaimAdditionalInfo additional information about the claim being requested | ||
*/ | ||
public void requestClaimInIdToken(String claim, RequestedClaimAdditionalInfo requestedClaimAdditionalInfo) { | ||
idTokenRequestedClaims.add(new RequestedClaim(claim, requestedClaimAdditionalInfo)); | ||
} | ||
|
||
/** | ||
* Inserts a claim into the list of claims to be added to the "access_token" section of an OIDC claims request | ||
* | ||
* @param claim the name of the claim to be requested | ||
* @param requestedClaimAdditionalInfo additional information about the claim being requested | ||
*/ | ||
protected void requestClaimInAccessToken(String claim, RequestedClaimAdditionalInfo requestedClaimAdditionalInfo) { | ||
accessTokenRequestedClaims.add(new RequestedClaim(claim, requestedClaimAdditionalInfo)); | ||
} | ||
|
||
/** | ||
* Converts the ClaimsRequest object to a JSON-formatted String which follows the specification for the OIDC claims request parameter | ||
* | ||
* @return a String following JSON formatting | ||
*/ | ||
public String formatAsJSONString() { | ||
ObjectMapper mapper = new ObjectMapper(); | ||
ObjectNode rootNode = mapper.createObjectNode(); | ||
|
||
if (!idTokenRequestedClaims.isEmpty()) { | ||
rootNode.set("id_token", convertClaimsToObjectNode(idTokenRequestedClaims)); | ||
} | ||
if (!userInfoRequestedClaims.isEmpty()) { | ||
rootNode.set("userinfo", convertClaimsToObjectNode(userInfoRequestedClaims)); | ||
} | ||
if (!accessTokenRequestedClaims.isEmpty()) { | ||
rootNode.set("access_token", convertClaimsToObjectNode(accessTokenRequestedClaims)); | ||
} | ||
|
||
return mapper.valueToTree(rootNode).toString(); | ||
} | ||
|
||
private ObjectNode convertClaimsToObjectNode(List<RequestedClaim> claims) { | ||
ObjectMapper mapper = new ObjectMapper(); | ||
ObjectNode claimsNode = mapper.createObjectNode(); | ||
|
||
for (RequestedClaim claim: claims) { | ||
claimsNode.setAll((ObjectNode) mapper.valueToTree(claim)); | ||
} | ||
return claimsNode; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,6 @@ | |
|
||
interface IApiParameters { | ||
Set<String> scopes(); | ||
|
||
ClaimsRequest claims(); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.