Openid - user data after authentication

I am trying to use Catalyst :: Authentication :: Credential :: OpenID to authenticate users from Google. After successful authentication, I get the Catalyst :: Plugin :: Authentication :: User :: Hash object as my user. If users register for the first time in my application, I want to get information about the user from the OpenID provider and save them in my database. This facilitates the registration process, I want as much details as possible from OpenID. But at least the first name, last name, email address, etc.

But I can’t achieve this. As an example, if I call, I get an exception saying the method * url, display * are not defined.

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

Any help in sorting it is helpful.

+3
source share
1 answer

After reading the Catalyst manual several times and getting some help from the Catalyst mailing lists, I found out that we should use the extensions.

Since we will use several different areas, I used a progressive class.

Here is an example configuration used in my application that currently only supports openID.

This uses a simple registration scheme for the OpenID Exchange attribute, 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',
                    }
                ],
            },
        }
    }
},
+2
source

Source: https://habr.com/ru/post/1779458/


All Articles