Overtrue\Socialite\Providers\GitHubProvider::getEmailByToken PHP Method

getEmailByToken() protected method

Get the email for the given access token.
protected getEmailByToken ( string $token ) : string | null
$token string
return string | null
    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'];
            }
        }
    }