diff --git a/src/LineProvider.php b/src/LineProvider.php index fff3fcf..b25a844 100644 --- a/src/LineProvider.php +++ b/src/LineProvider.php @@ -7,13 +7,29 @@ class LineProvider extends AbstractProvider { + /** + * {@inheritdoc} + */ + protected $scopeSeparator = ' '; + + /** + * {@inheritdoc} + */ + protected $scopes = ['profile','openid','email']; + + /** + * {@inheritdoc} + */ + protected $id_token = ''; + + /** * {@inheritdoc} */ protected function getAuthUrl(string $state) { return $this->buildAuthUrlFromBase( - 'https://access.line.me/dialog/oauth/weblogin', $state + 'https://access.line.me/oauth2/v2.1/authorize', $state ); } @@ -22,7 +38,7 @@ protected function getAuthUrl(string $state) */ protected function getTokenUrl() { - return 'https://api.line.me/v2/oauth/accessToken'; + return 'https://api.line.me/oauth2/v2.1/token'; } /** @@ -30,12 +46,13 @@ protected function getTokenUrl() */ protected function getUserByToken(string $token) { - $response = $this->getHttpClient()->get( - 'https://api.line.me/v2/profile', [ - 'headers' => [ - 'Authorization' => 'Bearer ' . $token, - ], + + $response = $this->getHttpClient()->post( + 'https://api.line.me/oauth2/v2.1/verify', [ + 'headers' => ['Accept' => 'application/json'], + 'form_params' => ['id_token'=>$this->id_token, 'client_id' => $this->clientId], ]); + return json_decode($response->getBody()->getContents(), true); } @@ -45,11 +62,11 @@ protected function getUserByToken(string $token) protected function mapUserToObject(array $user) { return (new User())->setRaw($user)->map([ - 'id' => $user['userId'], + 'id' => $user['sub'], 'nickname' => null, - 'name' => $user['displayName'], - 'email' => null, - 'avatar' => $user['pictureUrl'] ?? null, + 'name' => $user['name'], + 'email' => $user['email'], + 'avatar' => $user['picture'] ?? null, ]); } @@ -62,4 +79,18 @@ protected function getTokenFields(string $code) 'grant_type' => 'authorization_code', ]); } + + /** + * {@inheritdoc} + */ + public function getAccessTokenResponse(string $code) + { + $response = $this->getHttpClient()->post($this->getTokenUrl(), [ + 'headers' => ['Accept' => 'application/json','Content-Type' => 'application/x-www-form-urlencoded'], + 'form_params' => $this->getTokenFields($code), + ]); + $array=json_decode($response->getBody(), true); + $this->id_token = $array['id_token'] ?? null; + return $array; + } }