0

When user submits login form, for authenticating that user instead of using cakephp default authentication $this->Auth->login() I want to call some java based api where I will send user id and password entered by user and that api will return user details if user is authentic and false if not. I want to use cakephp AuthComponent for rest of thing (for example: sessions etc) but just for authenticating a user I want to call my api. Is this possible ? can I override some core method ?

Thanks.

1
  • I'm no CakePHP expert but I would think you'd be able to populate/create the Auth object manually based on what you get back from the API call. Commented Feb 13, 2014 at 11:16

3 Answers 3

1

I think this covers it, under "Creating Custom Authentication Objects"

http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html

Sign up to request clarification or add additional context in comments.

Comments

0

You can create a class extending BaseAuthenticate in Controllers/Component/Auth folder path. There you have to implement an authenticate() method that, if logged successfully, have to return an array with user data, and if not, return false.

Then you tell Auth component to use your custom authenticate when you call it in AppController by:

'Auth' => array(
    'authenticate' => array(
        'yourNewAuth' => array(
            //other stuff
        )
    )
)

2 Comments

Thanks. I created the authenticate class. It's working fine if I return user details array but in case of FALSE(i.e. user not found), cakephp ignores that and logs the user in(ignoring my class), although it should show error.
looks like, cakephp running its own default authenticate function after running mine. how can i fix this\?
0

you can set AuthComponent::$sessionKey to false to ensure AuthComponent doesn’t try to read user info from session.

http://api.cakephp.org/2.4/class-AuthComponent.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.