PSR-7 and PSR-15 HTTP Basic Authentication Middleware

Overview

PSR-7 and PSR-15 Basic Auth Middleware

This middleware implements HTTP Basic Authentication. It was originally developed for Slim but can be used with all frameworks using PSR-7 or PSR-15 style middlewares. It has been tested with Slim Framework and Zend Expressive.

Latest Version Packagist Software License Build Status Coverage

Heads up! You are reading documentation for 3.x branch which is PHP 7.1 and up only. If you are using older version of PHP see the 2.x branch. These two branches are not backwards compatible, see UPGRADING for instructions how to upgrade.

Install

Install latest version using composer.

$ composer require tuupola/slim-basic-auth

Usage

Configuration options are passed as an array. Only mandatory parameter is users. This is an array where you pass one or more "username" => "password" combinations. Username is the key and password is the value.

$app = new Slim\App;

$app->add(new Tuupola\Middleware\HttpBasicAuthentication([
    "users" => [
        "root" => "t00r",
        "somebody" => "passw0rd"
    ]
]));

Same with Zend Expressive.

$app = Zend\Expressive\AppFactory::create();

$app->pipe(new Tuupola\Middleware\HttpBasicAuthentication([
    "users" => [
        "root" => "t00r",
        "user" => "passw0rd"
    ]
]));

Rest of the examples assume you are using Slim Framework.

Cleartext passwords are only good for quick testing. You probably want to use hashed passwords. Hashed password can be generated with htpasswd command line tool or password_hash() PHP function

$ htpasswd -nbBC 10 root t00r
root:$2y$10$1lwCIlqktFZwEBIppL4ak.I1AHxjoKy9stLnbedwVMrt92aGz82.O
$ htpasswd -nbBC 10 somebody passw0rd
somebody:$2y$10$6/vGXuMUoRlJUeDN.bUWduge4GhQbgPkm6pfyGxwgEWT0vEkHKBUW
$app = new Slim\App;

$app->add(new Tuupola\Middleware\HttpBasicAuthentication([
    "users" => [
        "root" => '$2y$10$1lwCIlqktFZwEBIppL4ak.I1AHxjoKy9stLnbedwVMrt92aGz82.O',
        "somebody" => '$2y$10$6/vGXuMUoRlJUeDN.bUWduge4GhQbgPkm6pfyGxwgEWT0vEkHKBUW'
    ]
]));

Even if you are using hashed passwords it is not the best idea to store credentials in the code. Instead you could store them in environment or external file which is not committed to GitHub.

$app = new Slim\App;

$app->add(new Tuupola\Middleware\HttpBasicAuthentication([
    "users" => [
        "admin" => getenv("ADMIN_PASSWORD")
    ]
]));

Optional parameters

Path

The optional path parameter allows you to specify the protected part of your website. It can be either a string or an array. You do not need to specify each URL. Instead think of path setting as a folder. In the example below everything starting with /api will be authenticated.

$app = new Slim\App;

$app->add(new Tuupola\Middleware\HttpBasicAuthentication([
    "path" => "/api", /* or ["/admin", "/api"] */
    "realm" => "Protected",
    "users" => [
        "root" => "t00r",
        "somebody" => "passw0rd"
    ]
]));

Ignore

With optional ignore parameter you can make exceptions to path parameter. In the example below everything starting with /api and /admin will be authenticated with the exception of /api/token and /admin/ping which will not be authenticated.

$app = new Slim\App;

$app->add(new Tuupola\Middleware\HttpBasicAuthentication([
    "path" => ["/api", "/admin"],
    "ignore" => ["/api/token", "/admin/ping"],
    "realm" => "Protected",
    "users" => [
        "root" => "t00r",
        "somebody" => "passw0rd"
    ]
]));

Before

Before function is called only when authentication succeeds but before the next incoming middleware is called. You can use this to alter the request before passing it to the next incoming middleware in the stack. If it returns anything else than \Psr\Http\Message\RequestInterface the return value will be ignored.

$app = new Slim\App;

$app->add(new Tuupola\Middleware\HttpBasicAuthentication([
    "path" => "/admin",
    "realm" => "Protected",
    "users" => [
        "root" => "t00r",
        "somebody" => "passw0rd"
    ],
    "before" => function ($request, $arguments) {
        return $request->withAttribute("user", $arguments["user"]);
    }
]));

