zend-expressive-authentication icon indicating copy to clipboard operation
zend-expressive-authentication copied to clipboard

A new IdentityInterface for authentication

Open ezimuel opened this issue 7 years ago • 6 comments

This PR is a work in progress to solve the issue about OAuth2 client authentication reported in https://github.com/zendframework/zend-expressive-authentication-oauth2/pull/55. The idea is to use a general IdentityInterface as follows:

namespace Zend\Expressive\Authentication;

interface IdentityInterface
{
    /**
     * Get the unique identity
     */
    public function getIdentity() : string;
}

And a specific UserInterface that extends the IdentityInterface, as follows:

namespace Zend\Expressive\Authentication;

interface UserInterface extends IdentityInterface
{
    /**
     * Get all user roles
     *
     * @return Iterable
     */
    public function getRoles() : iterable;

    /**
     * Get a detail $name if present, $default otherwise
     */
    public function getDetail(string $name, $default = null);

    /**
     * Get all the details, if any
     */
    public function getDetails() : array;
}

Regarding the AuthenticationMiddleware, this PR generates a UserInterface PSR-7 attribute if authenticate($request) returns an instance of UserInterface. Otherwise, it will returns a IdentityInterface attribute.

These changes should prevent BC breaks for existing implementations using zend-expressive-authentication and offers a new solution to zend-expressive-authentication-oauth2 for implementing a ClientInterface (extending IdentityInterface).

ezimuel avatar Nov 13 '18 15:11 ezimuel

@ezimuel Is there still work to do on this patch?

weierophinney avatar Mar 05 '19 17:03 weierophinney

sorry for the super late response - LGTM 👍

marc-mabe avatar Mar 20 '19 15:03 marc-mabe

@ezimuel Is there still work to do on this patch?

@weierophinney this PR is ready, of course we need to implement a new ClientInterface for zend-expressive-authentication-oauth2 to solve https://github.com/zendframework/zend-expressive-authentication-oauth2/pull/55

ezimuel avatar Mar 21 '19 13:03 ezimuel

I've got this and the related one for oauth2 on my todo list - not sure if I'll have time to evaluate them this week, or if it will be early next. I'll drop a note with what route I go (new minor or new major) when I do.

weierophinney avatar Mar 21 '19 16:03 weierophinney

This repository has been closed and moved to mezzio/mezzio-authentication; a new issue has been opened at https://github.com/mezzio/mezzio-authentication/issues/2.

weierophinney avatar Dec 31 '19 20:12 weierophinney

This repository has been moved to mezzio/mezzio-authentication. If you feel that this patch is still relevant, please re-open against that repository, and reference this issue. To re-open, we suggest the following workflow:

  • Squash all commits in your branch (git rebase -i origin/{branch})
  • Make a note of all changed files (`git diff --name-only origin/{branch}...HEAD
  • Run the laminas/laminas-migration tool on the code.
  • Clone mezzio/mezzio-authentication to another directory.
  • Copy the files from the second bullet point to the clone of mezzio/mezzio-authentication.
  • In your clone of mezzio/mezzio-authentication, commit the files, push to your fork, and open the new PR. We will be providing tooling via laminas/laminas-migration soon to help automate the process.

weierophinney avatar Dec 31 '19 20:12 weierophinney