spring-projects / spring-projects/spring-security

Issue of private_key_jwt authentication type token issuance (JwtClientAssertionAuthenticationConverter)

Open
#16,945 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

in: oauth2 type: bug
Dominant language
Java
Stars
9.6k
Forks
6.3k
Avg merge
2d 11h
Merged PRs (30d)
52

Description

Logic within Jwt Client AuthenticationConverter

f you look at the token issuance logic of the private_key_jwt authentication type,
It says to send client_id as a parameter.

If you only look at the RFC 7523 standard, a separate client_id parameter is not required because it identifies the client with an iss/sub claim within the client_assertion.

It seems that branch processing is required for each type of authentication.

 @Nullable
    public Authentication convert(HttpServletRequest request) {
        MultiValueMap<String, String> parameters = OAuth2EndpointUtils.getFormParameters(request);
        if (parameters.getFirst("client_assertion_type") != null && parameters.getFirst("client_assertion") != null) {
            String clientAssertionType = (String)parameters.getFirst("client_assertion_type");
            if (((List)parameters.get("client_assertion_type")).size() != 1) {
                throw new OAuth2AuthenticationException("invalid_request");
            } else if (!JWT_CLIENT_ASSERTION_AUTHENTICATION_METHOD.getValue().equals(clientAssertionType)) {
                return null;
            } else {
                String jwtAssertion = (String)parameters.getFirst("client_assertion");
                if (((List)parameters.get("client_assertion")).size() != 1) {
                    throw new OAuth2AuthenticationException("invalid_request");
                } else {
                    String clientId = (String)parameters.getFirst("client_id");  // <========== this line.
                    if (StringUtils.hasText(clientId) && ((List)parameters.get("client_id")).size() == 1) {
                        Map<String, Object> additionalParameters = OAuth2EndpointUtils.getParametersIfMatchesAuthorizationCodeGrantRequest(request, new String[]{"client_assertion_type", "client_assertion", "client_id"});
                        return new OAuth2ClientAuthenticationToken(clientId, JWT_CLIENT_ASSERTION_AUTHENTICATION_METHOD, jwtAssertion, additionalParameters);
                    } else {
                        throw new OAuth2AuthenticationException("invalid_request");
                    }
                }
            }
        } else {
            return null;
        }
    }

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with JwtClientAssertionAuthenticationConverter and compare its private_key_jwt parameter handling with RFC 7523. Trace how the token issuance request identifies the client through client_id versus the client_assertion iss/sub claims. Done means the authentication flow handles the required client-identification form for this authentication type and has coverage for the relevant request cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
authentication, security
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.