After

After function is called only when authentication succeeds and after the incoming middleware stack has been called. You can use this to alter the response before passing it next outgoing middleware in the stack. If it returns anything else than \Psr\Http\Message\ResponseInterface the return value will be ignored.

$app = new Slim\App;

$app->add(new Tuupola\Middleware\HttpBasicAuthentication([
    "path" => "/admin",
    "realm" => "Protected",
    "users" => [
        "root" => "t00r",
        "somebody" => "passw0rd"
    ],
    "after" => function ($response, $arguments) {
        return $response->withHeader("X-Brawndo", "plants crave");
    }
]));

Security

Basic authentication transmits credentials in clear text. For this reason HTTPS should always be used together with basic authentication. If the middleware detects insecure usage over HTTP it will throw a RuntimeException with the following message: Insecure use of middleware over HTTP denied by configuration.

By default, localhost is allowed to use HTTP. The security behavior of HttpBasicAuthentication can also be configured to allow:

How to configure a whitelist:

You can list hosts to allow access insecurely. For example, to allow HTTP traffic to your development host dev.example.com, add the hostname to the relaxed config key.

$app = new Slim\App;

$app->add(new Tuupola\Middleware\HttpBasicAuthentication([
    "path" => "/admin",
    "secure" => true,
    "relaxed" => ["localhost", "dev.example.com"],
    "users" => [
        "root" => "t00r",
        "somebody" => "passw0rd"
    ]
]));

Allow HTTPS termination and forwarding

If public traffic terminates SSL on a load balancer or proxy and forwards to the application host insecurely, HttpBasicAuthentication can inspect request headers to ensure that the original client request was initiated securely. To enable, add the string headers to the relaxed config key.

$app = new Slim\App;

$app->add(new Tuupola\Middleware\HttpBasicAuthentication([
    "path" => "/admin",
    "secure" => true,
    "relaxed" => ["localhost", "headers"],
    "users" => [
        "root" => "t00r",
        "somebody" => "passw0rd"
    ]
]));

Allow all unencrypted traffic

To allow insecure usage by any host, you must enable it manually by setting secure to false. This is generally a bad idea. Use only if you know what you are doing.

$app = new Slim\App;

$app->add(new Tuupola\Middleware\HttpBasicAuthentication([
    "path" => "/admin",
    "secure" => false,
    "users" => [
        "root" => "t00r",
        "somebody" => "passw0rd"
    ]
]));

Custom authentication methods

Sometimes passing users in an array is not enough. To authenticate against custom datasource you can pass a callable as authenticator parameter. This can be either a class which implements AuthenticatorInterface or anonymous function. Callable receives an array containing user and password as argument. In both cases authenticator must return either true or false.

If you are creating an Enterprise™ software which randomly lets people log in you could use the following.

use Tuupola\Middleware\HttpBasicAuthentication\AuthenticatorInterface;
use Tuupola\Middleware\HttpBasicAuthentication;

class RandomAuthenticator implements AuthenticatorInterface {
    public function __invoke(array $arguments): bool {
        return (bool)rand(0,1);
    }
}

$app = new Slim\App;

$app->add(new HttpBasicAuthentication([
    "path" => "/admin",
    "realm" => "Protected",
    "authenticator" => new RandomAuthenticator
]));

Same thing can also be accomplished with anonymous function.

$app = new Slim\App;

$app->add(new Tuupola\Middleware\HttpBasicAuthentication([
    "path" => "/admin",
    "realm" => "Protected",
    "authenticator" => function ($arguments) {
        return (bool)rand(0,1);
    }
]));

Setting response body when authentication fails

By default plugin returns an empty response body with 401 response. You can return custom body using by providing an error handler. This is useful for example when you need additional information why authentication failed.

$app = new Slim\App;

$app->add(new Tuupola\Middleware\HttpBasicAuthentication([
    "path" => "/api",
    "realm" => "Protected",
    "users" => [
        "root" => "t00r",
        "somebody" => "passw0rd"
    ],
    "error" => function ($response, $arguments) {
        $data = [];
        $data["status"] = "error";
        $data["message"] = $arguments["message"];

        $body = $response->getBody();
        $body->write(json_encode($data, JSON_UNESCAPED_SLASHES));

        return $response->withBody($body);
    }
]));

