Code Monkey home page Code Monkey logo

slim-auth's People

Contributors

krzysztof-gzocha avatar wojteninho avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

slim-auth's Issues

HttpDigestAuthenticator

Authenticator is object which implements Slim\Authenticator\AuthenticatorInterface

interface AuthenticatorInterface
{
    /**
     * @param RequestInterface $request
     * @return mixed
     */
    public function authenticate(RequestInterface $request);

    /**
     * @param RequestInterface      $request
     * @param ResponseInterface     $response
     * @param UnauthorizedException $e
     * @return ResponseInterface
     */
    public function onUnauthorized(RequestInterface $request, ResponseInterface $response, UnauthorizedException $e);
}

Currently available authenticators are HttpBasicAuthenticator & JsonWebTokenAuthenticator. HttpDigestAuthenticator implementation is more than welcome link. It should be very similar to HttpBasicAuthenticator and logic behind the scenes should be as follow:

  1. resolve credentials from RequestInterface
  2. validate credentials against some strategy (Maybe both HttpBasicAuthenticator and HttpDigestAuthenticator can share same strategies?)
  3. throw UnauthorizedException when sth went wrong with authentication

Additional strategies for HttpBasicAuthenticator

For Slim\Authenticator\HttpBasicAuthenticator mandatory parameter in options is strategy which should be instance of Slim\Authenticator\HttpBasic\StrategyInterface. Startegy interface body is as follow:

interface StrategyInterface
{
    /**
     * @param string $user
     * @param string $password
     */
    public function authenticate($user, $password);
}

It gets credentials resolved by HttpBasicAuthenticator and should perform authentication logic. Currently only one implementation is available: Slim\Authenticator\HttpBasic\UserArrayStrategy, which is a very naive:

$authenticator = new HttpBasicAuthenticator([
  'strategy' => new UserArrayStrategy([
    'user_1' => 'password_1',
    'user_2' => 'password_2'
    ...
  ])
]);

It is necessary to have more ready to use strategies. My wishes are at least:

HtpasswdStrategy

$authenticator = new HttpBasicAuthenticator([
  'strategy' => new HtpasswdStrategy([
    'file' => // path to .htpasswd file,
  ])
]);

PDOStrategy

$authenticator = new HttpBasicAuthenticator([
  'strategy' => new PDOStrategy([
    'pdo' => // instance of \PDO,
    'table' => 'users',
    'usernameColumn' => 'login',
    'passwordColumn' => 'password',
    'comparePasswords' => function ($password, $passwordFromDatabase) {
        // just example, I want the strategy to be as much adjustable as possible
        // and I am aware that hashing strategies can be different across many applications
        return md5($password) === $passwordFromDatabase;
    }
  ])
]);

Other suggestions about new startegies are more than welcome ;)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.