Index: VKontakte.pm =================================================================== --- VKontakte.pm (revision 511) +++ VKontakte.pm (revision 512) @@ -33,6 +33,25 @@ =cut +our %SCOPE = ( + 'notify' => 1, + 'friends' => 2, + 'photos' => 4, + 'audio' => 8, + 'video' => 16, + 'docs' => 131072, + 'notes' => 2048, + 'pages' => 128, + 'menu_link' => 256, + 'status' => 1024, + 'groups' => 262144, + 'email' => 4194304, + 'notifications' => 524288, + 'stats' => 1048576, + 'ads' => 32768, + 'offline' => 65536, +); + sub new { my ($class, %config) = @_; my $self = bless {}, $class; @@ -41,7 +60,7 @@ $self->{vk_access_token_url} = 'https://oauth.vk.com/access_token'; $self->{vk_user_info_url} = 'https://api.vk.com/method/getProfiles'; - for (qw( vk_app_id vk_app_secret )) { + for (qw( vk_app_id vk_app_secret vk_scope)) { $self->{$_} = $config{$_} || $state->{session}->{$_} || return undef; } $self->{timeout} = $state->{session}->{connection_timeout} || 3; @@ -56,7 +75,7 @@ my (%args) = @_; my $go = URI->new( $self->{vk_authorize_url} ); $go->query_param( client_id => $self->{vk_app_id} ); - $go->query_param( scope => '' ); + $go->query_param( scope => $self->{vk_scope} || '' ); $go->query_param( response_type => 'code' ); $args{redirect_uri} ||= $self->{vk_redirect_uri}; for ( keys %args ) { @@ -145,6 +164,7 @@ my @plugins = split (/[\ |\t]+/, $state->{plugins}); my $name = $user_info->{first_name}.' '.$user_info->{last_name}; + my $email = exists $user_info->{email} && $user_info->{email} ? $user_info->{email} : undef; if ( grep { $_ eq 'users' } @plugins ) { my $user; if ( $state->{users}->use_credentials ) { @@ -170,7 +190,7 @@ if ( exists $props{country} ) { $user->country( $user_info->{country} ); } - $user->email( undef ); + $user->email( $email ); my ($prop_ava) = grep { $_->{attr} eq 'avatar' && $_->{type} eq 'image' } $user->structure; if ( ref $prop_ava ) { @@ -217,6 +237,9 @@ if ( $user_info->{photo} ) { $data{avatar} = $user_info->{photo}; } + if ( $user_info->{email} ) { + $data{email} = $user_info->{email}; + } $local_session->set( %data ); } return $local_session;