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

fix: Omit non-standard, empty fields in RefreshTokenRequest when performing a token refresh #599

Merged
merged 2 commits into from
May 6, 2024

Conversation

ymarcus93
Copy link
Contributor

The OIDC spec's definition of a refresh request does not include client_assertion or client_assertion_type as valid parameters for the refresh request. See request format here: https://openid.net/specs/openid-connect-core-1_0.html#RefreshingAccessToken. The document only displays client_id, client_secret, grant_type, refresh_token, and scope as acceptable parameters.

Therefore, I propose we add the omitempty tags to the ClientAssertion and ClientAssertionType fields in RefreshTokenRequest, so that the token refresh functionality provided by rp.RefreshTokens can work with identity providers that may have additional logic or different expectations when these fields are included in the refresh token request.

For example, when attempting to construct an OIDC client via rp.RelyingParty against an Okta identity provider, I ran into issues when performing refresh with rp.RefreshTokens. The Okta identity provider returned http status not ok: 400 Bad Request {"error":"invalid_request","error_description":"The client_assertion_type is invalid."} as an error. I assume I'm receiving this error because I'm calling the RefreshTokens func with clientAssertion="" and clientAssertionType=""; the addition of the omitempty tags resolves this issue and hopefully future proofs this library against other identity providers that have the same behavior.

Definition of Ready

  • I am happy with the code
  • Short description of the feature/issue is added in the pr description
  • PR is linked to the corresponding user story
  • Acceptance criteria are met
  • All open todos and follow ups are defined in a new ticket and justified
  • Deviations from the acceptance criteria and design are agreed with the PO and documented.
  • No debug or dead code
  • My code has no repetitions
  • Critical parts are tested automatically
  • Where possible E2E tests are implemented
  • Documentation/examples are up-to-date
  • All non-functional requirements are met
  • Functionality of the acceptance criteria is checked manually on the dev system.

@livio-a
Copy link
Member

livio-a commented May 2, 2024

hey @ymarcus93 thanks for the fix and totally agree on that. Since scope and depending on the authentication also client_id and client_secret are optional, I'd add the omitempty tag there as well.

@ymarcus93
Copy link
Contributor Author

ymarcus93 commented May 3, 2024

@livio-a Rebased and pushed b03e835 with omitempty on scope, client_id, and client_secret

Copy link

codecov bot commented May 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 62.04%. Comparing base (0992c5f) to head (b03e835).
Report is 56 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #599      +/-   ##
==========================================
+ Coverage   60.06%   62.04%   +1.98%     
==========================================
  Files          80       81       +1     
  Lines        6998     6192     -806     
==========================================
- Hits         4203     3842     -361     
+ Misses       2498     2041     -457     
- Partials      297      309      +12     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@livio-a livio-a merged commit 5a84d8c into zitadel:main May 6, 2024
7 checks passed
Copy link

github-actions bot commented May 6, 2024

🎉 This PR is included in version 3.23.2 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

3 participants