hoauth icon indicating copy to clipboard operation
hoauth copied to clipboard

Attibutes Mapping not used

Open Herve-M opened this issue 11 years ago • 3 comments

Hy,

After installing and setting parameter, I can't login/signin. Every time I get error like :

2014/09/21 12:38:48 [error] [exception.CException] exception 'CException' with message 'Property "User.email" is not defined.' in website/protected/vendor/framework/base/CComponent.php:130
Stack trace:
#0 website/protected/vendor/framework/db/ar/CActiveRecord.php(145): CComponent->__get('email')
#1 website/protected/extensions/hoauth/HOAuthAction.php(234): CActiveRecord->__get('email')
#2 website/protected/extensions/hoauth/HOAuthAction.php(163): HOAuthAction->getAccessCode()
#3 website/protected/extensions/hoauth/HOAuthAction.php(136): HOAuthAction->oAuth('Live')
#4 website/protected/vendor/framework/web/actions/CAction.php(76): HOAuthAction->run()
#5 website/protected/vendor/framework/web/CController.php(308): CAction->runWithParams(Array)
#6 website/protected/vendor/framework/web/CController.php(286): CController->runAction(Object(HOAuthAction))
#7 website/protected/vendor/framework/web/CController.php(265): CController->runActionWithFilters(Object(HOAuthAction), Array)
#8 website/protected/vendor/framework/web/CWebApplication.php(282): CController->run('oauth')
#9 website/protected/vendor/framework/web/CWebApplication.php(141): CWebApplication->runController('site/oauth')
#10 website/protected/vendor/framework/base/CApplication.php(180): CWebApplication->processRequest()
#11 website/index.php(13): CApplication->run()
#12 {main}
REQUEST_URI=/site/oauth?provider=Live

After some research doing a CVardump to the $user give :

[trace] [application] Test User: User#1
(
    [CActiveRecord:_new] => false
    [CActiveRecord:_attributes] => array
    (
        'USER_ID' => '2'
        'USERSTATE_ID' => '2'
        'USERCLASS_ID' => '3'
        'USER_LASTNAME' => 'LASTTest'
        'USER_FORNAME' => 'FORTest'
        'USER_EMAIL' => '[email protected]'
        'USER_PASSWORD' => 'hashedpassword'
    )
    [CActiveRecord:_related] => array()
    [CActiveRecord:_c] => null
    [CActiveRecord:_pk] => '2'
    [CActiveRecord:_alias] => 't'
    [CModel:_errors] => array()
    [CModel:_validators] => null
    [CModel:_scenario] => 'update'
    [CComponent:_e] => null
    [CComponent:_m] => null
)

But even using $user->_emailAttribute or $user->USER_EMAIL give a null value making a null identity etc..

All other part of website run, so I don't know why here...

PS: will be good to precise what getId / getName must return in UserIdentity for who don't use yii-user.

My Config:

'oauth' => array(
    // the list of additional properties of this action is below
    'class' => 'ext.hoauth.HOAuthAction',
    'model' => 'User',
    // model attribute => profile attribute
    'attributes' => array(
        'USER_EMAIL' => 'email',
        'USER_FORNAME' => 'firstName',
        'USER_LASTNAME' => 'lastName',
    ),
),

System Spec : PHP 5.4.33 Yii yii-1.1.15.022a51 hoauth 1.2.5

Herve-M avatar Sep 21 '14 10:09 Herve-M

There is the instruction for both attributes property and UserIdentity in README.

In attributes you should specify the attributes of your User model as keys and coresponding fields of social user profile as values. As I see, you have already done that.

And here is the example of UserIdentity class: https://github.com/SleepWalker/hoauth/wiki/UserIdentity-class-example. UserIdentity::getId() and UserIdentity::getName() do not matter for auth, because they will be filled in afterwards.

When hoauth tries to authenticate user, it will path the login of user (e.g. email) and null as pasword to your's UserIdentity class. So if you have null as password, you should handle user as that from hoauth (don't forget about strict equal operator ===)

SleepWalker avatar Sep 21 '14 12:09 SleepWalker

I use your version of UserIdentity, just changed the findBy. Only problem is hoauth tries to authenticate user with null for email and password.

The User get loaded but attributes aren't accessible... CVardump show it, accessing it with $user->attName don't.

Herve-M avatar Sep 21 '14 12:09 Herve-M

Hmm, I can't understand. From where do you try to access those attributes? Probably it will be easier if you post your user's table sql, User model and UserIdentity. Than, we will surely find the true answer.

SleepWalker avatar Oct 04 '14 17:10 SleepWalker