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

feature: Auth middleware will now setIntendedUrl() before login redirect #364

Merged
merged 3 commits into from
Apr 12, 2023

Conversation

evansims
Copy link
Member

@evansims evansims commented Apr 11, 2023

Changes

This PR updates the Auth0\Laravel\Http\Middleware\Stateful\Authenticate route middleware to setIntendedUrl() from an intercepted request before issuing the redirect to the login route.

The callback route was already configured to issue redirects after login that default to honouring any assigned intended URLs, so no other changes are necessary elsewhere.

To illustrate this process:

  • Visitor requests /protected-route.
  • auth0.authorize middleware determines visitor is not authenticated.
  • auth0.authorize makes note that the visitor was trying to access /protected-route.
  • auth0.authorize redirects to /login to kick off the authentication flow.
  • Visitor completes the authentication flow, and is dropped back off to /callback.
  • Auth0\Laravel\Http\Controller\Stateful (the /callback controller) completes the code exchange, and validates the session.
  • Auth0\Laravel\Http\Controller\Stateful issues a redirect()->intended(...), which picks up the intended URL that auth0.authorize noted earlier.
  • Visitor is redirected to /protected-route, now with an authenticated session.

References

Resolves #357

Testing

Tests have been updated to cover this new feature.

Contributor Checklist

@evansims evansims requested a review from a team as a code owner April 11, 2023 17:11
@evansims evansims added the Scope: Improvement Proposed improvements, or feature additions. label Apr 11, 2023
@codecov
Copy link

codecov bot commented Apr 11, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (4f7a770) 100.00% compared to head (1195dfb) 100.00%.

Additional details and impacted files
@@             Coverage Diff             @@
##                main      #364   +/-   ##
===========================================
  Coverage     100.00%   100.00%           
  Complexity       288       288           
===========================================
  Files             21        21           
  Lines            782       782           
===========================================
  Hits             782       782           
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/Http/Middleware/Stateful/Authenticate.php 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@evansims evansims added this to the 7.6.0 milestone Apr 11, 2023
@evansims evansims enabled auto-merge (squash) April 11, 2023 21:21
@evansims evansims merged commit 7eb6c6b into main Apr 12, 2023
11 checks passed
@evansims evansims deleted the feature/middleware-setintendedurl branch April 12, 2023 10:10
@evansims evansims mentioned this pull request Apr 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Scope: Improvement Proposed improvements, or feature additions.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature Request: Support for setIntendedUrl()
2 participants