Usage with PDO

For those in hurry there is a ready made PDO authenticator. It covers most of the use cases. You probably end up implementing your own though.

use Tuupola\Middleware\HttpBasicAuthentication\PdoAuthenticator;

$pdo = new PDO("sqlite:/tmp/users.sqlite");
$app = new Slim\App;

$app->add(new Tuupola\Middleware\HttpBasicAuthentication([
    "path" => "/admin",
    "realm" => "Protected",
    "authenticator" => new PdoAuthenticator([
        "pdo" => $pdo
    ])
]));

For better explanation see Basic Authentication from Database blog post.

Usage with FastCGI

By default Apache does not pass credentials to FastCGI process. If you are using mod_fcgi you can configure authorization headers with:

FastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi -host 127.0.0.1:9000 -pass-header Authorization

Testing

You can run tests either manually or automatically on every code change. Automatic tests require entr to work.

$ make test
$ brew install entr
$ make watch

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

License

The MIT License (MIT). Please see LICENSE for more information.

Comments
  • Class 'Tuupola\Middleware\HttpBasicAuthentication' not found

    Class 'Tuupola\Middleware\HttpBasicAuthentication' not found

    I am using tuupola with slim framework to secure android connection but I always get this error although I followed the steps that I found in this site : https://github.com/tuupola/slim-basic-auth

    opened by aliahmedisback 32
  • Why does local(HTTP) connection work but not online(HTTPS)?

    Why does local(HTTP) connection work but not online(HTTPS)?

    I am testing the SLIM structure for my new API REST project.

    I installed SLIM on my Apache CGI server online with SSL certificate: ok, it works! I can access my resource from my computer (http://domaine.fr/v1/test for example)

    I tested with basic authentication through the htaccess file. I type user / password to access my resource: it works!

    Now, "I would like to test with basic authentication in SLIM with https://github.com/tuupola/slim-basic-auth

    But it does not work! It always asks me for the login and password!

    opened by manzowa 16
  • Fatal error insecure use of middleware

    Fatal error insecure use of middleware

    Copy pasted your example into index.php with users, t00r and I get this error:

    Fatal error: Uncaught exception 'RuntimeException' with message 'Insecure use of middleware over HTTP denied by configuration.' in /home/httpd/testapi/vendor/tuupola/slim-basic-auth/src/HttpBasicAuthentication.php:92
    Stack trace:
    #0 /home/httpd/testapi/vendor/slim/slim/Slim/Slim.php(1302): Slim\Middleware\HttpBasicAuthentication->call()
    #1 /home/httpd/testapi/public/index.php(96): Slim\Slim->run()
    #2 {main}
      thrown in /home/httpd/testapi/vendor/tuupola/slim-basic-auth/src/HttpBasicAuthentication.php on line 92
    
    

    Any idea?

    opened by Zyles 12
  • Can't sign in

    Can't sign in

    Hello, I can't connect to my app on remote server. It works on local but not on remote server :

    $application->add(new HttpBasicAuthentication([
        'realm' => 'Piso',
        'secure' => true,
        'relaxed' => ['localhost'],
        'users' => [
            'root' => '$2y$10$TJor1LmWl5Vi9Ljrqp5Fr.S5TdIUbleIei9.Ndo0gT1IO0/ELwKyK',
            'test' => 'azerty'
        ]
    ]));
    

    I use "tuupola/slim-basic-auth": "^3.0" .

    Thank you

    opened by miradozk 10
  • Multiple Paths

    Multiple Paths

    I want to setup authentication on multiple paths for my API. In most cases I'll need authentication but in others I definitely don't want authentication (i.e. registration). I know I can create separate instances of \Slim\Middleware\HttpBasicAuthentication but is there a way to create a single instance that includes multiple paths?

    opened by mastermindg 9
  • Config to allow 'https forward'

    Config to allow 'https forward'

    I ran into "Insecure use of middleware over HTTP denied by configuration." when I deployed and found this discussion of the issue in #12

    I have worked around the problem by setting "secure" => "false".

    However, I think that a better solution would be to allow HttpBasicAuthentication to be configured to permit forwarded https requests.

    The use case is where a load balancer or cdn is terminating https requests which are then forwarded over http to slim.

    An example implementation can be found here: https://github.com/oscarotero/psr7-middlewares/blob/master/src/Middleware/Https.php#L110

    By implementing, testing and documenting this configuration capability, slim-basic-auth would help the end user to securely and quickly set up basic authentication in what I assume is a common deployment scenario.

    enhancement 
    opened by acinader 8
  • Keeps asking to login

    Keeps asking to login

    this code works in my development environment:

    $app->add(new \Slim\Middleware\HttpBasicAuthentication(
      [
        "path" => "/admin",
        "secure" => false,
        "users" => [
          "admin" => "admin"
        ]
      ]
    ));
    

    But on my production server is keeps asking over and over for the password (the error message is that authentication failed.

    However, changing the path to "path" => "admin" fixed the issue immediately (and on page reload I didnt have to login again)

    Just a heads up for any others running into this

    opened by KevinBatdorf 8
  • ArrayAuthenticator class error

    ArrayAuthenticator class error

    Hi i just found some errors in your code and debugged it

    `namespace Slim\Middleware\HttpBasicAuthentication;

    class ArrayAuthenticator implements AuthenticatorInterface {

    public $options;
    
    public function __construct($options = null)
    {
    
        /* Default options. */
        $this->options = [
            "users" => []
        ];
    		
        if ($options) {
            $this->options = array_merge($this->options, (array)$options);
        }
    		
    }
    
    public function __invoke(array $arguments)
    {
        $user = $arguments["user"];
        $password = $arguments["password"];
    
        /* Unknown user. */
        if (!isset($this->options["users"]["user"])) {
            return false;
        }
    
        if (self::isHash($this->options["users"]["password"])) {
            /* Hashed password. */
            return password_verify($password, $this->options["users"]["password"]);
        } else {
            /* Cleartext password. */
            return $this->options["users"]["password"] === $password && $this->options["users"]["user"] === $user;
        }
    }
    
    public static function isHash($password)
    {
        return preg_match('/^\$(2|2a|2y)\$\d{2}\$.*/', $password) && (strlen($password) >= 60);
    }
    

    }`

    opened by ChanderTambia 7
  •  PHP Fatal error:  Uncaught Error: Class 'Slim\\Middleware\\HttpBasicAuthentication' not found

    PHP Fatal error: Uncaught Error: Class 'Slim\\Middleware\\HttpBasicAuthentication' not found

    Im having a strange error.

    On my localhost (windows10 with xampp) all my slim api is working fine, but when i put it on my server (ubuntu) i've got the error: PHP Fatal error: Uncaught Error: Class 'Slim\Middleware\HttpBasicAuthentication' not found /var/www/html ...

    Some useful notes: My composer.php { "require": { "slim/slim": "^3.9", "tuupola/slim-basic-auth": "^3.0", "slim/middleware": "*", "firebase/php-jwt": "^5.0", "tuupola/slim-jwt-auth": "^3.0", "tuupola/base62": "^0.10.0", "tuupola/cors-middleware": "^0.7.0" } }

    My bootstrap.php $app->add(new \Tuupola\Middleware\HttpBasicAuthentication([

    "users" => [
        "root" => "toor"
    ],
    "path" => ["/"],
    /**
     * Whitelist - Protege todas as rotas e só libera as de dentro do array
     */
    "passthrough" => ["/auth"]
    

    ]));

    Can you please give some tips? Thank you

    opened by fernandocassola 7
  • There is a way to update request in callback ?

    There is a way to update request in callback ?

    Hi,

    There is a way to add an attribute/header in the request in callback (or authenticator) method ?

    Currently I did that in two steps:

    1. In authenticator when credentials are correct I set my attribute in session
    2. In a second middleware I check if the attribute exist in session and I set it to the request

    So I would be nice if it's possible to update the request in this middleware.

    Thanks for your help ;)

    opened by Ducatel 7
  • Set passthrough in RequestPathRule from configuration parameter

    Set passthrough in RequestPathRule from configuration parameter

    there's a passthrough variable in RequestPathRule.php, but no way of set it up from configuration parameter.

    edit: should have been about RequestPathRule instead of RequestMethodRule

    opened by 3ace 7
  • HTTP_X_FORWARDED_PROTO

    HTTP_X_FORWARDED_PROTO

    Hi,

    Getting this error message over an HTTPS connection for a server hosted on Heroku:

    Insecure use of middleware over HTTP denied by configuration. File: /app/vendor/tuupola/slim-basic-auth/src/HttpBasicAuthentication.php Line: 148

    FYI, in local development (over HTTPS, with a self-encrypted certificate), I get these key/pairs in $_SERVER:

    [HTTPS] => on
    [SERVER_PORT] => 443
    

    Whereas on Heroku there's no such line, but, instead:

    [HTTP_X_FORWARDED_PORT] => 443
    [HTTP_X_FORWARDED_PROTO] => https
    

    This is typical for hosting behind a proxy or load balance. See X-Forwarded-Proto.

    Here's the workaround I'm using:

    if (
        isset($_SERVER['HTTP_X_FORWARDED_PROTO'])
        && isset($_SERVER['HTTP_X_FORWARDED_PORT'])
    ) {
        $_SERVER['HTTPS'] = 'on';
        $_SERVER['SERVER_PORT'] = $_SERVER['HTTP_X_FORWARDED_PORT'];
            // Typically, `443`.
    }
    

    I guess tuupola/slim-basic-auth could check for these values as well when trying to determine if a connection is secure.

    opened by fabswt 1
  • Ignore is not working as expected

    Ignore is not working as expected

    Hi,

    the following configuration:

    $app->add(new Tuupola\Middleware\HttpBasicAuthentication([
        "path" => ["/"],
        "ignore" => ["/api/unauthorized"],
        // ...
    ]));
    

    does not work as expected, the requests to mydomain.com/api.php/api/unauthorized/... are still protected (as all those to mydomain.com/api.php/api/...). While, if I change that to something like:

    $app->add(new Tuupola\Middleware\HttpBasicAuthentication([
        "path" => ["/api"],
        "ignore" => ["/api/unauthorized"],
        // ...
    ]));
    

    all my requests containing mydomain.com/api.php/api/... are not protected.

    What am I doing wrong? Is that a know issue (e.g. https://github.com/tuupola/slim-jwt-auth/issues/140)?

    Thanks

    opened by seth100 0
  • Add request object back  to the error handler.

    Add request object back to the error handler.

    Add request object back as parameter to the error handler.

    $app->add(new Tuupola\Middleware\HttpBasicAuthentication([
        "error" => function ($request, $response, $arguments) {
          ...
        }
    ]));
    

    See https://github.com/tuupola/branca-middleware/pull/13 for reference.

    4.x 
    opened by tuupola 1
  • "final class" and CloudFlare proxification error

    If a site is proxied through ClaudFlare using the "Flexible" mode (Encrypts traffic between the browser and Cloudflare), we will always get the error: "Insecure use of middleware over HTTP denied by configuration.". image

    That's because you incorrectly define the use of the HTTPS protocol in the following lines: https://github.com/tuupola/slim-basic-auth/blob/3.2.1/src/HttpBasicAuthentication.php#L107-L111

    When using proxying through cloud providers (CloudFlare), you should use the following code: https://gist.github.com/saippuakauppias/f1082a32f5797755b69b043d4852eda2

    I tried to inherit your class and fix it to get around this limitation, but your class is declared as "final". Why is that done?

    PS: It is not possible to use the "Full" proxy mode in a CloudFlare, then you will need to set the slide certificate to nginx for each domain. This is a lot of manual work, which is difficult to automate (certificates are issued in the dashboard, most likely they can be issued through the API, but it's not such a task to spend a lot of time on integration with it).

    opened by saippuakauppias 1
Releases(2.2.0)
  • 2.2.0(Sep 22, 2016)

    You can now also use hashed passwords created with htpasswd from command line or password_hash().

    $app->add(new \Slim\Middleware\HttpBasicAuthentication([
        "users" => [
            "root" => '$2y$10$Tm03qGT4FLqobzbZcfLDcOVIwZEpg20QZYffleeA2jfcClLpufYpy',
            "somebody" => '$2y$12$BlC21Ah2CuO7xlplqyysEejr1rwnj.uh2IEW9TX0JPgTnLNJk6XOC'
        ]
    ]));
    
    Source code(tar.gz)
    Source code(zip)
  • 2.1.1(Sep 16, 2016)

  • 2.1.0(Sep 4, 2016)

    You can now set the passthrough parameter via options.

    $app->add(new \Slim\Middleware\HttpBasicAuthentication([
        "path" => "/admin",
        "passthrough" => "/admin/ping",
        "users" => [
            "root" => "t00r",
            "somebody" => "passw0rd"
        ]
    ]));
    
    Source code(tar.gz)
    Source code(zip)
  • 2.0.4(Sep 4, 2016)

  • 2.0.3(Sep 4, 2016)

  • 2.0.2(Mar 24, 2016)

  • 2.0.1(Mar 24, 2016)

  • 2.0.0(Jan 31, 2016)

  • 1.0.0(Aug 13, 2015)

  • 0.12.1(Aug 13, 2015)

  • 0.12.0(Jul 12, 2015)

    You can now bind the middleware to multiple paths by passing an array.

    $auth = new \Slim\Middleware\HttpBasicAuthentication([
        "path" => ["/api/v1", "/api/v2"],
        "users" => [
            "root" => "t00r",
            "user" => "passw0rd"
        ]
    ]);
    
    $app->add($auth);
    
    Source code(tar.gz)
    Source code(zip)
  • 0.11.0(May 25, 2015)

    By default plugin returns an empty response body with 401 response. You can now return custom body using by providing an error handler. This is useful for example when you need additional information why authentication failed.

    $app = new \Slim\Slim();
    
    $app->add(new \Slim\Middleware\HttpBasicAuthentication([
        "path" => "/api",
        "realm" => "Protected",
        "users" => [
            "root" => "t00r",
            "user" => "passw0rd"
        ],
        "error" => function ($arguments) use ($app) {
            $response["status"] = "error";
            $response["message"] = $arguments["message"];
            $app->response->write(json_encode($response, JSON_UNESCAPED_SLASHES));
        }
    ]));
    

    Compatibility break!

    Function signature for custom authenticator changed. Callable now receives an array containing user and password. This for futureproofing the api and make me stop OCDing over having different signatures with callback and errorhandler.

    $app->add(new \Slim\Middleware\HttpBasicAuthentication([
        "path" => "/admin",
        "realm" => "Protected",
        "authenticator" => function ($arguments) use ($app) {
            $user = $arguments["user"];
            $password = $arguments["password"];
        }
    ]));
    
    Source code(tar.gz)
    Source code(zip)
  • 0.10.0(May 19, 2015)

    You can now include optional callback which is called if authentication succeeds. However if callback returns boolean false authentication is forced to fail.

    $app->add(new \Slim\Middleware\HttpBasicAuthentication([
        "path" => "/admin",
        "realm" => "Protected",
        "users" => [
            "root" => "t00r",
            "user" => "passw0rd"
        ],
        "callback" => function ($arguments) use ($app) {
            print_r($arguments);
        }
    ]));
    
    Source code(tar.gz)
    Source code(zip)
  • 0.9.0(May 6, 2015)

    This release syncs the api to be more close with slim-jwt-auth sister middleware. Custom authentication should now be a callable. This means you can either pass a class with __invoke() or anynymous function.

    use \Slim\Middleware\HttpBasicAuthentication\AuthenticatorInterface;
    
    class RandomAuthenticator implements AuthenticatorInterface {
        public function __invoke($user, $pass) {
            return (bool)rand(0,1);
        }
    }
    
    $app = new \Slim\Slim();
    
    $app->add(new \Slim\Middleware\HttpBasicAuthentication([
        "path" => "/admin",
        "realm" => "Protected",
        "authenticator" => new RandomAuthenticator()
    ]));
    
    $app = new \Slim\Slim();
    
    $app->add(new \Slim\Middleware\HttpBasicAuthentication([
        "path" => "/admin",
        "realm" => "Protected",
        "authenticator" => function ($user, $pass) {
            return (bool)rand(0,1);
        }
    ]));
    

    Also introduces a concept of rules which are callables and can be stacked. Use these only if the normal "easy" mode is not enough for your needs. If any of the rules is stack return false middleware assumes this is an public url and will not authenticate. For example to authenticate everything in /apiexcept /api/public you could use the following.

    $app->add(new \Slim\Middleware\HttpBasicAuthentication([
        "users" => ["root" => "00r"],
        "rules" => [
            new \Slim\Middleware\HttpBasicAuthentication\RequestPathRule([
                "path" => "/api",
                "passthrough" => ["/api/public"]
            ])
        ]
    ]));
    

    Old HttpBasicAuth shortcut class alias was removed. Always use HttpBasicAuthentication instead.

    Source code(tar.gz)
    Source code(zip)
  • 0.8.2(Feb 16, 2015)

  • 0.8.1(Feb 16, 2015)

    CORS preflight OPTIONS are not anymore authenticated by default.

    You can use the ValidatorInterface to implement any other arbitrary rules of allowing request to pass through even though it normally should be authenticated.

    $app->add(new \Slim\Middleware\HttpBasicAuthentication([
        "path" => "/admin",
        "realm" => "Protected",
        "validator" => new FooValidator()
    ]));
    
    Source code(tar.gz)
    Source code(zip)
  • 0.8.0(Nov 5, 2014)

    You can now authenticate against database using included PDO authenticator. Database must contain column for username and password hash. The hash must be created with password_hash() function.

    use \Slim\Middleware\HttpBasicAuthentication\PdoAuthenticator;
    
    $pdo = new \PDO("sqlite:/tmp/users.sqlite");
    
    $app = new \Slim\Slim();
    
    $app->add(new \Slim\Middleware\HttpBasicAuthentication([
        "path" => "/admin",
        "realm" => "Protected",
        "authenticator" => new PdoAuthenticator([
            "pdo" => $pdo,
            "table" => "users",
            "user" => "user",
            "hash" => "hash"
        ])
    ]));
    
    Source code(tar.gz)
    Source code(zip)
  • 0.7.1(Nov 5, 2014)

  • 0.7.0(Aug 7, 2014)

    Note! Class was renamed from HttpBasicAuth to HttpBasicAuthentication. BC will be maintained for a while. Make sure to update your code!

    Possibility to authenticate against custom datasource was added. Custom authenticator class must implement authenticate($user, $pass) method. It must return either true or false.

    use \Slim\Middleware\HttpBasicAuthentication\AuthenticatorInterface;
    
    class RandomAuthenticator implements AuthenticatorInterface {
        public function authenticate($user, $pass) {
            return (bool)rand(0,1);
        }
    }
    
    $app = new \Slim\Slim();
    
    $app->add(new \Slim\Middleware\HttpBasicAuthentication([
        "path" => "/admin",
        "realm" => "Protected",
        "authenticator" => new RandomAuthenticator()
    ]));
    
    Source code(tar.gz)
    Source code(zip)
  • 0.6.0(Aug 7, 2014)

    Support for FastCGI workarounds was added by adding environment configuration option.

    $app = new \Slim\Slim();
    
    $app->add(new \Slim\Middleware\HttpBasicAuthentication(array(
        "path" => "/admin",
        "realm" => "Protected",
        "users" => array(
            "root" => "t00r",
            "user" => "passw0rd"
        ),
        "environment" => "REDIRECT_HTTP_AUTHORIZATION"
    )));
    
    Source code(tar.gz)
    Source code(zip)
  • 0.5.0(Aug 7, 2014)

Basic Authentication handler for the JSON API, used for development and debugging purposes

Basic Authentication handler This plugin adds Basic Authentication to a WordPress site. Note that this plugin requires sending your username and passw

WordPress REST API Team 667 Dec 31, 2022
This is a basic Oauth2 authorization/authentication server implemented using Mezzio.

Mezzio-OAuth2-Authorization-Authentication-Server This is a basic OAuth2 authorization/authentication server implemented using Mezzio. I have found so

null 1 Nov 15, 2022
HTTP Basic Auth Guard for Lumen 5.x

HTTP Basic Auth Guard HTTP Basic Auth Guard is a Lumen Package that lets you use basic as your driver for the authentication guard in your application

Christopher Lass 40 Nov 11, 2022
Stateless HTTP basic auth for Laravel without the need for a database.

Laravel Very Basic Auth Documentation available in: ???? English ???? 日本語 This package allows you to add a HTTP Basic Auth filter on your routes, with

Marcus Olsson 141 Dec 31, 2022
It's a Laravel 8 authentication markdown that will help you to understand and grasp all the underlying functionality for Session and API Authentication

About Auth Starter It's a Laravel 8 authentication markdown that will help you to understand and grasp all the underlying functionality for Session an

Sami Alateya 10 Aug 3, 2022
Rinvex Authy is a simple wrapper for @Authy TOTP API, the best rated Two-Factor Authentication service for consumers, simplest 2fa Rest API for developers and a strong authentication platform for the enterprise.

Rinvex Authy Rinvex Authy is a simple wrapper for Authy TOTP API, the best rated Two-Factor Authentication service for consumers, simplest 2fa Rest AP

Rinvex 34 Feb 14, 2022
phpCAS is an authentication library that allows PHP applications to easily authenticate users via a Central Authentication Service (CAS) server.

phpCAS is an authentication library that allows PHP applications to easily authenticate users via a Central Authentication Service (CAS) server.

Apereo Foundation 780 Dec 24, 2022
Library to manage HTTP authentication with PHP. Includes ServiceProviders for easy Laravel integration.

Intervention HttpAuth Library to manage HTTP authentication with PHP. Includes ServiceProviders for easy Laravel integration. Installation You can ins

null 69 Jul 14, 2022
Static utilitiy classes to bridge PSR-7 http messages to OAuth2 Server requests and responses.

Static utilitiy classes to bridge PSR-7 http messages to OAuth2 Server requests and responses. While this libray is entended for use with Slim 3, it should work with any PSR-7 compatible framework.

Chad Gray 18 Jul 12, 2021
Routes and Middleware for Using OAuth2 Server within a Slim Framework API

Chadicus\Slim\OAuth2 A collection of OAuth2 Server routes, middleware and utilities for use within a Slim 3 Framework API Requirements Chadicus\Slim\O

Chad Gray 126 Oct 8, 2022
A Guzzle middleware to keep track of redirects

A Guzzle middleware to keep track of redirects This package contains middleware for Guzzle that allows you to track redirects that happened during a r

Spatie 17 Oct 9, 2022
Middleware to generate access logs for each request using the Apache's access log format

Middleware to generate access logs for each request using the Apache's access log format. This middleware requires a Psr log implementation, for example monolog.

Middlewares 20 Jun 23, 2022
Configurable Basic Auth based on Pimcore Documents

CORS Property Basic Auth This bundles allows to add basic auth based on Properties on Pimcore Documents. Simply use these properties password_enabled

CORS GmbH 1 Nov 12, 2021
PHP OpenID Connect Basic Client

PHP OpenID Connect Basic Client A simple library that allows an application to authenticate a user through the basic OpenID Connect flow. This library

Michael Jett 469 Dec 23, 2022
Laravel Auth is a Complete Build of Laravel 8 with Email Registration Verification, Social Authentication, User Roles and Permissions, User Profiles, and Admin restricted user management system.

Laravel Auth is a Complete Build of Laravel 8 with Email Registration Verification, Social Authentication, User Roles and Permissions, User Profiles, and Admin restricted user management system. Built on Bootstrap 4.

Jeremy Kenedy 2.8k Dec 31, 2022
Laravel Passport is an OAuth2 server and API authentication package that is simple and enjoyable to use

Introduction Laravel Passport is an OAuth2 server and API authentication package that is simple and enjoyable to use. Official Documentation Documenta

The Laravel Framework 3.1k Dec 31, 2022
Provides a unified interface to local and remote authentication systems.

Aura.Auth Provides authentication functionality and session tracking using various adapters; currently supported adapters are: Apache htpasswd files S

Aura for PHP 125 Sep 28, 2022
Minimal Laravel authentication scaffolding with Blade and Tailwind.

Introduction Breeze provides a minimal and simple starting point for building a Laravel application with authentication. Styled with Tailwind, Breeze

The Laravel Framework 2.1k Jan 3, 2023
This is registration and authentication forms written in PHP, JQuery

Registration-form This is registration and authentication forms written in PHP, JQuery Each file is: header.php - html-file for links "Главная", "Реги

Galina 2 Nov 2, 2021