Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Openid - User details after authentication

I am trying to use Catalyst::Authentication::Credential::OpenID to authenticate users from Google. Once authentication is successful, I get a Catalyst::Plugin::Authentication::User::Hash object as my user. If users are logging in for the first time in my application, I want to get details of user from OpenID provider and store them in my DB. This is to ease the process of registration, I want as much details from OpenID as possible. But at least first name, last name, email etc..

But I am not able to achieve it. As an example, if I call, I get exception saying method *url,display * are not defined.

$c->user->url
$c->user->display

Any help in sorting it out is helpful.

like image 446
awake416 Avatar asked Feb 16 '26 09:02

awake416


1 Answers

After reading the Catalyst manual a number of times and getting some clue from Catalyst mailing lists, I came to know that we have to use extensions.

Because we will be using a number of different realms, I used progressive class.

Here is sample configuration used in my app, currently supporting only openID.

This uses Simple Registration Schema for OpenID Attribute Exchange defined at http://www.axschema.org/types/

'Plugin::Authentication' => {
    default_realm => 'progressive',
    realms => {
        progressive => {
            class  => 'Progressive',
            realms => [ 'openid' ],
        },
        openid => {
            credential => {
                class => "OpenID",
                store => {
                    class => "OpenID",
                },
                consumer_secret => "Don't bother setting",
                ua_class => "LWP::UserAgent",
                # whitelist is only relevant for LWPx::ParanoidAgent
                ua_args => {
                    whitelisted_hosts => [qw/ 127.0.0.1 localhost /],
                },
                extensions => [
                    'http://openid.net/srv/ax/1.0' => {
                        mode => 'fetch_request',
                        'type.nickname' => 'http://axschema.org/namePerson/friendly',
                        'type.email' => 'http://axschema.org/contact/email',
                        'type.fullname' => 'http://axschema.org/namePerson',
                        'type.firstname' => 'http://axschema.org/namePerson/first',
                        'type.lastname' => 'http://axschema.org/namePerson/last',
                        'type.dob' => 'http://axschema.org/birthDate',
                        'type.gender' => 'http://axschema.org/person/gender',
                        'type.country' => 'http://axschema.org/contact/country/home',
                        'type.language' => 'http://axschema.org/pref/language',
                        'type.timezone' => 'http://axschema.org/pref/timezone',
                        required => 'nickname,fullname,email,firstname,lastname,dob,gender,country',
                        if_available => 'dob,gender,language,timezone',
                    }
                ],
            },
        }
    }
},
like image 107
awake416 Avatar answered Feb 19 '26 06:02

awake416



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!