Revision 511

Date:
2015/09/18 14:48:19
Author:
ahitrov
Revision Log:
New rules in Facebook oAuth protocol

Files:

Legend:

 
Added
 
Removed
 
Modified
  • utf8/plugins/session/lib/session/AUTH/FaceBook.pm

     
    54 54 for (qw(facebook_user_post_url facebook_redirect_uri facebook_scope)) {
    55 55 $self->{$_} = $config{$_} || $state->{session}{$_};
    56 56 }
    57 if ( exists $self->{facebook_scope} && $self->{facebook_scope} ) {
    58 @{$self->{facebook_fields}} = split /[\,\ ]+/, $self->{facebook_scope};
    59 }
    57 60 return $self;
    58 61 }
    59 62
     
    123 126 }
    124 127
    125 128 my $req = URI->new( $self->{facebook_user_info_url} );
    126 $req->query_param( access_token => $access_token );
    129 my @req_fields = qw( id name gender location picture.width(720).height(720).as(picture_large) );
    130 if ( exists $self->{facebook_fields} && ref $self->{facebook_fields} eq 'ARRAY' && @{$self->{facebook_fields}} ) {
    131 push @req_fields, @{$self->{facebook_fields}};
    132 }
    133 $req->query_param( fields => join(',', @req_fields) );
    134 $req->query_param( access_token => $access_token );
    127 135
    128 136 warn "Fetching user $req" if $DEBUG;
    129 137 my $res = $ua->get($req);
     
    144 152 my @plugins = split (/[\ |\t]+/, $state->{plugins});
    145 153 my $name = Encode::encode('utf-8', $info->{name});
    146 154 my $email = exists $info->{email} && $info->{email} ? $info->{email} : undef;
    155 my $avatar_url = exists $info->{picture_large} ? $info->{picture_large}{data}{url} : 'https://graph.facebook.com/'.$info->{id}.'/picture?type=large';
    147 156 if ( grep { $_ eq 'users' } @plugins ) {
    148 157 my $user;
    149 158 if ( $state->{users}->use_credentials ) {
     
    175 184
    176 185 my ($prop_ava) = grep { $_->{attr} eq 'avatar' && $_->{type} eq 'image' } $user->structure;
    177 186 if ( ref $prop_ava ) {
    178 my $avatar = $user->_store_image( 'https://graph.facebook.com/'.$info->{username}.'/picture?type=large', attr => 'avatar' );
    187 my $avatar = $user->_store_image( $avatar_url, attr => 'avatar' );
    179 188 $user->avatar( $user->_serialize($avatar) );
    180 189 }
    181 190
     
    185 194 if ( ref $prop_ava ) {
    186 195 my $avatar = $user->get_image( 'avatar' );
    187 196 unless ( ref $avatar && exists $avatar->{filename} ) {
    188 my $avatar = $user->_store_image( 'https://graph.facebook.com/'.$info->{username}.'/picture?type=large', attr => 'avatar' );
    197 my $avatar = $user->_store_image( $avatar_url, attr => 'avatar' );
    189 198 $user->avatar( $user->_serialize($avatar) );
    190 199 $user->store;
    191 200 }
     
    194 203 if ( $state->{users}->use_credentials ) {
    195 204 $user->create_credential(
    196 205 facebook => $info->{id},
    197 avatar => 'https://graph.facebook.com/'.$info->{username}.'/picture?type=large',
    206 avatar => $avatar_url,
    198 207 );
    199 208 if ( exists $info->{email} && $info->{email} ) {
    200 209 $user->create_credential(
     
    205 214 }
    206 215 my %data = session::Keeper::_get_hash_from_profile( $user );
    207 216 $data{auth_by} = 'facebook';
    208 $data{avatar} ||= 'https://graph.facebook.com/'.$info->{username}.'/picture';
    217 $data{avatar} ||= 'https://graph.facebook.com/'.$info->{id}.'/picture?type=square';
    209 218 $data{email} ||= $email if $email;
    210 219 $local_session->set( %data );
    211 220 } else {