Tuesday, February 25, 2014

Help! Auth Component in Lib directory

Hi all, I'm struggling getting this code working, wondering if anyone had any insights


I've written an application that has a lot of web services, It used Zend to create a server and loads classes from my lib folder

So my structure is like this:

app/Controller/WebServicesController.php
app/Lib/WebServices/SomeService.php

The controller loads the requested service and passes it as an argument to the Zend SOAP server code. It works fine, except where I need the response from the Auth Component.

I want a partner site to be able to validate a username/password as part of a unified login. So if a user tries logging in to site X, that site will call my web service with the username and password and return the result of Auth:identify.

This is the relevant code in my SomeService.php file, I've attempted to initialize the Auth Component as I do in the standard login procedure, but it ALWAYS returns false, even if the credentials are correct:

function check_credentials($username, $password) {
    $userObj = new CakeRequest();
    $userObj->data['User'] = array('username'=>$username, 'password'=>$password);

    $resp = new CakeResponse();

    App::import('Component', 'Auth');
    $Auth = new AuthComponent(new ComponentCollection());
    $Auth::initialize();

    $Auth->authenticate = array(
                                'all' => array('userModel' => 'User'),
                                );

    $result = $Auth->identify($userArr,$resp);

    return $result;

}

Any help would be greatly appreciated!

--
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 cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: