1
0
Fork 0
mirror of synced 2024-06-26 18:20:43 +12:00

chore: refactoring OAuth Adapters

This commit is contained in:
Christy Jacob 2020-01-19 01:42:41 +05:30
parent e8cf1cb977
commit 4d4745ccd2
13 changed files with 63 additions and 25 deletions

View file

@ -17,7 +17,10 @@ class Apple extends OAuth
/**
* @var array
*/
protected $scopes = ["name", "email"];
protected $scopes = [
"name",
"email"
];
/**
* @return string

View file

@ -20,7 +20,7 @@ class Discord extends OAuth
protected $user = [];
protected $scope = [
protected $scopes = [
'identify',
'email'
];
@ -42,7 +42,7 @@ class Discord extends OAuth
http_build_query([
'response_type' => 'code',
'client_id' => $this->appID,
'scope' => implode(' ', $this->scope),
'scope' => implode(' ', $this->getScopes()),
'redirect_uri' => $this->callback
]);

View file

@ -19,7 +19,9 @@ class Facebook extends OAuth
/**
* @var array
*/
protected $scopes = ['email'];
protected $scopes = [
'email'
];
/**
* @return string

View file

@ -14,7 +14,9 @@ class Github extends OAuth
/**
* @var array
*/
protected $scopes = ['user:email'];
protected $scopes = [
'user:email'
];
/**
* @return string

View file

@ -17,7 +17,9 @@ class Gitlab extends OAuth
/**
* @var array
*/
protected $scopes = ['read_user'];
protected $scopes = [
'read_user'
];
/**
* @return string

View file

@ -18,7 +18,10 @@ class Google extends OAuth
/**
* @var array
*/
protected $scopes = ['https://www.googleapis.com/auth/userinfo.email','https://www.googleapis.com/auth/userinfo.profile'];
protected $scopes = [
'https://www.googleapis.com/auth/userinfo.email',
'https://www.googleapis.com/auth/userinfo.profile'
];
/**
* @var array

View file

@ -17,7 +17,10 @@ class Microsoft extends OAuth
/**
* @var array
*/
protected $scopes = ['offline_access', 'user.read'];
protected $scopes = [
'offline_access',
'user.read'
];
/**
* @return string

View file

@ -11,6 +11,13 @@ class Mock extends OAuth
*/
protected $version = 'v1';
/**
* @var array
*/
protected $scopes = [
'email'
];
/**
* @var array
*/
@ -29,7 +36,12 @@ class Mock extends OAuth
*/
public function getLoginURL():string
{
return 'http://localhost/'.$this->version.'/oauth?client_id='.urlencode($this->appID).'&redirect_uri='.urlencode($this->callback).'&scope=email&state='.urlencode(json_encode($this->state));
return 'http://localhost/'.$this->version.'/oauth?'. http_build_query([
'client_id' => $this->appID,
'redirect_uri' => $this->callback,
'scope' => implode(' ', $this->getScopes()),
'state' => json_encode($this->state)
]);
}
/**
@ -42,10 +54,12 @@ class Mock extends OAuth
$accessToken = $this->request(
'GET',
'http://localhost/'.$this->version.'/oauth/token?'.
'client_id='.urlencode($this->appID).
'&redirect_uri='.urlencode($this->callback).
'&client_secret='.urlencode($this->appSecret).
'&code='.urlencode($code)
http_build_query([
'client_id' => $this->appID,
'redirect_uri' => $this->callback,
'client_secret' => $this->appSecret,
'code' => $code
])
);
$accessToken = json_decode($accessToken, true); //

View file

@ -14,7 +14,12 @@ class Slack extends OAuth
/**
* @var array
*/
protected $scopes = ['identity.avatar', 'identity.basic', 'identity.email','identity.team'];
protected $scopes = [
'identity.avatar',
'identity.basic',
'identity.email',
'identity.team'
];
/**
* @return string

View file

@ -23,7 +23,7 @@ class Spotify extends OAuth
/**
* @var array
*/
protected $scope = [
protected $scopes = [
'user-read-email',
];
@ -49,7 +49,7 @@ class Spotify extends OAuth
http_build_query([
'response_type' => 'code',
'client_id' => $this->appID,
'scope' => implode(' ', $this->scope),
'scope' => implode(' ', $this->getScopes()),
'redirect_uri' => $this->callback,
'state' => json_encode($this->state)
]);

View file

@ -23,7 +23,7 @@ class Twitch extends OAuth
/**
* @var array
*/
protected $scope = [
protected $scopes = [
'user:read:email',
];
@ -49,7 +49,7 @@ class Twitch extends OAuth
http_build_query([
'response_type' => 'code',
'client_id' => $this->appID,
'scope' => implode(' ', $this->scope),
'scope' => implode(' ', $this->getScopes()),
'redirect_uri' => $this->callback,
'force_verify' => true,
'state' => json_encode($this->state)

View file

@ -20,7 +20,10 @@ class Vk extends OAuth
/**
* @var array
*/
protected $scopes = ['openid' ,'email'];
protected $scopes = [
'openid',
'email'
];
/**
* @var string
@ -144,10 +147,11 @@ class Vk extends OAuth
if (empty($this->user['name'])) {
$user = $this->request(
'GET',
'https://api.vk.com/method/users.get?'.
'v='.urlencode($this->version).
'&fields=id,name,email,first_name,last_name'.
'&access_token='.urlencode($accessToken)
'https://api.vk.com/method/users.get?'. http_build_query([
'v' => $this->version,
'fields' => 'id,name,email,first_name,last_name',
'access_token' => $accessToken
])
);
$user = json_decode($user, true);

View file

@ -23,7 +23,7 @@ class Yahoo extends OAuth
/**
* @var array
*/
protected $scope = [
protected $scopes = [
'sdct-r',
'sdpp-w',
];
@ -61,7 +61,7 @@ class Yahoo extends OAuth
http_build_query([
'response_type' => 'code',
'client_id' => $this->appID,
'scope' => implode(' ', $this->scope),
'scope' => implode(' ', $this->getScopes()),
'redirect_uri' => $this->callback,
'state' => json_encode($this->state)
]);