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 "state" parameter of error responses #1298

Merged
merged 21 commits into from
Oct 11, 2024

Conversation

hafezdivandari
Copy link
Contributor

@hafezdivandari hafezdivandari commented Sep 8, 2022

According to RFC 6749 on error response of the implicit grant, the authorization server should add parameters to the fragment component of the redirection URI and the state parameter is required if it was present on the request.

There already 2 error responses that have redirect URI:

  • Invalid_scope:
    • The error parameters were already on fragment component when using implicit grant as expected, but this error response doesn't include the state parameter when redirecting. This PR fixes this on both 'auth code' and 'implicit' grants.
    • Auth code grant:
      • before: http://example.com/callback?error=access_denied&error_description=...
      • after: http://example.com/callback?state=123&error=access_denied&error_description=...
    • Implicit grant:
      • before: http://example.com/callback#error=access_denied&error_description=...
      • after: http://example.com/callback#state=123&error=access_denied&error_description=...
  • access_denied: This error response does include the state parameter when redirecting as expected, but when using implicit grant, the error's state parameter is on query string and other parameters were on fragment component. This PR fixes this.
    • Before: http://example.com/callback?state=123#error=access_denied&error_description=...
    • After: http://example.com/callback#state=123&error=access_denied&error_description=...

@Sephster
Copy link
Member

Sephster commented Sep 8, 2022

Please can you provide some information about why you want to add this change? Thank you

@hafezdivandari
Copy link
Contributor Author

hafezdivandari commented Sep 8, 2022

I added description I hope it is clear enough.

@hafezdivandari
Copy link
Contributor Author

Just merged master into this and resolved conflicts.

@hafezdivandari hafezdivandari changed the title Use fragment for error response on implicit grant Fix "state" parameter of error responses Oct 3, 2024
@hafezdivandari hafezdivandari mentioned this pull request Oct 10, 2024
9 tasks
@Sephster
Copy link
Member

Thanks for this @hafezdivandari - the code looks good. I was wondering if you would be up for adding some tests to ensure we don't add any regressions for this in future. Because I've taken so long to get around to this, if you don't have time I will try to add them in myself and we can then get this merged. If it is also possible to add a changelog entry that would be appreciated but I can do this myself if you don't have time. Thanks so much for this!

@hafezdivandari
Copy link
Contributor Author

@Sephster just added some tests and a changelog entry.

@Sephster Sephster merged commit 238a787 into thephpleague:master Oct 11, 2024
15 checks passed
@Sephster
Copy link
Member

Thanks for this @hafezdivandari - looks great

@hafezdivandari hafezdivandari deleted the patch-1 branch October 11, 2024 22:10
ajgarlag added a commit to ajgarlag/oauth2-server-bundle that referenced this pull request Oct 15, 2024
chalasr added a commit to thephpleague/oauth2-server-bundle that referenced this pull request Oct 16, 2024
This PR was squashed before being merged into the 0.9-dev branch.

Discussion
----------

Fix Ci

- Fix CS
- Fix failing tests related to thephpleague/oauth2-server#1298

Commits
-------

9dfd8cc Fix tests
568c7de Fix CS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants