Skip to content
This repository was archived by the owner on Jul 3, 2025. It is now read-only.
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 42 additions & 11 deletions src/LineProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}

Expand All @@ -22,20 +38,21 @@ 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';
}

/**
* {@inheritdoc}
*/
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);
}

Expand All @@ -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,
]);
}

Expand All @@ -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;
}
}