Revision 320

Date:
2013/04/25 13:13:34
Author:
ahitrov
Revision Log:
New FACEBOOK_SCOPE parameter in config. Now we can get emails from Facebook
Credentials concatenation for logged users for Facebook and VK
Files:

Legend:

 
Added
 
Removed
 
Modified
  • utf8/plugins/session/config.proto

     
    60 60
    61 61 REWRITE += FACEBOOK_APP_ID FACEBOOK_APP_SECRET FACEBOOK_REDIRECT_URL FACEBOOK_USER_POST_URL
    62 62
    63 ### if additional rights needed:
    64 FACEBOOK_SCOPE =
    65 REWRITE += FACEBOOK_SCOPE
    63 66
    64 67 ### AUTH::VKontakte
    65 68 ######################################
  • utf8/plugins/session/lib/session/AUTH/FaceBook.pm

     
    51 51 $self->{$_} = $config{$_} || $state->{session}{$_} || return undef;
    52 52 }
    53 53 $self->{timeout} = $state->{session}{connection_timeout} || 3;
    54 for (qw(facebook_user_post_url facebook_redirect_uri)) {
    54 for (qw(facebook_user_post_url facebook_redirect_uri facebook_scope)) {
    55 55 $self->{$_} = $config{$_} || $state->{session}{$_};
    56 56 }
    57 57 return $self;
     
    63 63 my $go = URI->new( $self->{facebook_authorize_url} );
    64 64 $go->query_param( client_id => $self->{facebook_app_id} );
    65 65 $go->query_param( state => $args{state} ) if $args{state};
    66 $go->query_param( scope => "publish_stream" );
    66 $go->query_param( scope => $self->{facebook_scope} ) if $self->{facebook_scope};
    67 67 $args{redirect_uri} ||= $self->{facebook_redirect_uri};
    68 68 for ( keys %args ) {
    69 69 $go->query_param( $_ => $args{$_} );
     
    143 143
    144 144 my @plugins = split (/[\ |\t]+/, $state->{plugins});
    145 145 my $name = Encode::encode('utf-8', $info->{name});
    146 my $email = exists $info->{email} && $info->{email} ? $info->{email} : undef;
    146 147 if ( grep { $_ eq 'users' } @plugins ) {
    147 148 my $user;
    148 149 if ( $state->{users}->use_credentials ) {
    149 $user = $keeper->{users}->get_profile( facebook => $info->{id} );
    150 if ( $local_session->id ) {
    151 $user = $keeper->{users}->get_profile( id => $local_session->{id} );
    152 } else {
    153 $user = $keeper->{users}->get_profile( facebook => $info->{id} );
    154 }
    150 155 }
    156 if ( !ref $user && $email ) {
    157 $user = $keeper->{users}->get_profile( email => $keeper->{users}->_email_reduction( $email ) );
    158 }
    151 159 unless ( ref $user ) {
    152 160 $user = $keeper->{users}->get_profile( login => 'facebook:'.$info->{id} );
    153 161 }
     
    155 163 my $user_class = $state->{users}->profile_document_class;
    156 164 $user = $user_class->new( $keeper );
    157 165 my %props = map { $_->{attr} => $_ } $user->structure;
    158 $user->login( 'facebook:'.$info->{id} );
    166 $user->login( $email || 'facebook:'.$info->{id} );
    159 167 $user->name( $name );
    160 168 $user->status( 1 );
    161 169 $user->type( 0 );
     
    163 171 if ( exists $props{country} ) {
    164 172 $user->country( $info->{locale} );
    165 173 }
    166 $user->email( undef );
    174 $user->email( $email );
    167 175
    168 176 my ($prop_ava) = grep { $_->{attr} eq 'avatar' && $_->{type} eq 'image' } $user->structure;
    169 177 if ( ref $prop_ava ) {
     
    188 196 facebook => $info->{id},
    189 197 avatar => 'https://graph.facebook.com/'.$info->{username}.'/picture?type=large',
    190 198 );
    199 if ( exists $info->{email} && $info->{email} ) {
    200 $user->create_credential(
    201 email => $info->{email},
    202 status => 1,
    203 );
    204 }
    191 205 }
    192 206 my %data = (
    193 207 id => $user->id,
     
    198 212 ltime => time,
    199 213 avatar => 'https://graph.facebook.com/'.$info->{username}.'/picture',
    200 214 );
    215 $data{email} = $email if $email;
    201 216 $local_session->set( %data );
    202 217 } else {
    203 218 my %data = (
     
    210 225 ltime => time,
    211 226 avatar => 'https://graph.facebook.com/'.$info->{username}.'/picture?type=large',
    212 227 );
    228 $data{email} = $email if $email;
    213 229 $local_session->set ( %data );
    214 230 }
    215 231 return $local_session;
  • utf8/plugins/session/lib/session/AUTH/VKontakte.pm

     
    148 148 if ( grep { $_ eq 'users' } @plugins ) {
    149 149 my $user;
    150 150 if ( $state->{users}->use_credentials ) {
    151 $user = $keeper->{users}->get_profile( vkontakte => $user_info->{uid} );
    151 if ( $local_session->id ) {
    152 $user = $keeper->{users}->get_profile( id => $local_session->{id} );
    153 } else {
    154 $user = $keeper->{users}->get_profile( vkontakte => $user_info->{uid} );
    155 }
    152 156 }
    153 157 unless ( ref $user ) {
    154 158 $user = $keeper->{users}->get_profile( login => 'vkontakte:'.$user_info->{uid} );
  • utf8/plugins/session/lib/session/State.pm.proto

     
    63 63 $self->{facebook_app_id} = '@FACEBOOK_APP_ID@';
    64 64 $self->{facebook_app_secret} = '@FACEBOOK_APP_SECRET@';
    65 65 $self->{facebook_redirect_uri} = '@FACEBOOK_REDIRECT_URL@';
    66 $self->{facebook_scope} = '@FACEBOOK_SCOPE@';
    66 67 $self->{facebook_user_post_url} = '@FACEBOOK_USER_POST_URL@';
    67 68
    68 69 $self->{vk_app_id} = '@VK_APP_ID@';