Cake 3 Base Authentication without Model

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Cake 3 Base Authentication without Model

Rumkuchen
I want to use Basic Authentication without a Model - so I want to verify the credentials in a controller....
Is that possible? I know how to do it with Form-Authentication but not with Basic Authentication.

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Cake 3 Base Authentication without Model

Rumkuchen
just found a way to solve it :-)
I do not know, if it is the best way to implement and to place it...
The docu helped my

created a file "/vendor/cakephp/src/Auth/Basic2Authenticate.php"
(I hope, it does not disappear after update via composer)

<?php
namespace Cake\Auth;

use Cake\Network\Exception\UnauthorizedException;
use Cake\Network\Request;
use Cake\Network\Response;

class Basic2Authenticate extends BasicAuthenticate
{

    public function authenticate(Request $request, Response $response)
    {
        return $this->getUser($request);
    }

    public function getUser(Request $request)
    {
        $username = $request->env('PHP_AUTH_USER');
        $pass = $request->env('PHP_AUTH_PW');
        if (!is_string($username) || $username === '' || !is_string($pass) || $pass === '') {
            return false;
        }
        if ($username === 'foo' && $pass === "bar") {
            return ['User' => $username, 'Password' => $pass];
        }
        return false;
    }

}


Am Samstag, 28. November 2015 10:39:25 UTC+1 schrieb Rumkuchen:
I want to use Basic Authentication without a Model - so I want to verify the credentials in a controller....
Is that possible? I know how to do it with Form-Authentication but not with Basic Authentication.

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.