1
0
Fork 0
mirror of synced 2024-09-30 17:26:48 +13:00

chore: google oauth adapter changes

This commit is contained in:
Christy Jacob 2020-01-18 20:57:48 +05:30
parent d2a19207c2
commit ba96505aa4
2 changed files with 22 additions and 14 deletions

View file

@ -38,7 +38,7 @@ class Apple extends OAuth
'state' => json_encode($this->state),
'response_type' => 'code',
'response_mode' => 'form_post',
'scope' => implode('+', $this->getScopes())
'scope' => implode(' ', $this->getScopes())
]);
}

View file

@ -14,6 +14,12 @@ class Google extends OAuth
* @var string
*/
protected $version = 'v4';
/**
* @var array
*/
protected $scopes = ['https://www.googleapis.com/auth/userinfo.email','https://www.googleapis.com/auth/userinfo.profile'];
/**
* @var array
*/
@ -32,12 +38,13 @@ class Google extends OAuth
*/
public function getLoginURL(): string
{
return 'https://accounts.google.com/o/oauth2/v2/auth?'.
'client_id='.urlencode($this->appID).
'&redirect_uri='.urlencode($this->callback).
'&scope=https://www.googleapis.com/auth/userinfo.email+https://www.googleapis.com/auth/userinfo.profile'.
'&state='.urlencode(json_encode($this->state)).
'&response_type=code';
return 'https://accounts.google.com/o/oauth2/v2/auth?'. http_build_query([
'client_id' => $this->appID,
'redirect_uri' => $this->callback,
'scope' => implode(' ', $this->getScopes()),
'state' => json_encode($this->state),
'response_type' => 'code'
]);
}
/**
@ -49,13 +56,14 @@ class Google extends OAuth
{
$accessToken = $this->request(
'POST',
'https://www.googleapis.com/oauth2/'.$this->version.'/token?'.
'code='.urlencode($code).
'&client_id='.urlencode($this->appID).
'&client_secret='.urlencode($this->appSecret).
'&redirect_uri='.urlencode($this->callback).
'&scope='.
'&grant_type=authorization_code'
'https://www.googleapis.com/oauth2/'.$this->version.'/token?'.http_build_query([
'code' => $code,
'client_id' => $this->appID,
'client_secret' => $this->appSecret,
'redirect_uri' => $this->callback,
'scope' => null,
'grant_type' => 'authorization_code'
])
);
$accessToken = json_decode($accessToken, true);