Christian Strang
Christian Strang

Reputation: 8530

Cakephp with OpenID and User Authentication

I have a table "users" and I want to enable my visitors to login with their openID Account. For this I use the OpenId Component for Cakephp and it works fine (When I login with the Google URL I receive the "successfully authenticated!" notification).

But now I'm kind of stuck because I don't know how to go on from there.

Upvotes: 8

Views: 3005

Answers (1)

dhofstet
dhofstet

Reputation: 9964

No, you don't have to access the "oid_associations" table, it is a table which is only used by the OpenID library.

Instead, you can use the identity_url to figure out whether it is a new user. If that's the case, you can then create an entry in your "users" table. For example (assuming your "users" table has an "openid" column):

$response = $this->Openid->getResponse($returnTo);

if ($response->status == Auth_OpenID_SUCCESS) {
    $user = $this->User->findByOpenid($response->identity_url);
    if ($user) {
        // existing user
    } else {
        // new user -> create user entry in the database
    }
}

I'm not sure I understand your second question correctly. If someone logs in with an OpenID and you get an Auth_OpenID_SUCESS response, then this means this user was sucessfully authenticated. How you use this information in your application is up to you.

I hope this answers your questions.

Upvotes: 7

Related Questions