cakephp / authentication

Authentication plugin for CakePHP. Can also be used in PSR7 based applications.
MIT License
115 stars 101 forks source link

Feature request: Make Authentication service available via DI in the Middleware #646

Closed jamisonbryant closed 8 months ago

jamisonbryant commented 8 months ago

Related to https://github.com/cakephp/authorization/issues/265

Per a recent community discussion it would be helpful for some apps to be able to obtain an instance of AuthenticationServiceInterface and/or the currently configured AuthenticationService from the service container.

Currently there is no way to add the AuthenticationService as a dependency to userland Services registered in the service container because the ServerRequest is added to the container after the user's container registration code has run. This means that the only avenue for accessing the instantiated AuthenticationService is via a request attribute.

If the service were available via DI, that Service class could list it as a dependency when configuring the application service container and then call it directly from within the service. This provides greater type safety and less (direct) reliance on the HTTP request object.