paradox870
paradox870

Reputation: 2202

Manually Authorize User in CakePHP

I am looking to manually authorize a user knowing the username. This account however, has no password. It is an account created with an association to a Twitter account in another table. I can verify that the correct twitter account is trying to sign in, but I need to be able to use the Auth component to authorize the user linked to this twitter account.

All accounts that are linked to a twitter account are created in the same fashion, without a password. Since we are planning to make changes to improve this later, a generic password is not a viable option - we need to authenticate the user regardless of what is (or isn't) in the password field of the users table.

Upvotes: 2

Views: 4149

Answers (3)

John C. Martin
John C. Martin

Reputation: 94

Cake 2.3 + apparently requires this to now be in an array in order to work properly:

$this->Auth->login(array('id' =>$user['User']['id']));

It did not work just passing the id as a single integer.

Upvotes: 3

Sumith Harshan
Sumith Harshan

Reputation: 6445

$this->Auth->login($user['User']['id']);
$this->Auth->login($user['User']['username']);
$this->Auth->login($user['User']['password']);  // hashed password

Upvotes: 0

deceze
deceze

Reputation: 522520

I suppose by "authorize" you mean "authenticate" or "log in". That's as simple as passing the primary id of the user record to Auth::login():

$user = $this->User->find('first', array('conditions' => array('twitter_id' => ...)));
$this->Auth->login($user['User']['id']);

Upvotes: 10

Related Questions