$url = 'https://api.line.me/oauth2/v2.1/token';
$params = array(
'grant_type' => 'authorization_code',
'code' => $code,
'redirect_uri' => $this->strategy['redirect_uri'],
'client_id' => $this->strategy['channel_id'],
'client_secret' => $this->strategy['channel_secret']
);
$option = array('http' => array('header' => 'Content-Type: application/x-www-form-urlencoded'));
$response = $this->serverPost($url, $params,$option, $headers);
$results = json_decode($response);
//$userEmail = $this->_userEmail($results->id_token);
$id_token = $results->id_token;
//JWT 驗證 id token
$remainder = strlen($id_token) % 4;
if ($remainder)
{
$padlen = 4 - $remainder;
$id_token .= str_repeat('=', $padlen);
}
$response=base64_decode(strtr($id_token, '-_', '+/'));
$cc=preg_match('/({.+})({.+})/',$response,$res);
$results = json_decode($res[2], true);
if(empty($results['email'])) return 'empty';
else return $results['email'];
參考:
http://www.zzv.cn/index.php?c=content&a=show&id=132
https://hotexamples.com/examples/-/JWT/urlsafeB64Decode/php-jwt-urlsafeb64decode-method-examples.html
https://jwt.io/