1
0
Fork 0
mirror of synced 2024-09-30 09:18:14 +13: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 * @var array
*/ */
protected $scopes = ["name", "email"]; protected $scopes = [
"name",
"email"
];
/** /**
* @return string * @return string

View file

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

View file

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

View file

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

View file

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

View file

@ -18,7 +18,10 @@ class Google extends OAuth
/** /**
* @var array * @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 * @var array

View file

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

View file

@ -11,6 +11,13 @@ class Mock extends OAuth
*/ */
protected $version = 'v1'; protected $version = 'v1';
/**
* @var array
*/
protected $scopes = [
'email'
];
/** /**
* @var array * @var array
*/ */
@ -29,7 +36,12 @@ class Mock extends OAuth
*/ */
public function getLoginURL():string 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( $accessToken = $this->request(
'GET', 'GET',
'http://localhost/'.$this->version.'/oauth/token?'. 'http://localhost/'.$this->version.'/oauth/token?'.
'client_id='.urlencode($this->appID). http_build_query([
'&redirect_uri='.urlencode($this->callback). 'client_id' => $this->appID,
'&client_secret='.urlencode($this->appSecret). 'redirect_uri' => $this->callback,
'&code='.urlencode($code) 'client_secret' => $this->appSecret,
'code' => $code
])
); );
$accessToken = json_decode($accessToken, true); // $accessToken = json_decode($accessToken, true); //

View file

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

View file

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

View file

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

View file

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

View file

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