Skip to content

Commit

Permalink
Update Provider.php (#136)
Browse files Browse the repository at this point in the history
custom user mapping
  • Loading branch information
recca0120 authored and faustbrian committed Jan 19, 2018
1 parent 48af2b0 commit 2fad04e
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,18 @@ class Provider extends AbstractProvider implements ProviderInterface
*/
public static function additionalConfigKeys()
{
return ['host', 'authorize_uri', 'token_uri', 'userinfo_uri', 'userinfo_key'];
return [
'host',
'authorize_uri',
'token_uri',
'userinfo_uri',
'userinfo_key',
'user_id',
'user_nickname',
'user_name',
'user_email',
'user_avatar',
];
}

/**
Expand Down Expand Up @@ -80,11 +91,11 @@ protected function mapUserToObject(array $user)
$data = is_null($key) === true ? $user : Arr::get($user, $key, []);

return (new User())->setRaw($data)->map([
'id' => Arr::get($data, 'id'),
'nickname' => Arr::get($data, 'username'),
'name' => Arr::get($data, 'name'),
'email' => Arr::get($data, 'email'),
'avatar' => Arr::get($user, 'avatar'),
'id' => $this->getUserData($data, 'id'),
'nickname' => $this->getUserData($data, 'nickname'),
'name' => $this->getUserData($data, 'name'),
'email' => $this->getUserData($data, 'email'),
'avatar' => $this->getUserData($data, 'avatar'),
]);
}

Expand Down Expand Up @@ -113,4 +124,12 @@ protected function getLaravelPassportUrl($type)
'userinfo_uri' => 'api/user',
], $type))), '/');
}

/**
* {@inheritdoc}
*/
protected function getUserData($user, $key)
{
return Arr::get($user, $this->getConfig('user_'.$key, $key));
}
}

0 comments on commit 2fad04e

Please sign in to comment.