protected function getEmailByToken($token)
{
$emailsUrl = 'https://api.github.com/user/emails?access_token=' . $token->getToken();
try {
$response = $this->getHttpClient()->get($emailsUrl, $this->getRequestOptions());
} catch (Exception $e) {
return;
}
foreach (json_decode($response->getBody(), true) as $email) {
if ($email['primary'] && $email['verified']) {
return $email['email'];
}
}
}