wojteninho / slim-auth Goto Github PK
View Code? Open in Web Editor NEWSlim Auth Middleware
Slim Auth Middleware
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:
RequestInterface
HttpBasicAuthenticator
and HttpDigestAuthenticator
can share same strategies?)UnauthorizedException
when sth went wrong with authenticationFor 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 ;)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.