Skip to content

Commit 30972c1

Browse files
Added email to X provider (#742)
* feat(x): Added email to XProvider X has added email to OAuth2: https://devcommunity.x.com/t/announcing-support-for-email-address-retrieval-with-oauth-2-0-in-the-x-api-v2/240555 * Formatting --------- Co-authored-by: Taylor Otwell <[email protected]>
1 parent d17ffe3 commit 30972c1

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/Two/XProvider.php

+13-1
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,21 @@ protected function getUserByToken($token)
3030
{
3131
$response = $this->getHttpClient()->get('https://api.x.com/2/users/me', [
3232
RequestOptions::HEADERS => ['Authorization' => 'Bearer '.$token],
33-
RequestOptions::QUERY => ['user.fields' => 'profile_image_url'],
33+
RequestOptions::QUERY => ['user.fields' => 'profile_image_url,confirmed_email'],
3434
]);
3535

3636
return Arr::get(json_decode($response->getBody(), true), 'data');
3737
}
38+
39+
/**
40+
* {@inheritdoc}
41+
*/
42+
protected function mapUserToObject(array $user)
43+
{
44+
$user = parent::mapUserToObject($user);
45+
46+
$user->email = $user['confirmed_email'];
47+
48+
return $user;
49+
}
3850
}

0 commit comments

Comments
 (0)