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

Recommend getting the sub claim to guarantee uniqueness in the JsonWebToken.getName JavaDocs #332

Merged
merged 1 commit into from
May 20, 2024
Merged
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
11 changes: 7 additions & 4 deletions api/src/main/java/org/eclipse/microprofile/jwt/JsonWebToken.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@
*/
public interface JsonWebToken extends Principal {
/**
* Returns the unique name of this principal. This either comes from the upn claim, or if that is missing, the
* preferred_username claim. Note that for guaranteed interoperability a upn claim should be used.
* Returns the unique name of this principal. The upn claim is checked first, the preferred_username claim is
* checked next, and finally, the sub claim is checked. Note that for guaranteed interoperability a upn claim should
Comment on lines +34 to +35
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should consider adding a test in the TCK for this. Unless there's already one in there that I missed while looking just now.

* be used. However, the preferred_username claim is not guaranteed to be always unique. Therefore, if a truly
* unique principal identifier is required, prefer getting the sub claim directly by calling the
* {@link #getSubject()} method.
*
* @return the unique name of this principal.
*/
Expand Down Expand Up @@ -67,8 +70,8 @@ default Set<String> getAudience() {
}

/**
* The sub(Subject) claim identifies the principal that is the subject of the JWT. This is the token issuing IDP
* subject.
* The sub(Subject) claim uniquely identifies the principal that is the subject of the JWT. This is the token
* issuing IDP subject.
*
* @return the sub claim.
*/
Expand Down
Loading