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

Usage of scopes in sessions and auth, adding CurrentRequest #1080

Merged
merged 28 commits into from
Mar 13, 2024

Conversation

msmakouz
Copy link
Member

@msmakouz msmakouz commented Feb 17, 2024

Q A
Bugfix?
Breaks BC?
New feature? ✔️

Refactored AuthMiddleware and SessionMiddleware

The Spiral\Auth\Middleware\AuthMiddleware and Spiral\Session\Middleware\SessionMiddleware have been refactored. Now, instead of starting a scope and defining bindings in it, they add data to the request attributes.

CurrentRequest

Added Spiral\Http\CurrentRequest, which will be available in the container in the http scope and is intended for obtaining the current instance of Psr\Http\Message\ServerRequestInterface. In this scope, ServerRequestInterface can be changed using middleware. Using Spiral\Http\CurrentRequest, you can obtain the current request object. For example, in the next middleware, after the previous middleware has added some data to the attributes. In the http.request scope, Psr\Http\Message\ServerRequestInterface will be available as before.

Added exceptions

  • Spiral\Auth\Exception\InvalidAuthContext - when a user tries to use Spiral\Auth\AuthContextInterface, but the request attribute lacks the necessary data, the exception message advises configuring Spiral\Auth\Middleware\AuthMiddleware.
  • Spiral\Session\Exception\InvalidSessionContext - when a user tries to use Spiral\Session\SessionInterface, but the request attribute lacks the necessary data, the exception message advises configuring Spiral\Session\Middleware\SessionMiddleware.

Scope limited via attribute

  • Spiral\Cookies\CookieQueue - http.request
  • Spiral\Cookies\CookieManager - http.request
  • Spiral\Filter\InputScope - http.request
  • Spiral\Http\Request\InputManager - http.request
  • Spiral\Session\Session - http
  • Spiral\Session\SessionFactory - http

Scope limitation check is disabled by default. It will be enabled in version 4.0.

Marked as deprecated

  • Spiral\Auth\AuthScope - in favor of using Spiral\Auth\AuthContextInterface directly.
  • Spiral\Auth\TokenStorageScope - in favor of using Spiral\Auth\TokenStorageInterface directly.
  • Spiral\Session\SessionScope - in favor of using Spiral\Session\SessionInterface directly.
  • Spiral\SessionSectionScope - in favor of using method getSection from Spiral\Session\SessionInterface instead.

@msmakouz msmakouz self-assigned this Feb 17, 2024
@msmakouz msmakouz marked this pull request as draft February 17, 2024 22:02
Copy link

codecov bot commented Feb 17, 2024

Codecov Report

Attention: Patch coverage is 99.38272% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 89.77%. Comparing base (9a2b173) to head (db49785).
Report is 22 commits behind head on feature/scopes.

Files Patch % Lines
...xception/Shared/InvalidContainerScopeException.php 83.33% 1 Missing ⚠️
Additional details and impacted files
@@                 Coverage Diff                  @@
##             feature/scopes    #1080      +/-   ##
====================================================
+ Coverage             89.60%   89.77%   +0.16%     
- Complexity             6354     6381      +27     
====================================================
  Files                   830      836       +6     
  Lines                 17956    18085     +129     
====================================================
+ Hits                  16089    16235     +146     
+ Misses                 1867     1850      -17     

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

@msmakouz msmakouz changed the title Using HTTP scopes Usage of scopes in sessions and auth, addition of CurrentRequest Feb 20, 2024
@msmakouz msmakouz changed the title Usage of scopes in sessions and auth, addition of CurrentRequest Usage of scopes in sessions and auth, adding of CurrentRequest Feb 20, 2024
@msmakouz msmakouz marked this pull request as ready for review February 20, 2024 13:56
@msmakouz msmakouz requested a review from wolfy-j February 20, 2024 14:17
@msmakouz msmakouz changed the title Usage of scopes in sessions and auth, adding of CurrentRequest Usage of scopes in sessions and auth, adding CurrentRequest Feb 20, 2024
@msmakouz msmakouz added this to the 3.13 milestone Mar 7, 2024
@roxblnfk roxblnfk force-pushed the feature/http-scopes branch 2 times, most recently from f401a54 to 9a77110 Compare March 11, 2024 13:25
@roxblnfk roxblnfk force-pushed the feature/http-scopes branch from d103aea to 90b366c Compare March 12, 2024 11:58
src/AuthHttp/src/Middleware/AuthMiddleware.php Outdated Show resolved Hide resolved
src/Cookies/src/CookieQueue.php Outdated Show resolved Hide resolved
src/Framework/Filter/InputScope.php Show resolved Hide resolved
src/Http/src/Http.php Outdated Show resolved Hide resolved
src/Http/src/Pipeline.php Outdated Show resolved Hide resolved
tests/Framework/Http/AuthSessionTest.php Outdated Show resolved Hide resolved
@roxblnfk roxblnfk force-pushed the feature/http-scopes branch from d13171b to 6d5422f Compare March 12, 2024 18:45
@roxblnfk roxblnfk force-pushed the feature/http-scopes branch from ad8ab07 to db49785 Compare March 13, 2024 15:20
@roxblnfk roxblnfk merged commit 6561d86 into feature/scopes Mar 13, 2024
13 checks passed
@roxblnfk roxblnfk deleted the feature/http-scopes branch March 13, 2024 15:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants