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

fix: improve typing and nullish values

This commit is contained in:
Torsten Dittmann 2022-05-12 17:56:20 +02:00
parent 726b71ae3b
commit 05c37c8a28
32 changed files with 712 additions and 1006 deletions

View file

@ -7,27 +7,27 @@ abstract class OAuth2
/**
* @var string
*/
protected $appID;
protected string $appID;
/**
* @var string
*/
protected $appSecret;
protected string $appSecret;
/**
* @var string
*/
protected $callback;
protected string $callback;
/**
* @var array
*/
protected $state;
protected array $state;
/**
* @var array
*/
protected $scopes;
protected array $scopes;
/**
* OAuth2 constructor.
@ -74,7 +74,7 @@ abstract class OAuth2
abstract public function refreshTokens(string $refreshToken): array;
/**
* @param $accessToken
* @param string $accessToken
*
* @return string
*/
@ -83,14 +83,14 @@ abstract class OAuth2
/**
* Check if the OAuth email is verified
*
* @param $accessToken
* @param string $accessToken
*
* @return bool
*/
abstract public function isEmailVerified(string $accessToken): bool;
/**
* @param $accessToken
* @param string $accessToken
*
* @return string
*/
@ -107,6 +107,7 @@ abstract class OAuth2
if (!\in_array($scope, $this->scopes)) {
$this->scopes[] = $scope;
}
return $this;
}
@ -126,6 +127,7 @@ abstract class OAuth2
public function getAccessToken(string $code): string
{
$tokens = $this->getTokens($code);
return $tokens['access_token'] ?? '';
}
@ -137,6 +139,7 @@ abstract class OAuth2
public function getRefreshToken(string $code): string
{
$tokens = $this->getTokens($code);
return $tokens['refresh_token'] ?? '';
}
@ -148,6 +151,7 @@ abstract class OAuth2
public function getAccessTokenExpiry(string $code): string
{
$tokens = $this->getTokens($code);
return $tokens['expires_in'] ?? '';
}

View file

@ -14,17 +14,17 @@ class Amazon extends OAuth2
/**
* @var array
*/
protected $user = [];
/**
* @var array
*/
protected $tokens = [];
protected array $user = [];
/**
* @var array
*/
protected $scopes = [
protected array $tokens = [];
/**
* @var array
*/
protected array $scopes = [
"profile"
];
@ -37,7 +37,7 @@ class Amazon extends OAuth2
}
/**
* @param $state
* @param string $state
*
* @return array
*/
@ -52,13 +52,13 @@ class Amazon extends OAuth2
*/
public function getLoginURL(): string
{
return 'https://www.amazon.com/ap/oa?'.\http_build_query([
'response_type' => 'code',
'client_id' => $this->appID,
'scope' => \implode(' ', $this->getScopes()),
'state' => \json_encode($this->state),
'redirect_uri' => $this->callback
]);
return 'https://www.amazon.com/ap/oa?' . \http_build_query([
'response_type' => 'code',
'client_id' => $this->appID,
'scope' => \implode(' ', $this->getScopes()),
'state' => \json_encode($this->state),
'redirect_uri' => $this->callback
]);
}
/**
@ -68,7 +68,7 @@ class Amazon extends OAuth2
*/
protected function getTokens(string $code): array
{
if(empty($this->tokens)) {
if (empty($this->tokens)) {
$headers = ['Content-Type: application/x-www-form-urlencoded;charset=UTF-8'];
$this->tokens = \json_decode($this->request(
'POST',
@ -92,7 +92,7 @@ class Amazon extends OAuth2
*
* @return array
*/
public function refreshTokens(string $refreshToken):array
public function refreshTokens(string $refreshToken): array
{
$headers = ['Content-Type: application/x-www-form-urlencoded;charset=UTF-8'];
$this->tokens = \json_decode($this->request(
@ -107,7 +107,7 @@ class Amazon extends OAuth2
])
), true);
if(empty($this->tokens['refresh_token'])) {
if (empty($this->tokens['refresh_token'])) {
$this->tokens['refresh_token'] = $refreshToken;
}
@ -123,11 +123,7 @@ class Amazon extends OAuth2
{
$user = $this->getUser($accessToken);
if (isset($user['user_id'])) {
return $user['user_id'];
}
return '';
return $user['user_id'] ?? '';
}
/**
@ -139,11 +135,7 @@ class Amazon extends OAuth2
{
$user = $this->getUser($accessToken);
if (isset($user['email'])) {
return $user['email'];
}
return '';
return $user['email'] ?? '';
}
/**
@ -151,7 +143,7 @@ class Amazon extends OAuth2
*
* If present, the email is verified. This was verfied through a manual Amazon sign up process
*
* @param $accessToken
* @param string $accessToken
*
* @return bool
*/
@ -171,11 +163,7 @@ class Amazon extends OAuth2
{
$user = $this->getUser($accessToken);
if (isset($user['name'])) {
return $user['name'];
}
return '';
return $user['name'] ?? '';
}
/**
@ -186,7 +174,7 @@ class Amazon extends OAuth2
protected function getUser(string $accessToken): array
{
if (empty($this->user)) {
$user = $this->request('GET', 'https://api.amazon.com/user/profile?access_token='.\urlencode($accessToken));
$user = $this->request('GET', 'https://api.amazon.com/user/profile?access_token=' . \urlencode($accessToken));
$this->user = \json_decode($user, true);
}
return $this->user;

View file

@ -13,17 +13,17 @@ class Apple extends OAuth2
/**
* @var array
*/
protected $user = [];
/**
* @var array
*/
protected $tokens = [];
protected array $user = [];
/**
* @var array
*/
protected $scopes = [
protected array $tokens = [];
/**
* @var array
*/
protected array $scopes = [
"name",
"email"
];
@ -31,7 +31,7 @@ class Apple extends OAuth2
/**
* @var array
*/
protected $claims = [];
protected array $claims = [];
/**
* @return string
@ -40,13 +40,13 @@ class Apple extends OAuth2
{
return 'apple';
}
/**
* @return string
*/
public function getLoginURL(): string
{
return 'https://appleid.apple.com/auth/authorize?'.\http_build_query([
return 'https://appleid.apple.com/auth/authorize?' . \http_build_query([
'client_id' => $this->appID,
'redirect_uri' => $this->callback,
'state' => \json_encode($this->state),
@ -63,7 +63,7 @@ class Apple extends OAuth2
*/
protected function getTokens(string $code): array
{
if(empty($this->tokens)) {
if (empty($this->tokens)) {
$headers = ['Content-Type: application/x-www-form-urlencoded'];
$this->tokens = \json_decode($this->request(
'POST',
@ -90,7 +90,7 @@ class Apple extends OAuth2
*
* @return array
*/
public function refreshTokens(string $refreshToken):array
public function refreshTokens(string $refreshToken): array
{
$headers = ['Content-Type: application/x-www-form-urlencoded'];
$this->tokens = \json_decode($this->request(
@ -105,7 +105,7 @@ class Apple extends OAuth2
])
), true);
if(empty($this->tokens['refresh_token'])) {
if (empty($this->tokens['refresh_token'])) {
$this->tokens['refresh_token'] = $refreshToken;
}
@ -122,11 +122,7 @@ class Apple extends OAuth2
*/
public function getUserID(string $accessToken): string
{
if (isset($this->claims['sub']) && !empty($this->claims['sub'])) {
return $this->claims['sub'];
}
return '';
return $this->claims['sub'] ?? '';
}
/**
@ -136,11 +132,7 @@ class Apple extends OAuth2
*/
public function getUserEmail(string $accessToken): string
{
if (isset($this->claims['email']) && !empty($this->claims['email'])) {
return $this->claims['email'];
}
return '';
return $this->claims['email'] ?? '';
}
/**
@ -148,13 +140,13 @@ class Apple extends OAuth2
*
* @link https://developer.apple.com/forums/thread/121411
*
* @param $accessToken
* @param string $accessToken
*
* @return bool
*/
public function isEmailVerified(string $accessToken): bool
{
if (isset($this->claims['email_verified']) && $this->claims['email_verified'] === 'true') {
if ($this->claims['email_verified'] ?? false) {
return true;
}
@ -168,17 +160,19 @@ class Apple extends OAuth2
*/
public function getUserName(string $accessToken): string
{
if (isset($this->claims['email']) &&
if (
isset($this->claims['email']) &&
!empty($this->claims['email']) &&
isset($this->claims['email_verified']) &&
$this->claims['email_verified'] === 'true') {
$this->claims['email_verified'] === 'true'
) {
return $this->claims['email'];
}
return '';
}
protected function getAppSecret():string
protected function getAppSecret(): string
{
try {
$secret = \json_decode($this->appSecret, true);
@ -195,18 +189,18 @@ class Apple extends OAuth2
'alg' => 'ES256',
'kid' => $keyID,
];
$claims = [
'iss' => $teamID,
'iat' => \time(),
'exp' => \time() + 86400*180,
'exp' => \time() + 86400 * 180,
'aud' => 'https://appleid.apple.com',
'sub' => $bundleID,
];
$pkey = \openssl_pkey_get_private($keyfile);
$payload = $this->encode(\json_encode($headers)).'.'.$this->encode(\json_encode($claims));
$payload = $this->encode(\json_encode($headers)) . '.' . $this->encode(\json_encode($claims));
$signature = '';
@ -216,7 +210,7 @@ class Apple extends OAuth2
return '';
}
return $payload.'.'.$this->encode($this->fromDER($signature, 64));
return $payload . '.' . $this->encode($this->fromDER($signature, 64));
}
/**
@ -245,10 +239,10 @@ class Apple extends OAuth2
* @param string $der
* @param int $partLength
*/
protected function fromDER(string $der, int $partLength):string
protected function fromDER(string $der, int $partLength): string
{
$hex = \unpack('H*', $der)[1];
if ('30' !== \mb_substr($hex, 0, 2, '8bit')) { // SEQUENCE
throw new \RuntimeException();
}
@ -267,7 +261,7 @@ class Apple extends OAuth2
$R = \str_pad($R, $partLength, '0', STR_PAD_LEFT);
$hex = \mb_substr($hex, 4 + $Rl * 2, null, '8bit');
if ('02' !== \mb_substr($hex, 0, 2, '8bit')) { // INTEGER
throw new \RuntimeException();
}
@ -276,6 +270,6 @@ class Apple extends OAuth2
$S = $this->retrievePositiveInteger(\mb_substr($hex, 4, $Sl * 2, '8bit'));
$S = \str_pad($S, $partLength, '0', STR_PAD_LEFT);
return \pack('H*', $R.$S);
return \pack('H*', $R . $S);
}
}

View file

@ -8,27 +8,27 @@ use Appwrite\Auth\OAuth2;
// https://auth0.com/docs/api/authentication
class Auth0 extends OAuth2
{
/**
{
/**
* @var array
*/
protected $scopes = [
protected array $scopes = [
'openid',
'profile',
'email',
'offline_access'
];
/**
* @var array
*/
protected $user = [];
protected array $user = [];
/**
* @var array
*/
protected $tokens = [];
protected array $tokens = [];
/**
* @return string
*/
@ -42,11 +42,11 @@ class Auth0 extends OAuth2
*/
public function getLoginURL(): string
{
return 'https://'.$this->getAuth0Domain().'/authorize?'.\http_build_query([
return 'https://' . $this->getAuth0Domain() . '/authorize?' . \http_build_query([
'client_id' => $this->appID,
'redirect_uri' => $this->callback,
'state'=> \json_encode($this->state),
'scope'=> \implode(' ', $this->getScopes()),
'state' => \json_encode($this->state),
'scope' => \implode(' ', $this->getScopes()),
'response_type' => 'code'
]);
}
@ -58,11 +58,11 @@ class Auth0 extends OAuth2
*/
protected function getTokens(string $code): array
{
if(empty($this->tokens)) {
if (empty($this->tokens)) {
$headers = ['Content-Type: application/x-www-form-urlencoded'];
$this->tokens = \json_decode($this->request(
'POST',
'https://'.$this->getAuth0Domain().'/oauth/token',
'https://' . $this->getAuth0Domain() . '/oauth/token',
$headers,
\http_build_query([
'code' => $code,
@ -77,8 +77,8 @@ class Auth0 extends OAuth2
return $this->tokens;
}
/**
* @param string $refreshToken
*
@ -89,7 +89,7 @@ class Auth0 extends OAuth2
$headers = ['Content-Type: application/x-www-form-urlencoded'];
$this->tokens = \json_decode($this->request(
'POST',
'https://'.$this->getAuth0Domain().'/oauth/token',
'https://' . $this->getAuth0Domain() . '/oauth/token',
$headers,
\http_build_query([
'refresh_token' => $refreshToken,
@ -99,7 +99,7 @@ class Auth0 extends OAuth2
])
), true);
if(empty($this->tokens['refresh_token'])) {
if (empty($this->tokens['refresh_token'])) {
$this->tokens['refresh_token'] = $refreshToken;
}
@ -114,12 +114,8 @@ class Auth0 extends OAuth2
public function getUserID(string $accessToken): string
{
$user = $this->getUser($accessToken);
if (isset($user['sub'])) {
return $user['sub'];
}
return '';
return $user['sub'] ?? '';
}
/**
@ -130,12 +126,8 @@ class Auth0 extends OAuth2
public function getUserEmail(string $accessToken): string
{
$user = $this->getUser($accessToken);
if (isset($user['email'])) {
return $user['email'];
}
return '';
return $user['email'] ?? '';
}
/**
@ -143,7 +135,7 @@ class Auth0 extends OAuth2
*
* @link https://auth0.com/docs/api/authentication?javascript#user-profile
*
* @param $accessToken
* @param string $accessToken
*
* @return bool
*/
@ -151,7 +143,7 @@ class Auth0 extends OAuth2
{
$user = $this->getUser($accessToken);
if (isset($user['email_verified']) && $user['email_verified'] === true) {
if ($user['email_verified'] ?? false) {
return true;
}
@ -166,15 +158,11 @@ class Auth0 extends OAuth2
public function getUserName(string $accessToken): string
{
$user = $this->getUser($accessToken);
if (isset($user['name'])) {
return $user['name'];
}
return '';
return $user['name'] ?? '';
}
/**
/**
* @param string $accessToken
*
* @return array
@ -182,8 +170,8 @@ class Auth0 extends OAuth2
protected function getUser(string $accessToken): array
{
if (empty($this->user)) {
$headers = ['Authorization: Bearer '. \urlencode($accessToken)];
$user = $this->request('GET', 'https://'.$this->getAuth0Domain().'/userinfo', $headers);
$headers = ['Authorization: Bearer ' . \urlencode($accessToken)];
$user = $this->request('GET', 'https://' . $this->getAuth0Domain() . '/userinfo', $headers);
$this->user = \json_decode($user, true);
}
@ -199,10 +187,10 @@ class Auth0 extends OAuth2
{
$secret = $this->getAppSecret();
return (isset($secret['clientSecret'])) ? $secret['clientSecret'] : '';
return $secret['clientSecret'] ?? '';
}
/**
/**
* Extracts the Auth0 Domain from the JSON stored in appSecret
*
* @return string
@ -210,7 +198,8 @@ class Auth0 extends OAuth2
protected function getAuth0Domain(): string
{
$secret = $this->getAppSecret();
return (isset($secret['auth0Domain'])) ? $secret['auth0Domain'] : '';
return $secret['auth0Domain'] ?? '';
}
/**
@ -219,7 +208,7 @@ class Auth0 extends OAuth2
* @return array
*/
protected function getAppSecret(): array
{
{
try {
$secret = \json_decode($this->appSecret, true, 512, JSON_THROW_ON_ERROR);
} catch (\Throwable $th) {
@ -227,4 +216,4 @@ class Auth0 extends OAuth2
}
return $secret;
}
}
}

View file

@ -12,17 +12,17 @@ class Bitbucket extends OAuth2
/**
* @var array
*/
protected $user = [];
/**
* @var array
*/
protected $tokens = [];
protected array $user = [];
/**
* @var array
*/
protected $scopes = [];
protected array $tokens = [];
/**
* @var array
*/
protected array $scopes = [];
/**
* @return string
@ -37,12 +37,12 @@ class Bitbucket extends OAuth2
*/
public function getLoginURL(): string
{
return 'https://bitbucket.org/site/oauth2/authorize?'.\http_build_query([
'response_type' => 'code',
'client_id' => $this->appID,
'scope' => \implode(' ', $this->getScopes()),
'state' => \json_encode($this->state),
]);
return 'https://bitbucket.org/site/oauth2/authorize?' . \http_build_query([
'response_type' => 'code',
'client_id' => $this->appID,
'scope' => \implode(' ', $this->getScopes()),
'state' => \json_encode($this->state),
]);
}
/**
@ -52,7 +52,7 @@ class Bitbucket extends OAuth2
*/
protected function getTokens(string $code): array
{
if(empty($this->tokens)) {
if (empty($this->tokens)) {
// Required as per Bitbucket Spec.
$headers = ['Content-Type: application/x-www-form-urlencoded'];
$this->tokens = \json_decode($this->request(
@ -76,7 +76,7 @@ class Bitbucket extends OAuth2
*
* @return array
*/
public function refreshTokens(string $refreshToken):array
public function refreshTokens(string $refreshToken): array
{
$headers = ['Content-Type: application/x-www-form-urlencoded'];
$this->tokens = \json_decode($this->request(
@ -91,7 +91,7 @@ class Bitbucket extends OAuth2
])
), true);
if(empty($this->tokens['refresh_token'])) {
if (empty($this->tokens['refresh_token'])) {
$this->tokens['refresh_token'] = $refreshToken;
}
@ -107,11 +107,7 @@ class Bitbucket extends OAuth2
{
$user = $this->getUser($accessToken);
if (isset($user['uuid'])) {
return $user['uuid'];
}
return '';
return $user['uuid'] ?? '';
}
/**
@ -123,17 +119,13 @@ class Bitbucket extends OAuth2
{
$user = $this->getUser($accessToken);
if (isset($user['email'])) {
return $user['email'];
}
return '';
return $user['email'] ?? '';
}
/**
* Check if the OAuth email is verified
*
* @param $accessToken
* @param string $accessToken
*
* @return bool
*/
@ -141,7 +133,7 @@ class Bitbucket extends OAuth2
{
$user = $this->getUser($accessToken);
if (isset($user['is_confirmed']) && $user['is_confirmed'] === true) {
if ($user['is_confirmed'] ?? false) {
return true;
}
@ -157,11 +149,7 @@ class Bitbucket extends OAuth2
{
$user = $this->getUser($accessToken);
if (isset($user['display_name'])) {
return $user['display_name'];
}
return '';
return $user['display_name'] ?? '';
}
/**
@ -172,10 +160,10 @@ class Bitbucket extends OAuth2
protected function getUser(string $accessToken): array
{
if (empty($this->user)) {
$user = $this->request('GET', 'https://api.bitbucket.org/2.0/user?access_token='.\urlencode($accessToken));
$user = $this->request('GET', 'https://api.bitbucket.org/2.0/user?access_token=' . \urlencode($accessToken));
$this->user = \json_decode($user, true);
$emails = $this->request('GET', 'https://api.bitbucket.org/2.0/user/emails?access_token='.\urlencode($accessToken));
$emails = $this->request('GET', 'https://api.bitbucket.org/2.0/user/emails?access_token=' . \urlencode($accessToken));
$emails = \json_decode($emails, true);
if (isset($emails['values'])) {
foreach ($emails['values'] as $email) {
@ -186,7 +174,6 @@ class Bitbucket extends OAuth2
}
}
}
}
return $this->user;
}

View file

@ -3,7 +3,6 @@
namespace Appwrite\Auth\OAuth2;
use Appwrite\Auth\OAuth2;
use Utopia\Exception;
// Reference Material
// https://dev.bitly.com/v4_documentation.html
@ -14,32 +13,32 @@ class Bitly extends OAuth2
/**
* @var string
*/
private $endpoint = 'https://bitly.com/oauth/';
private string $endpoint = 'https://bitly.com/oauth/';
/**
* @var string
*/
private $resourceEndpoint = 'https://api-ssl.bitly.com/';
private string $resourceEndpoint = 'https://api-ssl.bitly.com/';
/**
* @var array
*/
protected $scopes = [];
protected array $scopes = [];
/**
* @var array
*/
protected $user = [];
protected array $user = [];
/**
* @var array
*/
protected $tokens = [];
protected array $tokens = [];
/**
* @return string
*/
public function getName():string
public function getName(): string
{
return 'bitly';
}
@ -47,9 +46,9 @@ class Bitly extends OAuth2
/**
* @return string
*/
public function getLoginURL():string
public function getLoginURL(): string
{
return $this->endpoint . 'authorize?'.
return $this->endpoint . 'authorize?' .
\http_build_query([
'client_id' => $this->appID,
'redirect_uri' => $this->callback,
@ -64,7 +63,7 @@ class Bitly extends OAuth2
*/
protected function getTokens(string $code): array
{
if(empty($this->tokens)) {
if (empty($this->tokens)) {
$response = $this->request(
'POST',
$this->resourceEndpoint . 'oauth/access_token',
@ -91,7 +90,7 @@ class Bitly extends OAuth2
*
* @return array
*/
public function refreshTokens(string $refreshToken):array
public function refreshTokens(string $refreshToken): array
{
$response = $this->request(
'POST',
@ -109,7 +108,7 @@ class Bitly extends OAuth2
\parse_str($response, $output);
$this->tokens = $output;
if(empty($this->tokens['refresh_token'])) {
if (empty($this->tokens['refresh_token'])) {
$this->tokens['refresh_token'] = $refreshToken;
}
@ -117,27 +116,23 @@ class Bitly extends OAuth2
}
/**
* @param $accessToken
* @param string $accessToken
*
* @return string
*/
public function getUserID(string $accessToken):string
public function getUserID(string $accessToken): string
{
$user = $this->getUser($accessToken);
if (isset($user['login'])) {
return $user['login'];
}
return '';
return $user['login'] ?? '';
}
/**
* @param $accessToken
* @param string $accessToken
*
* @return string
*/
public function getUserEmail(string $accessToken):string
public function getUserEmail(string $accessToken): string
{
$user = $this->getUser($accessToken);
@ -157,7 +152,7 @@ class Bitly extends OAuth2
*
* @link https://dev.bitly.com/api-reference#getUser
*
* @param $accessToken
* @param string $accessToken
*
* @return bool
*/
@ -167,19 +162,15 @@ class Bitly extends OAuth2
}
/**
* @param $accessToken
* @param string $accessToken
*
* @return string
*/
public function getUserName(string $accessToken):string
public function getUserName(string $accessToken): string
{
$user = $this->getUser($accessToken);
if (isset($user['name'])) {
return $user['name'];
}
return '';
return $user['name'] ?? '';
}
/**
@ -190,7 +181,7 @@ class Bitly extends OAuth2
protected function getUser(string $accessToken)
{
$headers = [
'Authorization: Bearer '. \urlencode($accessToken),
'Authorization: Bearer ' . \urlencode($accessToken),
"Accept: application/json"
];
@ -198,7 +189,6 @@ class Bitly extends OAuth2
$this->user = \json_decode($this->request('GET', $this->resourceEndpoint . "v4/user", $headers), true);
}
return $this->user;
}
}

View file

@ -12,27 +12,27 @@ class Box extends OAuth2
/**
* @var string
*/
private $endpoint = 'https://account.box.com/api/oauth2/';
private string $endpoint = 'https://account.box.com/api/oauth2/';
/**
* @var string
*/
private $resourceEndpoint = 'https://api.box.com/2.0/';
private string $resourceEndpoint = 'https://api.box.com/2.0/';
/**
* @var array
*/
protected $user = [];
/**
* @var array
*/
protected $tokens = [];
protected array $user = [];
/**
* @var array
*/
protected $scopes = [
protected array $tokens = [];
/**
* @var array
*/
protected array $scopes = [
'manage_app_users',
];
@ -49,7 +49,7 @@ class Box extends OAuth2
*/
public function getLoginURL(): string
{
$url = $this->endpoint . 'authorize?'.
$url = $this->endpoint . 'authorize?' .
\http_build_query([
'response_type' => 'code',
'client_id' => $this->appID,
@ -68,7 +68,7 @@ class Box extends OAuth2
*/
protected function getTokens(string $code): array
{
if(empty($this->tokens)) {
if (empty($this->tokens)) {
$headers = ['Content-Type: application/x-www-form-urlencoded'];
$this->tokens = \json_decode($this->request(
'POST',
@ -93,7 +93,7 @@ class Box extends OAuth2
*
* @return array
*/
public function refreshTokens(string $refreshToken):array
public function refreshTokens(string $refreshToken): array
{
$headers = ['Content-Type: application/x-www-form-urlencoded'];
$this->tokens = \json_decode($this->request(
@ -108,7 +108,7 @@ class Box extends OAuth2
])
), true);
if(empty($this->tokens['refresh_token'])) {
if (empty($this->tokens['refresh_token'])) {
$this->tokens['refresh_token'] = $refreshToken;
}
@ -124,11 +124,7 @@ class Box extends OAuth2
{
$user = $this->getUser($accessToken);
if (isset($user['id'])) {
return $user['id'];
}
return '';
return $user['id'] ?? '';
}
/**
@ -140,11 +136,7 @@ class Box extends OAuth2
{
$user = $this->getUser($accessToken);
if (isset($user['login'])) {
return $user['login'];
}
return '';
return $user['login'] ?? '';
}
/**
@ -152,7 +144,7 @@ class Box extends OAuth2
*
* If present, the email is verified. This was verfied through a manual Box sign up process
*
* @param $accessToken
* @param string $accessToken
*
* @return bool
*/
@ -162,7 +154,7 @@ class Box extends OAuth2
return !empty($email);
}
/**
* @param string $accessToken
*
@ -172,11 +164,7 @@ class Box extends OAuth2
{
$user = $this->getUser($accessToken);
if (isset($user['name'])) {
return $user['name'];
}
return '';
return $user['name'] ?? '';
}
/**
@ -187,7 +175,7 @@ class Box extends OAuth2
protected function getUser(string $accessToken): array
{
$header = [
'Authorization: Bearer '.\urlencode($accessToken),
'Authorization: Bearer ' . \urlencode($accessToken),
];
if (empty($this->user)) {
$user = $this->request(

View file

@ -12,22 +12,22 @@ class Discord extends OAuth2
/**
* @var string
*/
private $endpoint = 'https://discordapp.com/api';
private string $endpoint = 'https://discordapp.com/api';
/**
* @var array
*/
protected $user = [];
protected array $user = [];
/**
* @var array
*/
protected $tokens = [];
protected array $tokens = [];
/**
* @var array
*/
protected $scopes = [
protected array $scopes = [
'identify',
'email'
];
@ -118,11 +118,7 @@ class Discord extends OAuth2
{
$user = $this->getUser($accessToken);
if (isset($user['id'])) {
return $user['id'];
}
return '';
return $user['id'] ?? '';
}
/**
@ -134,11 +130,7 @@ class Discord extends OAuth2
{
$user = $this->getUser($accessToken);
if (isset($user['email'])) {
return $user['email'];
}
return '';
return $user['email'] ?? '';
}
/**
@ -146,7 +138,7 @@ class Discord extends OAuth2
*
* @link https://discord.com/developers/docs/resources/user
*
* @param $accessToken
* @param string $accessToken
*
* @return bool
*/
@ -154,7 +146,7 @@ class Discord extends OAuth2
{
$user = $this->getUser($accessToken);
if (isset($user['verified']) && $user['verified'] === true) {
if ($user['verified'] ?? false) {
return true;
}
@ -170,11 +162,7 @@ class Discord extends OAuth2
{
$user = $this->getUser($accessToken);
if (isset($user['username'])) {
return $user['username'];
}
return '';
return $user['username'] ?? '';
}
/**

View file

@ -13,17 +13,17 @@ class Dropbox extends OAuth2
/**
* @var array
*/
protected $user = [];
/**
* @var array
*/
protected $tokens = [];
protected array $user = [];
/**
* @var array
*/
protected $scopes = [];
protected array $tokens = [];
/**
* @var array
*/
protected array $scopes = [];
/**
* @return string
@ -32,17 +32,17 @@ class Dropbox extends OAuth2
{
return 'dropbox';
}
/**
* @return string
*/
public function getLoginURL(): string
{
return 'https://www.dropbox.com/oauth2/authorize?'.\http_build_query([
'client_id' => $this->appID,
'redirect_uri' => $this->callback,
'state' => \json_encode($this->state),
'response_type' => 'code'
return 'https://www.dropbox.com/oauth2/authorize?' . \http_build_query([
'client_id' => $this->appID,
'redirect_uri' => $this->callback,
'state' => \json_encode($this->state),
'response_type' => 'code'
]);
}
@ -53,7 +53,7 @@ class Dropbox extends OAuth2
*/
protected function getTokens(string $code): array
{
if(empty($this->tokens)) {
if (empty($this->tokens)) {
$headers = ['Content-Type: application/x-www-form-urlencoded'];
$this->tokens = \json_decode($this->request(
'POST',
@ -77,7 +77,7 @@ class Dropbox extends OAuth2
*
* @return array
*/
public function refreshTokens(string $refreshToken):array
public function refreshTokens(string $refreshToken): array
{
$headers = ['Content-Type: application/x-www-form-urlencoded'];
$this->tokens = \json_decode($this->request(
@ -92,7 +92,7 @@ class Dropbox extends OAuth2
])
), true);
if(empty($this->tokens['refresh_token'])) {
if (empty($this->tokens['refresh_token'])) {
$this->tokens['refresh_token'] = $refreshToken;
}
@ -108,11 +108,7 @@ class Dropbox extends OAuth2
{
$user = $this->getUser($accessToken);
if (isset($user['account_id'])) {
return $user['account_id'];
}
return '';
return $user['account_id'] ?? '';
}
/**
@ -124,11 +120,7 @@ class Dropbox extends OAuth2
{
$user = $this->getUser($accessToken);
if (isset($user['email'])) {
return $user['email'];
}
return '';
return $user['email'] ?? '';
}
/**
@ -136,7 +128,7 @@ class Dropbox extends OAuth2
*
* @link https://www.dropbox.com/developers/documentation/http/documentation#users-get_current_account
*
* @param $accessToken
* @param string $accessToken
*
* @return bool
*/
@ -144,7 +136,7 @@ class Dropbox extends OAuth2
{
$user = $this->getUser($accessToken);
if (isset($user['email_verified']) && $user['email_verified'] === true) {
if ($user['email_verified'] ?? false) {
return true;
}
@ -160,11 +152,7 @@ class Dropbox extends OAuth2
{
$user = $this->getUser($accessToken);
if (isset($user['name'])) {
return $user['name']['display_name'];
}
return '';
return $user['name']['display_name'] ?? '';
}
/**
@ -175,7 +163,7 @@ class Dropbox extends OAuth2
protected function getUser(string $accessToken): array
{
if (empty($this->user)) {
$headers = ['Authorization: Bearer '. \urlencode($accessToken)];
$headers = ['Authorization: Bearer ' . \urlencode($accessToken)];
$user = $this->request('POST', 'https://api.dropboxapi.com/2/users/get_current_account', $headers);
$this->user = \json_decode($user, true);
}

View file

@ -3,36 +3,35 @@
namespace Appwrite\Auth\OAuth2;
use Appwrite\Auth\OAuth2;
use Utopia\Exception;
class Facebook extends OAuth2
{
/**
* @var string
*/
protected $version = 'v2.8';
protected string $version = 'v2.8';
/**
* @var array
*/
protected $user = [];
/**
* @var array
*/
protected $tokens = [];
protected array $user = [];
/**
* @var array
*/
protected $scopes = [
protected array $tokens = [];
/**
* @var array
*/
protected array $scopes = [
'email'
];
/**
* @return string
*/
public function getName():string
public function getName(): string
{
return 'facebook';
}
@ -40,10 +39,10 @@ class Facebook extends OAuth2
/**
* @return string
*/
public function getLoginURL():string
public function getLoginURL(): string
{
return 'https://www.facebook.com/'.$this->version.'/dialog/oauth?'.\http_build_query([
'client_id'=> $this->appID,
return 'https://www.facebook.com/' . $this->version . '/dialog/oauth?' . \http_build_query([
'client_id' => $this->appID,
'redirect_uri' => $this->callback,
'scope' => \implode(' ', $this->getScopes()),
'state' => \json_encode($this->state)
@ -57,7 +56,7 @@ class Facebook extends OAuth2
*/
protected function getTokens(string $code): array
{
if(empty($this->tokens)) {
if (empty($this->tokens)) {
$this->tokens = \json_decode($this->request(
'GET',
'https://graph.facebook.com/' . $this->version . '/oauth/access_token?' . \http_build_query([
@ -77,7 +76,7 @@ class Facebook extends OAuth2
*
* @return array
*/
public function refreshTokens(string $refreshToken):array
public function refreshTokens(string $refreshToken): array
{
$this->tokens = \json_decode($this->request(
'GET',
@ -90,7 +89,7 @@ class Facebook extends OAuth2
])
), true);
if(empty($this->tokens['refresh_token'])) {
if (empty($this->tokens['refresh_token'])) {
$this->tokens['refresh_token'] = $refreshToken;
}
@ -102,15 +101,11 @@ class Facebook extends OAuth2
*
* @return string
*/
public function getUserID(string $accessToken):string
public function getUserID(string $accessToken): string
{
$user = $this->getUser($accessToken);
if (isset($user['id'])) {
return $user['id'];
}
return '';
return $user['id'] ?? '';
}
/**
@ -118,15 +113,11 @@ class Facebook extends OAuth2
*
* @return string
*/
public function getUserEmail(string $accessToken):string
public function getUserEmail(string $accessToken): string
{
$user = $this->getUser($accessToken);
if (isset($user['email'])) {
return $user['email'];
}
return '';
return $user['email'] ?? '';
}
/**
@ -134,7 +125,7 @@ class Facebook extends OAuth2
*
* If present, the email is verified. This was verfied through a manual Facebook sign up process
*
* @param $accessToken
* @param string $accessToken
*
* @return bool
*/
@ -150,15 +141,11 @@ class Facebook extends OAuth2
*
* @return string
*/
public function getUserName(string $accessToken):string
public function getUserName(string $accessToken): string
{
$user = $this->getUser($accessToken);
if (isset($user['name'])) {
return $user['name'];
}
return '';
return $user['name'] ?? '';
}
/**
@ -166,10 +153,10 @@ class Facebook extends OAuth2
*
* @return array
*/
protected function getUser(string $accessToken):array
protected function getUser(string $accessToken): array
{
if (empty($this->user)) {
$user = $this->request('GET', 'https://graph.facebook.com/'.$this->version.'/me?fields=email,name&access_token='.\urlencode($accessToken));
$user = $this->request('GET', 'https://graph.facebook.com/' . $this->version . '/me?fields=email,name&access_token=' . \urlencode($accessToken));
$this->user = \json_decode($user, true);
}

View file

@ -3,31 +3,30 @@
namespace Appwrite\Auth\OAuth2;
use Appwrite\Auth\OAuth2;
use Utopia\Exception;
class Github extends OAuth2
{
/**
* @var array
*/
protected $user = [];
/**
* @var array
*/
protected $tokens = [];
protected array $user = [];
/**
* @var array
*/
protected $scopes = [
protected array $tokens = [];
/**
* @var array
*/
protected array $scopes = [
'user:email',
];
/**
* @return string
*/
public function getName():string
public function getName(): string
{
return 'github';
}
@ -35,9 +34,9 @@ class Github extends OAuth2
/**
* @return string
*/
public function getLoginURL():string
public function getLoginURL(): string
{
return 'https://github.com/login/oauth/authorize?'. \http_build_query([
return 'https://github.com/login/oauth/authorize?' . \http_build_query([
'client_id' => $this->appID,
'redirect_uri' => $this->callback,
'scope' => \implode(' ', $this->getScopes()),
@ -52,7 +51,7 @@ class Github extends OAuth2
*/
protected function getTokens(string $code): array
{
if(empty($this->tokens)) {
if (empty($this->tokens)) {
$response = $this->request(
'POST',
'https://github.com/login/oauth/access_token',
@ -78,7 +77,7 @@ class Github extends OAuth2
*
* @return array
*/
public function refreshTokens(string $refreshToken):array
public function refreshTokens(string $refreshToken): array
{
$response = $this->request(
'POST',
@ -96,7 +95,7 @@ class Github extends OAuth2
\parse_str($response, $output);
$this->tokens = $output;
if(empty($this->tokens['refresh_token'])) {
if (empty($this->tokens['refresh_token'])) {
$this->tokens['refresh_token'] = $refreshToken;
}
@ -104,35 +103,27 @@ class Github extends OAuth2
}
/**
* @param $accessToken
* @param string $accessToken
*
* @return string
*/
public function getUserID(string $accessToken):string
public function getUserID(string $accessToken): string
{
$user = $this->getUser($accessToken);
if (isset($user['id'])) {
return $user['id'];
}
return '';
return $user['id'] ?? '';
}
/**
* @param $accessToken
* @param string $accessToken
*
* @return string
*/
public function getUserEmail(string $accessToken):string
public function getUserEmail(string $accessToken): string
{
$user = $this->getUser($accessToken);
if (isset($user['email'])) {
return $user['email'];
}
return '';
return $user['email'] ?? '';
}
/**
@ -140,7 +131,7 @@ class Github extends OAuth2
*
* @link https://docs.github.com/en/rest/users/emails#list-email-addresses-for-the-authenticated-user
*
* @param $accessToken
* @param string $accessToken
*
* @return bool
*/
@ -148,7 +139,7 @@ class Github extends OAuth2
{
$user = $this->getUser($accessToken);
if (isset($user['verified']) && $user['verified'] !== null) {
if ($user['verified'] ?? false) {
return true;
}
@ -156,19 +147,15 @@ class Github extends OAuth2
}
/**
* @param $accessToken
* @param string $accessToken
*
* @return string
*/
public function getUserName(string $accessToken):string
public function getUserName(string $accessToken): string
{
$user = $this->getUser($accessToken);
if (isset($user['name'])) {
return $user['name'];
}
return '';
return $user['name'] ?? '';
}
/**
@ -179,9 +166,9 @@ class Github extends OAuth2
protected function getUser(string $accessToken)
{
if (empty($this->user)) {
$this->user = \json_decode($this->request('GET', 'https://api.github.com/user', ['Authorization: token '.\urlencode($accessToken)]), true);
$emails = $this->request('GET', 'https://api.github.com/user/emails', ['Authorization: token '.\urlencode($accessToken)]);
$this->user = \json_decode($this->request('GET', 'https://api.github.com/user', ['Authorization: token ' . \urlencode($accessToken)]), true);
$emails = $this->request('GET', 'https://api.github.com/user/emails', ['Authorization: token ' . \urlencode($accessToken)]);
$emails = \json_decode($emails, true);
foreach ($emails as $email) {

View file

@ -12,17 +12,17 @@ class Gitlab extends OAuth2
/**
* @var array
*/
protected $user = [];
/**
* @var array
*/
protected $tokens = [];
protected array $user = [];
/**
* @var array
*/
protected $scopes = [
protected array $tokens = [];
/**
* @var array
*/
protected array $scopes = [
'read_user'
];
@ -39,7 +39,7 @@ class Gitlab extends OAuth2
*/
public function getLoginURL(): string
{
return 'https://gitlab.com/oauth/authorize?'.\http_build_query([
return 'https://gitlab.com/oauth/authorize?' . \http_build_query([
'client_id' => $this->appID,
'redirect_uri' => $this->callback,
'scope' => \implode(' ', $this->getScopes()),
@ -55,7 +55,7 @@ class Gitlab extends OAuth2
*/
protected function getTokens(string $code): array
{
if(empty($this->tokens)) {
if (empty($this->tokens)) {
$this->tokens = \json_decode($this->request(
'POST',
'https://gitlab.com/oauth/token?' . \http_build_query([
@ -76,7 +76,7 @@ class Gitlab extends OAuth2
*
* @return array
*/
public function refreshTokens(string $refreshToken):array
public function refreshTokens(string $refreshToken): array
{
$this->tokens = \json_decode($this->request(
'POST',
@ -88,7 +88,7 @@ class Gitlab extends OAuth2
])
), true);
if(empty($this->tokens['refresh_token'])) {
if (empty($this->tokens['refresh_token'])) {
$this->tokens['refresh_token'] = $refreshToken;
}
@ -120,11 +120,7 @@ class Gitlab extends OAuth2
{
$user = $this->getUser($accessToken);
if (isset($user['email'])) {
return $user['email'];
}
return '';
return $user['email'] ?? '';
}
/**
@ -132,7 +128,7 @@ class Gitlab extends OAuth2
*
* @link https://docs.gitlab.com/ee/api/users.html#list-current-user-for-normal-users
*
* @param $accessToken
* @param string $accessToken
*
* @return bool
*/
@ -140,7 +136,7 @@ class Gitlab extends OAuth2
{
$user = $this->getUser($accessToken);
if (isset($user['confirmed_at']) && $user['confirmed_at'] !== null) {
if ($user['confirmed_at'] ?? false) {
return true;
}
@ -156,11 +152,7 @@ class Gitlab extends OAuth2
{
$user = $this->getUser($accessToken);
if (isset($user['name'])) {
return $user['name'];
}
return '';
return $user['name'] ?? '';
}
/**
@ -171,7 +163,7 @@ class Gitlab extends OAuth2
protected function getUser(string $accessToken): array
{
if (empty($this->user)) {
$user = $this->request('GET', 'https://gitlab.com/api/v4/user?access_token='.\urlencode($accessToken));
$user = $this->request('GET', 'https://gitlab.com/api/v4/user?access_token=' . \urlencode($accessToken));
$this->user = \json_decode($user, true);
}

View file

@ -14,12 +14,12 @@ class Google extends OAuth2
/**
* @var string
*/
protected $version = 'v4';
protected string $version = 'v4';
/**
* @var array
*/
protected $scopes = [
protected array $scopes = [
'https://www.googleapis.com/auth/userinfo.email',
'https://www.googleapis.com/auth/userinfo.profile',
'openid'
@ -28,12 +28,12 @@ class Google extends OAuth2
/**
* @var array
*/
protected $user = [];
protected array $user = [];
/**
* @var array
*/
protected $tokens = [];
protected array $tokens = [];
/**
* @return string
@ -48,7 +48,7 @@ class Google extends OAuth2
*/
public function getLoginURL(): string
{
return 'https://accounts.google.com/o/oauth2/v2/auth?'. \http_build_query([
return 'https://accounts.google.com/o/oauth2/v2/auth?' . \http_build_query([
'client_id' => $this->appID,
'redirect_uri' => $this->callback,
'scope' => \implode(' ', $this->getScopes()),
@ -64,7 +64,7 @@ class Google extends OAuth2
*/
protected function getTokens(string $code): array
{
if(empty($this->tokens)) {
if (empty($this->tokens)) {
$this->tokens = \json_decode($this->request(
'POST',
'https://oauth2.googleapis.com/token?' . \http_build_query([
@ -86,7 +86,7 @@ class Google extends OAuth2
*
* @return array
*/
public function refreshTokens(string $refreshToken):array
public function refreshTokens(string $refreshToken): array
{
$this->tokens = \json_decode($this->request(
'POST',
@ -98,7 +98,7 @@ class Google extends OAuth2
])
), true);
if(empty($this->tokens['refresh_token'])) {
if (empty($this->tokens['refresh_token'])) {
$this->tokens['refresh_token'] = $refreshToken;
}
@ -114,11 +114,7 @@ class Google extends OAuth2
{
$user = $this->getUser($accessToken);
if (isset($user['id'])) {
return $user['id'];
}
return '';
return $user['id'] ?? '';
}
/**
@ -130,11 +126,7 @@ class Google extends OAuth2
{
$user = $this->getUser($accessToken);
if (isset($user['email'])) {
return $user['email'];
}
return '';
return $user['email'] ?? '';
}
/**
@ -142,7 +134,7 @@ class Google extends OAuth2
*
* @link https://www.oauth.com/oauth2-servers/signing-in-with-google/verifying-the-user-info/
*
* @param $accessToken
* @param string $accessToken
*
* @return bool
*/
@ -150,7 +142,7 @@ class Google extends OAuth2
{
$user = $this->getUser($accessToken);
if (isset($user['email_verified']) && $user['email_verified'] === true) {
if ($user['email_verified'] ?? false) {
return true;
}
@ -166,11 +158,7 @@ class Google extends OAuth2
{
$user = $this->getUser($accessToken);
if (isset($user['name'])) {
return $user['name'];
}
return '';
return $user['name'] ?? '';
}
/**
@ -181,7 +169,7 @@ class Google extends OAuth2
protected function getUser(string $accessToken): array
{
if (empty($this->user)) {
$user = $this->request('GET', 'https://www.googleapis.com/oauth2/v3/userinfo?access_token='.\urlencode($accessToken));
$user = $this->request('GET', 'https://www.googleapis.com/oauth2/v3/userinfo?access_token=' . \urlencode($accessToken));
$this->user = \json_decode($user, true);
}

View file

@ -9,17 +9,17 @@ class Linkedin extends OAuth2
/**
* @var array
*/
protected $user = [];
/**
* @var array
*/
protected $tokens = [];
protected array $user = [];
/**
* @var array
*/
protected $scopes = [
protected array $tokens = [];
/**
* @var array
*/
protected array $scopes = [
'r_liteprofile',
'r_emailaddress',
];
@ -40,7 +40,7 @@ class Linkedin extends OAuth2
/**
* @return string
*/
public function getName():string
public function getName(): string
{
return 'linkedin';
}
@ -48,15 +48,15 @@ class Linkedin extends OAuth2
/**
* @return string
*/
public function getLoginURL():string
public function getLoginURL(): string
{
return 'https://www.linkedin.com/oauth/v2/authorization?'.\http_build_query([
'response_type' => 'code',
'client_id' => $this->appID,
'redirect_uri' => $this->callback,
'scope' => \implode(' ', $this->getScopes()),
'state' => \json_encode($this->state),
]);
return 'https://www.linkedin.com/oauth/v2/authorization?' . \http_build_query([
'response_type' => 'code',
'client_id' => $this->appID,
'redirect_uri' => $this->callback,
'scope' => \implode(' ', $this->getScopes()),
'state' => \json_encode($this->state),
]);
}
/**
@ -66,7 +66,7 @@ class Linkedin extends OAuth2
*/
protected function getTokens(string $code): array
{
if(empty($this->tokens)) {
if (empty($this->tokens)) {
$this->tokens = \json_decode($this->request(
'POST',
'https://www.linkedin.com/oauth/v2/accessToken',
@ -89,7 +89,7 @@ class Linkedin extends OAuth2
*
* @return array
*/
public function refreshTokens(string $refreshToken):array
public function refreshTokens(string $refreshToken): array
{
$this->tokens = \json_decode($this->request(
'POST',
@ -104,7 +104,7 @@ class Linkedin extends OAuth2
])
), true);
if(empty($this->tokens['refresh_token'])) {
if (empty($this->tokens['refresh_token'])) {
$this->tokens['refresh_token'] = $refreshToken;
}
@ -112,40 +112,27 @@ class Linkedin extends OAuth2
}
/**
* @param $accessToken
* @param string $accessToken
*
* @return string
*/
public function getUserID(string $accessToken):string
public function getUserID(string $accessToken): string
{
$user = $this->getUser($accessToken);
if (isset($user['id'])) {
return $user['id'];
}
return '';
return $user['id'] ?? '';
}
/**
* @param $accessToken
* @param string $accessToken
*
* @return string
*/
public function getUserEmail(string $accessToken):string
public function getUserEmail(string $accessToken): string
{
$email = \json_decode($this->request('GET', 'https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))', ['Authorization: Bearer '.\urlencode($accessToken)]), true);
$email = \json_decode($this->request('GET', 'https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))', ['Authorization: Bearer ' . \urlencode($accessToken)]), true);
if (
isset($email['elements']) &&
isset($email['elements'][0]) &&
isset($email['elements'][0]['handle~']) &&
isset($email['elements'][0]['handle~']['emailAddress'])
) {
return $email['elements'][0]['handle~']['emailAddress'];
}
return '';
return $email['elements'][0]['handle~']['emailAddress'] ?? '';
}
/**
@ -153,7 +140,7 @@ class Linkedin extends OAuth2
*
* If present, the email is verified. This was verfied through a manual Linkedin sign up process
*
* @param $accessToken
* @param string $accessToken
*
* @return bool
*/
@ -165,11 +152,11 @@ class Linkedin extends OAuth2
}
/**
* @param $accessToken
* @param string $accessToken
*
* @return string
*/
public function getUserName(string $accessToken):string
public function getUserName(string $accessToken): string
{
$user = $this->getUser($accessToken);
$name = '';
@ -179,7 +166,7 @@ class Linkedin extends OAuth2
}
if (isset($user['localizedLastName'])) {
$name = (empty($name)) ? $user['localizedLastName'] : $name.' '.$user['localizedLastName'];
$name = (empty($name)) ? $user['localizedLastName'] : $name . ' ' . $user['localizedLastName'];
}
return $name;
@ -193,7 +180,7 @@ class Linkedin extends OAuth2
protected function getUser(string $accessToken)
{
if (empty($this->user)) {
$this->user = \json_decode($this->request('GET', 'https://api.linkedin.com/v2/me', ['Authorization: Bearer '.\urlencode($accessToken)]), true);
$this->user = \json_decode($this->request('GET', 'https://api.linkedin.com/v2/me', ['Authorization: Bearer ' . \urlencode($accessToken)]), true);
}
return $this->user;

View file

@ -13,17 +13,17 @@ class Microsoft extends OAuth2
/**
* @var array
*/
protected $user = [];
/**
* @var array
*/
protected $tokens = [];
protected array $user = [];
/**
* @var array
*/
protected $scopes = [
protected array $tokens = [];
/**
* @var array
*/
protected array $scopes = [
'offline_access',
'user.read'
];
@ -35,17 +35,17 @@ class Microsoft extends OAuth2
{
return 'microsoft';
}
/**
* @return string
*/
public function getLoginURL(): string
{
return 'https://login.microsoftonline.com/'.$this->getTenantID().'/oauth2/v2.0/authorize?'.\http_build_query([
return 'https://login.microsoftonline.com/' . $this->getTenantID() . '/oauth2/v2.0/authorize?' . \http_build_query([
'client_id' => $this->appID,
'redirect_uri' => $this->callback,
'state'=> \json_encode($this->state),
'scope'=> \implode(' ', $this->getScopes()),
'state' => \json_encode($this->state),
'scope' => \implode(' ', $this->getScopes()),
'response_type' => 'code',
'response_mode' => 'query'
]);
@ -58,7 +58,7 @@ class Microsoft extends OAuth2
*/
protected function getTokens(string $code): array
{
if(empty($this->tokens)) {
if (empty($this->tokens)) {
$headers = ['Content-Type: application/x-www-form-urlencoded'];
$this->tokens = \json_decode($this->request(
'POST',
@ -83,7 +83,7 @@ class Microsoft extends OAuth2
*
* @return array
*/
public function refreshTokens(string $refreshToken):array
public function refreshTokens(string $refreshToken): array
{
$headers = ['Content-Type: application/x-www-form-urlencoded'];
$this->tokens = \json_decode($this->request(
@ -98,7 +98,7 @@ class Microsoft extends OAuth2
])
), true);
if(empty($this->tokens['refresh_token'])) {
if (empty($this->tokens['refresh_token'])) {
$this->tokens['refresh_token'] = $refreshToken;
}
@ -114,11 +114,7 @@ class Microsoft extends OAuth2
{
$user = $this->getUser($accessToken);
if (isset($user['id'])) {
return $user['id'];
}
return '';
return $user['id'] ?? '';
}
/**
@ -130,11 +126,7 @@ class Microsoft extends OAuth2
{
$user = $this->getUser($accessToken);
if (isset($user['userPrincipalName'])) {
return $user['userPrincipalName'];
}
return '';
return $user['userPrincipalName'] ?? '';
}
/**
@ -142,7 +134,7 @@ class Microsoft extends OAuth2
*
* If present, the email is verified. This was verfied through a manual Microsoft sign up process
*
* @param $accessToken
* @param string $accessToken
*
* @return bool
*/
@ -162,11 +154,7 @@ class Microsoft extends OAuth2
{
$user = $this->getUser($accessToken);
if (isset($user['displayName'])) {
return $user['displayName'];
}
return '';
return $user['displayName'] ?? '';
}
/**
@ -177,7 +165,7 @@ class Microsoft extends OAuth2
protected function getUser(string $accessToken): array
{
if (empty($this->user)) {
$headers = ['Authorization: Bearer '. \urlencode($accessToken)];
$headers = ['Authorization: Bearer ' . \urlencode($accessToken)];
$user = $this->request('GET', 'https://graph.microsoft.com/v1.0/me', $headers);
$this->user = \json_decode($user, true);
}
@ -191,7 +179,7 @@ class Microsoft extends OAuth2
* @return array
*/
protected function getAppSecret(): array
{
{
try {
$secret = \json_decode($this->appSecret, true, 512, JSON_THROW_ON_ERROR);
} catch (\Throwable $th) {
@ -208,7 +196,8 @@ class Microsoft extends OAuth2
protected function getClientSecret(): string
{
$secret = $this->getAppSecret();
return (isset($secret['clientSecret'])) ? $secret['clientSecret'] : '';
return $secret['clientSecret'] ?? '';
}
/**
@ -219,6 +208,7 @@ class Microsoft extends OAuth2
protected function getTenantID(): string
{
$secret = $this->getAppSecret();
return (isset($secret['tenantID'])) ? $secret['tenantID'] : 'common';
return $secret['tenantID'] ?? 'common';
}
}

View file

@ -10,29 +10,29 @@ class Mock extends OAuth2
/**
* @var string
*/
protected $version = 'v1';
protected string $version = 'v1';
/**
* @var array
*/
protected $scopes = [
protected array $scopes = [
'email'
];
/**
* @var array
*/
protected $user = [];
protected array $user = [];
/**
* @var array
*/
protected $tokens = [];
protected array $tokens = [];
/**
* @return string
*/
public function getName():string
public function getName(): string
{
return 'mock';
}
@ -40,9 +40,9 @@ class Mock extends OAuth2
/**
* @return string
*/
public function getLoginURL():string
public function getLoginURL(): string
{
return 'http://localhost/'.$this->version.'/mock/tests/general/oauth2?'. \http_build_query([
return 'http://localhost/' . $this->version . '/mock/tests/general/oauth2?' . \http_build_query([
'client_id' => $this->appID,
'redirect_uri' => $this->callback,
'scope' => \implode(' ', $this->getScopes()),
@ -57,16 +57,16 @@ class Mock extends OAuth2
*/
protected function getTokens(string $code): array
{
if(empty($this->tokens)) {
if (empty($this->tokens)) {
$this->tokens = \json_decode($this->request(
'GET',
'http://localhost/' . $this->version . '/mock/tests/general/oauth2/token?' .
\http_build_query([
'client_id' => $this->appID,
'redirect_uri' => $this->callback,
'client_secret' => $this->appSecret,
'code' => $code
])
\http_build_query([
'client_id' => $this->appID,
'redirect_uri' => $this->callback,
'client_secret' => $this->appSecret,
'code' => $code
])
), true);
}
@ -78,20 +78,20 @@ class Mock extends OAuth2
*
* @return array
*/
public function refreshTokens(string $refreshToken):array
public function refreshTokens(string $refreshToken): array
{
$this->tokens = \json_decode($this->request(
'GET',
'http://localhost/' . $this->version . '/mock/tests/general/oauth2/token?' .
\http_build_query([
'client_id' => $this->appID,
'client_secret' => $this->appSecret,
'refresh_token' => $refreshToken,
'grant_type' => 'refresh_token'
])
\http_build_query([
'client_id' => $this->appID,
'client_secret' => $this->appSecret,
'refresh_token' => $refreshToken,
'grant_type' => 'refresh_token'
])
), true);
if(empty($this->tokens['refresh_token'])) {
if (empty($this->tokens['refresh_token'])) {
$this->tokens['refresh_token'] = $refreshToken;
}
@ -103,15 +103,11 @@ class Mock extends OAuth2
*
* @return string
*/
public function getUserID(string $accessToken):string
public function getUserID(string $accessToken): string
{
$user = $this->getUser($accessToken);
if (isset($user['id'])) {
return $user['id'];
}
return '';
return $user['id'] ?? '';
}
/**
@ -119,21 +115,17 @@ class Mock extends OAuth2
*
* @return string
*/
public function getUserEmail(string $accessToken):string
public function getUserEmail(string $accessToken): string
{
$user = $this->getUser($accessToken);
if (isset($user['email'])) {
return $user['email'];
}
return '';
return $user['email'] ?? '';
}
/**
* Check if the OAuth email is verified
*
* @param $accessToken
* @param string $accessToken
*
* @return bool
*/
@ -147,15 +139,11 @@ class Mock extends OAuth2
*
* @return string
*/
public function getUserName(string $accessToken):string
public function getUserName(string $accessToken): string
{
$user = $this->getUser($accessToken);
if (isset($user['name'])) {
return $user['name'];
}
return '';
return $user['name'] ?? '';
}
/**
@ -163,10 +151,10 @@ class Mock extends OAuth2
*
* @return array
*/
protected function getUser(string $accessToken):array
protected function getUser(string $accessToken): array
{
if (empty($this->user)) {
$user = $this->request('GET', 'http://localhost/'.$this->version.'/mock/tests/general/oauth2/user?token='.\urlencode($accessToken));
$user = $this->request('GET', 'http://localhost/' . $this->version . '/mock/tests/general/oauth2/user?token=' . \urlencode($accessToken));
$this->user = \json_decode($user, true);
}

View file

@ -9,32 +9,32 @@ class Notion extends OAuth2
/**
* @var string
*/
private $endpoint = 'https://api.notion.com/v1';
private string $endpoint = 'https://api.notion.com/v1';
/**
* @var string
*/
private $version = '2021-08-16';
private string $version = '2021-08-16';
/**
* @var array
*/
protected $user = [];
/**
* @var array
*/
protected $tokens = [];
protected array $user = [];
/**
* @var array
*/
protected $scopes = [];
protected array $tokens = [];
/**
* @var array
*/
protected array $scopes = [];
/**
* @return string
*/
public function getName():string
public function getName(): string
{
return 'notion';
}
@ -42,9 +42,9 @@ class Notion extends OAuth2
/**
* @return string
*/
public function getLoginURL():string
public function getLoginURL(): string
{
return $this->endpoint . '/oauth/authorize?'. \http_build_query([
return $this->endpoint . '/oauth/authorize?' . \http_build_query([
'client_id' => $this->appID,
'redirect_uri' => $this->callback,
'response_type' => 'code',
@ -60,7 +60,7 @@ class Notion extends OAuth2
*/
protected function getTokens(string $code): array
{
if(empty($this->tokens)) {
if (empty($this->tokens)) {
$headers = ['Authorization: Basic ' . \base64_encode($this->appID . ':' . $this->appSecret)];
$this->tokens = \json_decode($this->request(
'POST',
@ -82,7 +82,7 @@ class Notion extends OAuth2
*
* @return array
*/
public function refreshTokens(string $refreshToken):array
public function refreshTokens(string $refreshToken): array
{
$headers = ['Authorization: Basic ' . \base64_encode($this->appID . ':' . $this->appSecret)];
$this->tokens = \json_decode($this->request(
@ -95,7 +95,7 @@ class Notion extends OAuth2
])
), true);
if(empty($this->tokens['refresh_token'])) {
if (empty($this->tokens['refresh_token'])) {
$this->tokens['refresh_token'] = $refreshToken;
}
@ -103,35 +103,27 @@ class Notion extends OAuth2
}
/**
* @param $accessToken
* @param string $accessToken
*
* @return string
*/
public function getUserID(string $accessToken):string
public function getUserID(string $accessToken): string
{
$response = $this->getUser($accessToken);
if (isset($response['bot']['owner']['user']['id'])) {
return $response['bot']['owner']['user']['id'];
}
return '';
return $response['bot']['owner']['user']['id'] ?? '';
}
/**
* @param $accessToken
* @param string $accessToken
*
* @return string
*/
public function getUserEmail(string $accessToken):string
public function getUserEmail(string $accessToken): string
{
$response = $this->getUser($accessToken);
if(isset($response['bot']['owner']['user']['person']['email'])){
return $response['bot']['owner']['user']['person']['email'];
}
return '';
return $response['bot']['owner']['user']['person']['email'] ?? '';
}
/**
@ -139,7 +131,7 @@ class Notion extends OAuth2
*
* If present, the email is verified. This was verfied through a manual Notion sign up process
*
* @param $accessToken
* @param string $accessToken
*
* @return bool
*/
@ -151,19 +143,15 @@ class Notion extends OAuth2
}
/**
* @param $accessToken
* @param string $accessToken
*
* @return string
*/
public function getUserName(string $accessToken):string
public function getUserName(string $accessToken): string
{
$response = $this->getUser($accessToken);
if (isset($response['bot']['owner']['user']['name'])) {
return $response['bot']['owner']['user']['name'];
}
return '';
return $response['bot']['owner']['user']['name'] ?? '';
}
/**
@ -171,11 +159,11 @@ class Notion extends OAuth2
*
* @return array
*/
protected function getUser(string $accessToken)
protected function getUser(string $accessToken): array
{
$headers = [
'Notion-Version: ' . $this->version,
'Authorization: Bearer '.\urlencode($accessToken)
'Authorization: Bearer ' . \urlencode($accessToken)
];
if (empty($this->user)) {

View file

@ -8,27 +8,27 @@ use Appwrite\Auth\OAuth2;
// https://developer.okta.com/docs/guides/sign-into-web-app-redirect/php/main/
class Okta extends OAuth2
{
/**
{
/**
* @var array
*/
protected $scopes = [
protected array $scopes = [
'openid',
'profile',
'email',
'offline_access'
];
/**
* @var array
*/
protected $user = [];
protected array $user = [];
/**
* @var array
*/
protected $tokens = [];
protected array $tokens = [];
/**
* @return string
*/
@ -42,11 +42,11 @@ class Okta extends OAuth2
*/
public function getLoginURL(): string
{
return 'https://'.$this->getOktaDomain().'/oauth2/'.$this->getAuthorizationServerId().'/v1/authorize?'.\http_build_query([
return 'https://' . $this->getOktaDomain() . '/oauth2/' . $this->getAuthorizationServerId() . '/v1/authorize?' . \http_build_query([
'client_id' => $this->appID,
'redirect_uri' => $this->callback,
'state'=> \json_encode($this->state),
'scope'=> \implode(' ', $this->getScopes()),
'state' => \json_encode($this->state),
'scope' => \implode(' ', $this->getScopes()),
'response_type' => 'code'
]);
}
@ -58,11 +58,11 @@ class Okta extends OAuth2
*/
protected function getTokens(string $code): array
{
if(empty($this->tokens)) {
if (empty($this->tokens)) {
$headers = ['Content-Type: application/x-www-form-urlencoded'];
$this->tokens = \json_decode($this->request(
'POST',
'https://'.$this->getOktaDomain().'/oauth2/'.$this->getAuthorizationServerId().'/v1/token',
'https://' . $this->getOktaDomain() . '/oauth2/' . $this->getAuthorizationServerId() . '/v1/token',
$headers,
\http_build_query([
'code' => $code,
@ -77,8 +77,8 @@ class Okta extends OAuth2
return $this->tokens;
}
/**
* @param string $refreshToken
*
@ -89,7 +89,7 @@ class Okta extends OAuth2
$headers = ['Content-Type: application/x-www-form-urlencoded'];
$this->tokens = \json_decode($this->request(
'POST',
'https://'.$this->getOktaDomain().'/oauth2/'.$this->getAuthorizationServerId().'/v1/token',
'https://' . $this->getOktaDomain() . '/oauth2/' . $this->getAuthorizationServerId() . '/v1/token',
$headers,
\http_build_query([
'refresh_token' => $refreshToken,
@ -99,7 +99,7 @@ class Okta extends OAuth2
])
), true);
if(empty($this->tokens['refresh_token'])) {
if (empty($this->tokens['refresh_token'])) {
$this->tokens['refresh_token'] = $refreshToken;
}
@ -114,12 +114,8 @@ class Okta extends OAuth2
public function getUserID(string $accessToken): string
{
$user = $this->getUser($accessToken);
if (isset($user['sub'])) {
return $user['sub'];
}
return '';
return $user['sub'] ?? '';
}
/**
@ -130,12 +126,8 @@ class Okta extends OAuth2
public function getUserEmail(string $accessToken): string
{
$user = $this->getUser($accessToken);
if (isset($user['email'])) {
return $user['email'];
}
return '';
return $user['email'] ?? '';
}
/**
@ -143,7 +135,7 @@ class Okta extends OAuth2
*
* @link https://developer.okta.com/docs/reference/api/oidc/#userinfo
*
* @param $accessToken
* @param string $accessToken
*
* @return bool
*/
@ -151,7 +143,7 @@ class Okta extends OAuth2
{
$user = $this->getUser($accessToken);
if (isset($user['email_verified']) && $user['email_verified'] === true) {
if ($user['email_verified'] ?? false) {
return true;
}
@ -166,15 +158,11 @@ class Okta extends OAuth2
public function getUserName(string $accessToken): string
{
$user = $this->getUser($accessToken);
if (isset($user['name'])) {
return $user['name'];
}
return '';
return $user['name'] ?? '';
}
/**
/**
* @param string $accessToken
*
* @return array
@ -182,8 +170,8 @@ class Okta extends OAuth2
protected function getUser(string $accessToken): array
{
if (empty($this->user)) {
$headers = ['Authorization: Bearer '. \urlencode($accessToken)];
$user = $this->request('GET', 'https://'.$this->getOktaDomain().'/oauth2/'.$this->getAuthorizationServerId().'/v1/userinfo', $headers);
$headers = ['Authorization: Bearer ' . \urlencode($accessToken)];
$user = $this->request('GET', 'https://' . $this->getOktaDomain() . '/oauth2/' . $this->getAuthorizationServerId() . '/v1/userinfo', $headers);
$this->user = \json_decode($user, true);
}
@ -199,10 +187,10 @@ class Okta extends OAuth2
{
$secret = $this->getAppSecret();
return (isset($secret['clientSecret'])) ? $secret['clientSecret'] : '';
return $secret['clientSecret'] ?? '';
}
/**
/**
* Extracts the Okta Domain from the JSON stored in appSecret
*
* @return string
@ -210,7 +198,8 @@ class Okta extends OAuth2
protected function getOktaDomain(): string
{
$secret = $this->getAppSecret();
return (isset($secret['oktaDomain'])) ? $secret['oktaDomain'] : '';
return $secret['oktaDomain'] ?? '';
}
/**
@ -221,7 +210,8 @@ class Okta extends OAuth2
protected function getAuthorizationServerId(): string
{
$secret = $this->getAppSecret();
return (isset($secret['authorizationServerId'])) ? $secret['authorizationServerId'] : 'default';
return $secret['authorizationServerId'] ?? 'default';
}
/**
@ -230,7 +220,7 @@ class Okta extends OAuth2
* @return array
*/
protected function getAppSecret(): array
{
{
try {
$secret = \json_decode($this->appSecret, true, 512, JSON_THROW_ON_ERROR);
} catch (\Throwable $th) {

View file

@ -12,7 +12,7 @@ class Paypal extends OAuth2
/**
* @var array
*/
private $endpoint = [
private array $endpoint = [
'sandbox' => 'https://www.sandbox.paypal.com/',
'live' => 'https://www.paypal.com/',
];
@ -20,7 +20,7 @@ class Paypal extends OAuth2
/**
* @var array
*/
private $resourceEndpoint = [
private array $resourceEndpoint = [
'sandbox' => 'https://api.sandbox.paypal.com/v1/',
'live' => 'https://api.paypal.com/v1/',
];
@ -28,22 +28,22 @@ class Paypal extends OAuth2
/**
* @var string
*/
protected $environment = 'live';
protected string $environment = 'live';
/**
* @var array
*/
protected $user = [];
/**
* @var array
*/
protected $tokens = [];
protected array $user = [];
/**
* @var array
*/
protected $scopes = [
protected array $tokens = [];
/**
* @var array
*/
protected array $scopes = [
'openid',
'profile',
'email'
@ -62,7 +62,7 @@ class Paypal extends OAuth2
*/
public function getLoginURL(): string
{
$url = $this->endpoint[$this->environment] . 'connect/?'.
$url = $this->endpoint[$this->environment] . 'connect/?' .
\http_build_query([
'flowEntry' => 'static',
'response_type' => 'code',
@ -83,7 +83,7 @@ class Paypal extends OAuth2
*/
protected function getTokens(string $code): array
{
if(empty($this->tokens)) {
if (empty($this->tokens)) {
$this->tokens = \json_decode($this->request(
'POST',
$this->resourceEndpoint[$this->environment] . 'oauth2/token',
@ -103,7 +103,7 @@ class Paypal extends OAuth2
*
* @return array
*/
public function refreshTokens(string $refreshToken):array
public function refreshTokens(string $refreshToken): array
{
$this->tokens = \json_decode($this->request(
'POST',
@ -115,7 +115,7 @@ class Paypal extends OAuth2
])
), true);
if(empty($this->tokens['refresh_token'])) {
if (empty($this->tokens['refresh_token'])) {
$this->tokens['refresh_token'] = $refreshToken;
}
@ -131,11 +131,7 @@ class Paypal extends OAuth2
{
$user = $this->getUser($accessToken);
if (isset($user['payer_id'])) {
return $user['payer_id'];
}
return '';
return $user['payer_id'] ?? '';
}
/**
@ -151,7 +147,7 @@ class Paypal extends OAuth2
$email = array_filter($user['emails'], function ($email) {
return $email['primary'] === true;
});
if (!empty($email)) {
return $email[0]['value'];
}
@ -165,7 +161,7 @@ class Paypal extends OAuth2
*
* @link https://developer.paypal.com/docs/api/identity/v1/#userinfo_get
*
* @param $accessToken
* @param string $accessToken
*
* @return bool
*/
@ -173,7 +169,7 @@ class Paypal extends OAuth2
{
$user = $this->getUser($accessToken);
if (isset($user['verified_account']) && $user['verified_account'] === true) {
if ($user['verified_account'] ?? false) {
return true;
}
@ -189,11 +185,7 @@ class Paypal extends OAuth2
{
$user = $this->getUser($accessToken);
if (isset($user['name'])) {
return $user['name'];
}
return '';
return $user['name'] ?? '';
}
/**
@ -205,7 +197,7 @@ class Paypal extends OAuth2
{
$header = [
'Content-Type: application/json',
'Authorization: Bearer '.\urlencode($accessToken),
'Authorization: Bearer ' . \urlencode($accessToken),
];
if (empty($this->user)) {
$user = $this->request(

View file

@ -6,7 +6,7 @@ use Appwrite\Auth\OAuth2\Paypal;
class PaypalSandbox extends Paypal
{
protected $environment = 'sandbox';
protected string $environment = 'sandbox';
/**
* @return string

View file

@ -14,17 +14,17 @@ class Salesforce extends OAuth2
/**
* @var array
*/
protected $user = [];
/**
* @var array
*/
protected $tokens = [];
protected array $user = [];
/**
* @var array
*/
protected $scopes = [
protected array $tokens = [];
/**
* @var array
*/
protected array $scopes = [
"openid"
];
@ -37,7 +37,7 @@ class Salesforce extends OAuth2
}
/**
* @param $state
* @param string $state
*
* @return array
*/
@ -52,13 +52,13 @@ class Salesforce extends OAuth2
*/
public function getLoginURL(): string
{
return 'https://login.salesforce.com/services/oauth2/authorize?'.\http_build_query([
'response_type' => 'code',
'client_id' => $this->appID,
'redirect_uri'=> $this->callback,
'scope'=> \implode(' ', $this->getScopes()),
'state' => \json_encode($this->state)
]);
return 'https://login.salesforce.com/services/oauth2/authorize?' . \http_build_query([
'response_type' => 'code',
'client_id' => $this->appID,
'redirect_uri' => $this->callback,
'scope' => \implode(' ', $this->getScopes()),
'state' => \json_encode($this->state)
]);
}
/**
@ -68,7 +68,7 @@ class Salesforce extends OAuth2
*/
protected function getTokens(string $code): array
{
if(empty($this->tokens)) {
if (empty($this->tokens)) {
$headers = [
'Authorization: Basic ' . \base64_encode($this->appID . ':' . $this->appSecret),
'Content-Type: application/x-www-form-urlencoded',
@ -93,7 +93,7 @@ class Salesforce extends OAuth2
*
* @return array
*/
public function refreshTokens(string $refreshToken):array
public function refreshTokens(string $refreshToken): array
{
$headers = [
'Authorization: Basic ' . \base64_encode($this->appID . ':' . $this->appSecret),
@ -109,7 +109,7 @@ class Salesforce extends OAuth2
])
), true);
if(empty($this->tokens['refresh_token'])) {
if (empty($this->tokens['refresh_token'])) {
$this->tokens['refresh_token'] = $refreshToken;
}
@ -125,11 +125,7 @@ class Salesforce extends OAuth2
{
$user = $this->getUser($accessToken);
if (isset($user['user_id'])) {
return $user['user_id'];
}
return '';
return $user['user_id'] ?? '';
}
/**
@ -141,11 +137,7 @@ class Salesforce extends OAuth2
{
$user = $this->getUser($accessToken);
if (isset($user['email'])) {
return $user['email'];
}
return '';
return $user['email'] ?? '';
}
/**
@ -153,7 +145,7 @@ class Salesforce extends OAuth2
*
* @link https://help.salesforce.com/s/articleView?id=sf.remoteaccess_using_userinfo_endpoint.htm&type=5
*
* @param $accessToken
* @param string $accessToken
*
* @return bool
*/
@ -161,7 +153,7 @@ class Salesforce extends OAuth2
{
$user = $this->getUser($accessToken);
if (isset($user['email_verified']) && $user['email_verified'] === true) {
if ($user['email_verified'] ?? false) {
return true;
}
@ -177,11 +169,7 @@ class Salesforce extends OAuth2
{
$user = $this->getUser($accessToken);
if (isset($user['name'])) {
return $user['name'];
}
return '';
return $user['name'] ?? '';
}
/**
@ -192,7 +180,7 @@ class Salesforce extends OAuth2
protected function getUser(string $accessToken): array
{
if (empty($this->user)) {
$user = $this->request('GET', 'https://login.salesforce.com/services/oauth2/userinfo?access_token='.\urlencode($accessToken));
$user = $this->request('GET', 'https://login.salesforce.com/services/oauth2/userinfo?access_token=' . \urlencode($accessToken));
$this->user = \json_decode($user, true);
}
return $this->user;

View file

@ -3,24 +3,23 @@
namespace Appwrite\Auth\OAuth2;
use Appwrite\Auth\OAuth2;
use Utopia\Exception;
class Slack extends OAuth2
{
/**
* @var array
*/
protected $user = [];
/**
* @var array
*/
protected $tokens = [];
protected array $user = [];
/**
* @var array
*/
protected $scopes = [
protected array $tokens = [];
/**
* @var array
*/
protected array $scopes = [
'identity.avatar',
'identity.basic',
'identity.email',
@ -30,7 +29,7 @@ class Slack extends OAuth2
/**
* @return string
*/
public function getName():string
public function getName(): string
{
return 'slack';
}
@ -38,11 +37,11 @@ class Slack extends OAuth2
/**
* @return string
*/
public function getLoginURL():string
public function getLoginURL(): string
{
// https://api.slack.com/docs/oauth#step_1_-_sending_users_to_authorize_and_or_install
return 'https://slack.com/oauth/authorize?'.\http_build_query([
'client_id'=> $this->appID,
return 'https://slack.com/oauth/authorize?' . \http_build_query([
'client_id' => $this->appID,
'scope' => \implode(' ', $this->getScopes()),
'redirect_uri' => $this->callback,
'state' => \json_encode($this->state)
@ -56,7 +55,7 @@ class Slack extends OAuth2
*/
protected function getTokens(string $code): array
{
if(empty($this->tokens)) {
if (empty($this->tokens)) {
// https://api.slack.com/docs/oauth#step_3_-_exchanging_a_verification_code_for_an_access_token
$this->tokens = \json_decode($this->request(
'GET',
@ -77,7 +76,7 @@ class Slack extends OAuth2
*
* @return array
*/
public function refreshTokens(string $refreshToken):array
public function refreshTokens(string $refreshToken): array
{
$this->tokens = \json_decode($this->request(
'GET',
@ -89,7 +88,7 @@ class Slack extends OAuth2
])
), true);
if(empty($this->tokens['refresh_token'])) {
if (empty($this->tokens['refresh_token'])) {
$this->tokens['refresh_token'] = $refreshToken;
}
@ -101,15 +100,11 @@ class Slack extends OAuth2
*
* @return string
*/
public function getUserID(string $accessToken):string
public function getUserID(string $accessToken): string
{
$user = $this->getUser($accessToken);
if (isset($user['user']['id'])) {
return $user['user']['id'];
}
return '';
return $user['user']['id'] ?? '';
}
/**
@ -117,15 +112,11 @@ class Slack extends OAuth2
*
* @return string
*/
public function getUserEmail(string $accessToken):string
public function getUserEmail(string $accessToken): string
{
$user = $this->getUser($accessToken);
if (isset($user['user']['email'])) {
return $user['user']['email'];
}
return '';
return $user['user']['email'] ?? '';
}
/**
@ -135,7 +126,7 @@ class Slack extends OAuth2
*
* @link https://slack.com/help/articles/207262907-Change-your-email-address
*
* @param $accessToken
* @param string $accessToken
*
* @return bool
*/
@ -151,15 +142,11 @@ class Slack extends OAuth2
*
* @return string
*/
public function getUserName(string $accessToken):string
public function getUserName(string $accessToken): string
{
$user = $this->getUser($accessToken);
if (isset($user['user']['name'])) {
return $user['user']['name'];
}
return '';
return $user['user']['name'] ?? '';
}
/**
@ -169,12 +156,12 @@ class Slack extends OAuth2
*
* @return array
*/
protected function getUser(string $accessToken):array
protected function getUser(string $accessToken): array
{
if (empty($this->user)) {
$user = $this->request(
'GET',
'https://slack.com/api/users.identity?token='.\urlencode($accessToken)
'https://slack.com/api/users.identity?token=' . \urlencode($accessToken)
);
$this->user = \json_decode($user, true);

View file

@ -13,34 +13,34 @@ class Spotify extends OAuth2
/**
* @var string
*/
private $endpoint = 'https://accounts.spotify.com/';
private string $endpoint = 'https://accounts.spotify.com/';
/**
* @var string
*/
private $resourceEndpoint = 'https://api.spotify.com/v1/';
private string $resourceEndpoint = 'https://api.spotify.com/v1/';
/**
* @var array
*/
protected $scopes = [
protected array $scopes = [
'user-read-email',
];
/**
* @var array
*/
protected $user = [];
protected array $user = [];
/**
* @var array
*/
protected $tokens = [];
protected array $tokens = [];
/**
* @return string
*/
public function getName():string
public function getName(): string
{
return 'spotify';
}
@ -48,9 +48,9 @@ class Spotify extends OAuth2
/**
* @return string
*/
public function getLoginURL():string
public function getLoginURL(): string
{
return $this->endpoint . 'authorize?'.
return $this->endpoint . 'authorize?' .
\http_build_query([
'response_type' => 'code',
'client_id' => $this->appID,
@ -67,7 +67,7 @@ class Spotify extends OAuth2
*/
protected function getTokens(string $code): array
{
if(empty($this->tokens)) {
if (empty($this->tokens)) {
$headers = ['Authorization: Basic ' . \base64_encode($this->appID . ':' . $this->appSecret)];
$this->tokens = \json_decode($this->request(
'POST',
@ -89,7 +89,7 @@ class Spotify extends OAuth2
*
* @return array
*/
public function refreshTokens(string $refreshToken):array
public function refreshTokens(string $refreshToken): array
{
$headers = ['Authorization: Basic ' . \base64_encode($this->appID . ':' . $this->appSecret)];
$this->tokens = \json_decode($this->request(
@ -102,7 +102,7 @@ class Spotify extends OAuth2
])
), true);
if(empty($this->tokens['refresh_token'])) {
if (empty($this->tokens['refresh_token'])) {
$this->tokens['refresh_token'] = $refreshToken;
}
@ -110,35 +110,27 @@ class Spotify extends OAuth2
}
/**
* @param $accessToken
* @param string $accessToken
*
* @return string
*/
public function getUserID(string $accessToken):string
public function getUserID(string $accessToken): string
{
$user = $this->getUser($accessToken);
if (isset($user['id'])) {
return $user['id'];
}
return '';
return $user['id'] ?? '';
}
/**
* @param $accessToken
* @param string $accessToken
*
* @return string
*/
public function getUserEmail(string $accessToken):string
public function getUserEmail(string $accessToken): string
{
$user = $this->getUser($accessToken);
if (isset($user['email'])) {
return $user['email'];
}
return '';
return $user['email'] ?? '';
}
/**
@ -148,7 +140,7 @@ class Spotify extends OAuth2
*
* @link https://developer.spotify.com/documentation/web-api/reference/#/operations/get-current-users-profile
*
* @param $accessToken
* @param string $accessToken
*
* @return bool
*/
@ -158,19 +150,15 @@ class Spotify extends OAuth2
}
/**
* @param $accessToken
* @param string $accessToken
*
* @return string
*/
public function getUserName(string $accessToken):string
public function getUserName(string $accessToken): string
{
$user = $this->getUser($accessToken);
if (isset($user['display_name'])) {
return $user['display_name'];
}
return '';
return $user['display_name'] ?? '';
}
/**
@ -184,7 +172,7 @@ class Spotify extends OAuth2
$this->user = \json_decode($this->request(
'GET',
$this->resourceEndpoint . 'me',
['Authorization: Bearer '.\urlencode($accessToken)]
['Authorization: Bearer ' . \urlencode($accessToken)]
), true);
}

View file

@ -10,38 +10,37 @@ class Stripe extends OAuth2
/**
* @var array
*/
protected $user = [];
protected array $user = [];
/**
* @var array
*/
protected $tokens = [];
protected array $tokens = [];
/**
* @var string
*/
protected $stripeAccountId = '';
protected string $stripeAccountId = '';
/**
* @var array
*/
protected $scopes = [
protected array $scopes = [
'read_write',
];
/**
* @return string
/**
* @var array
*/
protected $grantType = [
'authorize' => 'authorization_code',
'refresh' => 'refresh_token',
protected array $grantType = [
'authorize' => 'authorization_code',
'refresh' => 'refresh_token',
];
/**
* @return string
*/
public function getName():string
public function getName(): string
{
return 'stripe';
}
@ -49,9 +48,9 @@ class Stripe extends OAuth2
/**
* @return string
*/
public function getLoginURL():string
public function getLoginURL(): string
{
return 'https://connect.stripe.com/oauth/authorize?'. \http_build_query([
return 'https://connect.stripe.com/oauth/authorize?' . \http_build_query([
'response_type' => 'code', // The only option at the moment is "code."
'client_id' => $this->appID,
'redirect_uri' => $this->callback,
@ -67,7 +66,7 @@ class Stripe extends OAuth2
*/
protected function getTokens(string $code): array
{
if(empty($this->tokens)) {
if (empty($this->tokens)) {
$this->tokens = \json_decode($this->request(
'POST',
'https://connect.stripe.com/oauth/token',
@ -89,7 +88,7 @@ class Stripe extends OAuth2
*
* @return array
*/
public function refreshTokens(string $refreshToken):array
public function refreshTokens(string $refreshToken): array
{
$this->tokens = \json_decode($this->request(
'POST',
@ -101,7 +100,7 @@ class Stripe extends OAuth2
])
), true);
if(empty($this->tokens['refresh_token'])) {
if (empty($this->tokens['refresh_token'])) {
$this->tokens['refresh_token'] = $refreshToken;
}
@ -110,32 +109,28 @@ class Stripe extends OAuth2
}
/**
* @param $accessToken
* @param string $accessToken
*
* @return string
*/
public function getUserID(string $accessToken):string
public function getUserID(string $accessToken): string
{
$user = $this->getUser($accessToken);
if (isset($user['id'])) {
return $user['id'];
}
return '';
return $user['id'] ?? '';
}
/**
* @param $accessToken
* @param string $accessToken
*
* @return string
*/
public function getUserEmail(string $accessToken):string
public function getUserEmail(string $accessToken): string
{
$user = $this->getUser($accessToken);
if(empty($user)) {
return '';
if (empty($user)) {
return '';
}
return $user['email'] ?? '';
@ -146,7 +141,7 @@ class Stripe extends OAuth2
*
* If present, the email is verified. This was verfied through a manual Stripe sign up process
*
* @param $accessToken
* @param string $accessToken
*
* @return bool
*/
@ -158,19 +153,15 @@ class Stripe extends OAuth2
}
/**
* @param $accessToken
* @param string $accessToken
*
* @return string
*/
public function getUserName(string $accessToken):string
public function getUserName(string $accessToken): string
{
$user = $this->getUser($accessToken);
if (isset($user['name'])) {
return $user['name'];
}
return '';
return $user['name'] ?? '';
}
/**
@ -182,15 +173,13 @@ class Stripe extends OAuth2
{
if (empty($this->user) && !empty($this->stripeAccountId)) {
$this->user = \json_decode(
$this->request(
'GET',
'https://api.stripe.com/v1/accounts/' . $this->stripeAccountId,
['Authorization: Bearer '.\urlencode($accessToken)]
),
true
$this->request(
'GET',
'https://api.stripe.com/v1/accounts/' . $this->stripeAccountId,
['Authorization: Bearer ' . \urlencode($accessToken)]
),
true
);
}
return $this->user;

View file

@ -12,35 +12,37 @@ class Tradeshift extends OAuth2
const TRADESHIFT_SANDBOX_API_DOMAIN = 'api-sandbox.tradeshift.com';
const TRADESHIFT_API_DOMAIN = 'api.tradeshift.com';
private $apiDomain = [
private array $apiDomain = [
'sandbox' => self::TRADESHIFT_SANDBOX_API_DOMAIN,
'live' => self::TRADESHIFT_API_DOMAIN,
];
private $endpoint = [
private array $endpoint = [
'sandbox' => 'https://' . self::TRADESHIFT_SANDBOX_API_DOMAIN . '/tradeshift/',
'live' => 'https://' . self::TRADESHIFT_API_DOMAIN . '/tradeshift/',
];
private $resourceEndpoint = [
private array $resourceEndpoint = [
'sandbox' => 'https://' . self::TRADESHIFT_SANDBOX_API_DOMAIN . '/tradeshift/rest/external/',
'live' => 'https://' . self::TRADESHIFT_API_DOMAIN . '/tradeshift/rest/external/',
];
protected $environment = 'live';
protected string $environment = 'live';
/**
* @var array
*/
protected $user = [];
protected array $user = [];
/**
* @var array
*/
protected $tokens = [];
protected array $tokens = [];
protected $scopes = [
/**
* @var array
*/
protected array$scopes = [
'openid',
'offline',
];
@ -78,7 +80,7 @@ class Tradeshift extends OAuth2
*/
protected function getTokens(string $code): array
{
if(empty($this->tokens)) {
if (empty($this->tokens)) {
$this->tokens = \json_decode($this->request(
'POST',
$this->endpoint[$this->environment] . 'auth/token',
@ -98,7 +100,7 @@ class Tradeshift extends OAuth2
*
* @return array
*/
public function refreshTokens(string $refreshToken):array
public function refreshTokens(string $refreshToken): array
{
$this->tokens = \json_decode($this->request(
'POST',
@ -109,8 +111,8 @@ class Tradeshift extends OAuth2
'refresh_token' => $refreshToken,
])
), true);
if(empty($this->tokens['refresh_token'])) {
if (empty($this->tokens['refresh_token'])) {
$this->tokens['refresh_token'] = $refreshToken;
}
@ -146,7 +148,7 @@ class Tradeshift extends OAuth2
*
* If present, the email is verified. This was verfied through a manual Tradeshift sign up process
*
* @param $accessToken
* @param string $accessToken
*
* @return bool
*/

View file

@ -6,7 +6,7 @@ use Appwrite\Auth\OAuth2\Tradeshift;
class TradeshiftBox extends Tradeshift
{
protected $environment = 'sandbox';
protected string $environment = 'sandbox';
/**
* @return string

View file

@ -13,34 +13,34 @@ class Twitch extends OAuth2
/**
* @var string
*/
private $endpoint = 'https://id.twitch.tv/oauth2/';
private string $endpoint = 'https://id.twitch.tv/oauth2/';
/**
* @var string
*/
private $resourceEndpoint = 'https://api.twitch.tv/helix/users';
private string $resourceEndpoint = 'https://api.twitch.tv/helix/users';
/**
* @var array
*/
protected $scopes = [
protected array $scopes = [
'user:read:email',
];
/**
* @var array
*/
protected $user = [];
protected array $user = [];
/**
* @var array
*/
protected $tokens = [];
protected array $tokens = [];
/**
* @return string
*/
public function getName():string
public function getName(): string
{
return 'twitch';
}
@ -48,9 +48,9 @@ class Twitch extends OAuth2
/**
* @return string
*/
public function getLoginURL():string
public function getLoginURL(): string
{
return $this->endpoint . 'authorize?'.
return $this->endpoint . 'authorize?' .
\http_build_query([
'response_type' => 'code',
'client_id' => $this->appID,
@ -68,7 +68,7 @@ class Twitch extends OAuth2
*/
protected function getTokens(string $code): array
{
if(empty($this->tokens)) {
if (empty($this->tokens)) {
$this->tokens = \json_decode($this->request(
'POST',
$this->endpoint . 'token?' . \http_build_query([
@ -89,7 +89,7 @@ class Twitch extends OAuth2
*
* @return array
*/
public function refreshTokens(string $refreshToken):array
public function refreshTokens(string $refreshToken): array
{
$this->tokens = \json_decode($this->request(
'POST',
@ -101,7 +101,7 @@ class Twitch extends OAuth2
])
), true);
if(empty($this->tokens['refresh_token'])) {
if (empty($this->tokens['refresh_token'])) {
$this->tokens['refresh_token'] = $refreshToken;
}
@ -109,35 +109,27 @@ class Twitch extends OAuth2
}
/**
* @param $accessToken
* @param string $accessToken
*
* @return string
*/
public function getUserID(string $accessToken):string
public function getUserID(string $accessToken): string
{
$user = $this->getUser($accessToken);
if (isset($user['id'])) {
return $user['id'];
}
return '';
return $user['id'] ?? '';
}
/**
* @param $accessToken
* @param string $accessToken
*
* @return string
*/
public function getUserEmail(string $accessToken):string
public function getUserEmail(string $accessToken): string
{
$user = $this->getUser($accessToken);
if (isset($user['email'])) {
return $user['email'];
}
return '';
return $user['email'] ?? '';
}
/**
@ -147,31 +139,27 @@ class Twitch extends OAuth2
*
* @link https://dev.twitch.tv/docs/api/reference#get-users
*
* @param $accessToken
* @param string $accessToken
*
* @return bool
*/
public function isEmailVerified(string $accessToken): bool
{
$email = $this->getUserEmail($accessToken);
return !empty($email);
}
/**
* @param $accessToken
* @param string $accessToken
*
* @return string
*/
public function getUserName(string $accessToken):string
public function getUserName(string $accessToken): string
{
$user = $this->getUser($accessToken);
if (isset($user['display_name'])) {
return $user['display_name'];
}
return '';
return $user['display_name'] ?? '';
}
/**
@ -186,8 +174,8 @@ class Twitch extends OAuth2
'GET',
$this->resourceEndpoint,
[
'Authorization: Bearer '.\urlencode($accessToken),
'Client-Id: '. \urlencode($this->appID)
'Authorization: Bearer ' . \urlencode($accessToken),
'Client-Id: ' . \urlencode($this->appID)
]
), true);

View file

@ -12,24 +12,24 @@ class WordPress extends OAuth2
/**
* @var array
*/
protected $user = [];
/**
* @var array
*/
protected $tokens = [];
protected array $user = [];
/**
* @var array
*/
protected $scopes = [
protected array $tokens = [];
/**
* @var array
*/
protected array $scopes = [
'auth',
];
/**
* @return string
*/
public function getName():string
public function getName(): string
{
return 'wordpress';
}
@ -37,9 +37,9 @@ class WordPress extends OAuth2
/**
* @return string
*/
public function getLoginURL():string
public function getLoginURL(): string
{
return 'https://public-api.wordpress.com/oauth2/authorize?'. \http_build_query([
return 'https://public-api.wordpress.com/oauth2/authorize?' . \http_build_query([
'client_id' => $this->appID,
'redirect_uri' => $this->callback,
'response_type' => 'code',
@ -55,7 +55,7 @@ class WordPress extends OAuth2
*/
protected function getTokens(string $code): array
{
if(empty($this->tokens)) {
if (empty($this->tokens)) {
$this->tokens = \json_decode($this->request(
'POST',
'https://public-api.wordpress.com/oauth2/token',
@ -78,7 +78,7 @@ class WordPress extends OAuth2
*
* @return array
*/
public function refreshTokens(string $refreshToken):array
public function refreshTokens(string $refreshToken): array
{
$this->tokens = \json_decode($this->request(
'POST',
@ -92,7 +92,7 @@ class WordPress extends OAuth2
])
), true);
if(empty($this->tokens['refresh_token'])) {
if (empty($this->tokens['refresh_token'])) {
$this->tokens['refresh_token'] = $refreshToken;
}
@ -100,32 +100,28 @@ class WordPress extends OAuth2
}
/**
* @param $accessToken
* @param string $accessToken
*
* @return string
*/
public function getUserID(string $accessToken):string
public function getUserID(string $accessToken): string
{
$user = $this->getUser($accessToken);
if (isset($user['ID'])) {
return $user['ID'];
}
return '';
return $user['ID'] ?? '';
}
/**
* @param $accessToken
* @param string $accessToken
*
* @return string
*/
public function getUserEmail(string $accessToken):string
public function getUserEmail(string $accessToken): string
{
$user = $this->getUser($accessToken);
if (isset($user['email']) && $user['verified']) {
return $user['email'];
if ($user['verified']) {
return $user['email'] ?? '';
}
return '';
@ -136,7 +132,7 @@ class WordPress extends OAuth2
*
* @link https://developer.wordpress.com/docs/api/1.1/get/me/
*
* @param $accessToken
* @param string $accessToken
*
* @return bool
*/
@ -144,7 +140,7 @@ class WordPress extends OAuth2
{
$user = $this->getUser($accessToken);
if (isset($user['email_verified']) && $user['email_verified'] === true) {
if ($user['email_verified'] ?? false) {
return true;
}
@ -152,19 +148,15 @@ class WordPress extends OAuth2
}
/**
* @param $accessToken
* @param string $accessToken
*
* @return string
*/
public function getUserName(string $accessToken):string
public function getUserName(string $accessToken): string
{
$user = $this->getUser($accessToken);
if (isset($user['username'])) {
return $user['username'];
}
return '';
return $user['username'] ?? '';
}
/**
@ -175,7 +167,7 @@ class WordPress extends OAuth2
protected function getUser(string $accessToken)
{
if (empty($this->user)) {
$this->user = \json_decode($this->request('GET', 'https://public-api.wordpress.com/rest/v1/me', ['Authorization: Bearer '.$accessToken]), true);
$this->user = \json_decode($this->request('GET', 'https://public-api.wordpress.com/rest/v1/me', ['Authorization: Bearer ' . $accessToken]), true);
}
return $this->user;

View file

@ -13,17 +13,17 @@ class Yahoo extends OAuth2
/**
* @var string
*/
private $endpoint = 'https://api.login.yahoo.com/oauth2/';
private string $endpoint = 'https://api.login.yahoo.com/oauth2/';
/**
* @var string
*/
private $resourceEndpoint = 'https://api.login.yahoo.com/openid/v1/userinfo';
private string $resourceEndpoint = 'https://api.login.yahoo.com/openid/v1/userinfo';
/**
* @var array
*/
protected $scopes = [
protected array $scopes = [
'sdct-r',
'sdpp-w',
];
@ -31,17 +31,17 @@ class Yahoo extends OAuth2
/**
* @var array
*/
protected $user = [];
protected array $user = [];
/**
* @var array
*/
protected $tokens = [];
protected array $tokens = [];
/**
* @return string
*/
public function getName():string
public function getName(): string
{
return 'yahoo';
}
@ -60,9 +60,9 @@ class Yahoo extends OAuth2
/**
* @return string
*/
public function getLoginURL():string
public function getLoginURL(): string
{
return $this->endpoint . 'request_auth?'.
return $this->endpoint . 'request_auth?' .
\http_build_query([
'response_type' => 'code',
'client_id' => $this->appID,
@ -79,7 +79,7 @@ class Yahoo extends OAuth2
*/
protected function getTokens(string $code): array
{
if(empty($this->tokens)) {
if (empty($this->tokens)) {
$headers = [
'Authorization: Basic ' . \base64_encode($this->appID . ':' . $this->appSecret),
'Content-Type: application/x-www-form-urlencoded',
@ -105,7 +105,7 @@ class Yahoo extends OAuth2
*
* @return array
*/
public function refreshTokens(string $refreshToken):array
public function refreshTokens(string $refreshToken): array
{
$headers = [
'Authorization: Basic ' . \base64_encode($this->appID . ':' . $this->appSecret),
@ -122,7 +122,7 @@ class Yahoo extends OAuth2
])
), true);
if(empty($this->tokens['refresh_token'])) {
if (empty($this->tokens['refresh_token'])) {
$this->tokens['refresh_token'] = $refreshToken;
}
@ -130,35 +130,27 @@ class Yahoo extends OAuth2
}
/**
* @param $accessToken
* @param string $accessToken
*
* @return string
*/
public function getUserID(string $accessToken):string
public function getUserID(string $accessToken): string
{
$user = $this->getUser($accessToken);
if (isset($user['sub'])) {
return $user['sub'];
}
return '';
return $user['sub'] ?? '';
}
/**
* @param $accessToken
* @param string $accessToken
*
* @return string
*/
public function getUserEmail(string $accessToken):string
public function getUserEmail(string $accessToken): string
{
$user = $this->getUser($accessToken);
if (isset($user['email'])) {
return $user['email'];
}
return '';
return $user['email'] ?? '';
}
/**
@ -166,7 +158,7 @@ class Yahoo extends OAuth2
*
* If present, the email is verified. This was verfied through a manual Yahoo sign up process
*
* @param $accessToken
* @param string $accessToken
*
* @return bool
*/
@ -178,19 +170,15 @@ class Yahoo extends OAuth2
}
/**
* @param $accessToken
* @param string $accessToken
*
* @return string
*/
public function getUserName(string $accessToken):string
public function getUserName(string $accessToken): string
{
$user = $this->getUser($accessToken);
if (isset($user['name'])) {
return $user['name'];
}
return '';
return $user['name'] ?? '';
}
/**
@ -204,7 +192,7 @@ class Yahoo extends OAuth2
$this->user = \json_decode($this->request(
'GET',
$this->resourceEndpoint,
['Authorization: Bearer '.\urlencode($accessToken)]
['Authorization: Bearer ' . \urlencode($accessToken)]
), true);
}

View file

@ -12,17 +12,17 @@ class Yammer extends OAuth2
/**
* @var string
*/
private $endpoint = 'https://www.yammer.com/oauth2/';
private string $endpoint = 'https://www.yammer.com/oauth2/';
/**
* @var array
*/
protected $user = [];
protected array $user = [];
/**
* @var array
*/
protected $tokens = [];
protected array $tokens = [];
/**
* @return string
@ -37,13 +37,13 @@ class Yammer extends OAuth2
*/
public function getLoginURL(): string
{
return $this->endpoint . 'oauth2/authorize?'.
\http_build_query([
'client_id' => $this->appID,
'response_type' => 'code',
'redirect_uri' => $this->callback,
'state' => \json_encode($this->state)
]);
return $this->endpoint . 'oauth2/authorize?' .
\http_build_query([
'client_id' => $this->appID,
'response_type' => 'code',
'redirect_uri' => $this->callback,
'state' => \json_encode($this->state)
]);
}
/**
@ -53,7 +53,7 @@ class Yammer extends OAuth2
*/
protected function getTokens(string $code): array
{
if(empty($this->tokens)) {
if (empty($this->tokens)) {
$headers = ['Content-Type: application/x-www-form-urlencoded'];
$this->tokens = \json_decode($this->request(
'POST',
@ -76,7 +76,7 @@ class Yammer extends OAuth2
*
* @return array
*/
public function refreshTokens(string $refreshToken):array
public function refreshTokens(string $refreshToken): array
{
$headers = ['Content-Type: application/x-www-form-urlencoded'];
$this->tokens = \json_decode($this->request(
@ -91,7 +91,7 @@ class Yammer extends OAuth2
])
), true);
if(empty($this->tokens['refresh_token'])) {
if (empty($this->tokens['refresh_token'])) {
$this->tokens['refresh_token'] = $refreshToken;
}
@ -107,11 +107,7 @@ class Yammer extends OAuth2
{
$user = $this->getUser($accessToken);
if (isset($user['id'])) {
return $user['id'];
}
return '';
return $user['id'] ?? '';
}
/**
@ -123,11 +119,7 @@ class Yammer extends OAuth2
{
$user = $this->getUser($accessToken);
if (isset($user['email'])) {
return $user['email'];
}
return '';
return $user['email'] ?? '';
}
/**
@ -135,7 +127,7 @@ class Yammer extends OAuth2
*
* If present, the email is verified. This was verfied through a manual Yammer sign up process
*
* @param $accessToken
* @param string $accessToken
*
* @return bool
*/
@ -155,11 +147,7 @@ class Yammer extends OAuth2
{
$user = $this->getUser($accessToken);
if (isset($user['full_name'])) {
return $user['full_name'];
}
return '';
return $user['full_name'] ?? '';
}
/**
@ -170,7 +158,7 @@ class Yammer extends OAuth2
protected function getUser(string $accessToken): array
{
if (empty($this->user)) {
$headers = ['Authorization: Bearer '. \urlencode($accessToken)];
$headers = ['Authorization: Bearer ' . \urlencode($accessToken)];
$user = $this->request('GET', 'https://www.yammer.com/api/v1/users/current.json', $headers);
$this->user = \json_decode($user, true);
}

View file

@ -14,17 +14,17 @@ class Yandex extends OAuth2
/**
* @var array
*/
protected $user = [];
/**
* @var array
*/
protected $tokens = [];
protected array $user = [];
/**
* @var array
*/
protected $scopes = [];
protected array $tokens = [];
/**
* @var array
*/
protected array $scopes = [];
/**
* @return string
@ -35,7 +35,7 @@ class Yandex extends OAuth2
}
/**
* @param $state
* @param string $state
*
* @return array
*/
@ -50,12 +50,12 @@ class Yandex extends OAuth2
*/
public function getLoginURL(): string
{
return 'https://oauth.yandex.com/authorize?'.\http_build_query([
'response_type' => 'code',
'client_id' => $this->appID,
'scope'=> \implode(' ', $this->getScopes()),
'state' => \json_encode($this->state)
]);
return 'https://oauth.yandex.com/authorize?' . \http_build_query([
'response_type' => 'code',
'client_id' => $this->appID,
'scope' => \implode(' ', $this->getScopes()),
'state' => \json_encode($this->state)
]);
}
/**
@ -65,7 +65,7 @@ class Yandex extends OAuth2
*/
protected function getTokens(string $code): array
{
if(empty($this->tokens)) {
if (empty($this->tokens)) {
$headers = [
'Authorization: Basic ' . \base64_encode($this->appID . ':' . $this->appSecret),
'Content-Type: application/x-www-form-urlencoded',
@ -89,7 +89,7 @@ class Yandex extends OAuth2
*
* @return array
*/
public function refreshTokens(string $refreshToken):array
public function refreshTokens(string $refreshToken): array
{
$headers = [
'Authorization: Basic ' . \base64_encode($this->appID . ':' . $this->appSecret),
@ -105,7 +105,7 @@ class Yandex extends OAuth2
])
), true);
if(empty($this->tokens['refresh_token'])) {
if (empty($this->tokens['refresh_token'])) {
$this->tokens['refresh_token'] = $refreshToken;
}
@ -121,11 +121,7 @@ class Yandex extends OAuth2
{
$user = $this->getUser($accessToken);
if (isset($user['id'])) {
return $user['id'];
}
return '';
return $user['id'] ?? '';
}
/**
@ -137,17 +133,13 @@ class Yandex extends OAuth2
{
$user = $this->getUser($accessToken);
if (isset($user['default_email'])) {
return $user['default_email'];
}
return '';
return $user['default_email'] ?? '';
}
/**
* Check if the OAuth email is verified
*
* @param $accessToken
* @param string $accessToken
*
* @return bool
*/
@ -165,11 +157,7 @@ class Yandex extends OAuth2
{
$user = $this->getUser($accessToken);
if (isset($user['display_name'])) {
return $user['display_name'];
}
return '';
return $user['display_name'] ?? '';
}
/**
@ -180,7 +168,7 @@ class Yandex extends OAuth2
protected function getUser(string $accessToken): array
{
if (empty($this->user)) {
$user = $this->request('GET', 'https://login.yandex.ru/info?'.\http_build_query([
$user = $this->request('GET', 'https://login.yandex.ru/info?' . \http_build_query([
'format' => 'json',
'oauth_token' => $accessToken
]));

View file

@ -9,34 +9,34 @@ class Zoom extends OAuth2
/**
* @var string
*/
private $endpoint = 'https://zoom.us';
private string $endpoint = 'https://zoom.us';
/**
* @var string
*/
private $version = '2022-03-26';
private string $version = '2022-03-26';
/**
* @var array
*/
protected $user = [];
/**
* @var array
*/
protected $tokens = [];
protected array $user = [];
/**
* @var array
*/
protected $scopes = [
protected array $tokens = [];
/**
* @var array
*/
protected array $scopes = [
'user_profile'
];
/**
* @return string
*/
public function getName():string
public function getName(): string
{
return 'zoom';
}
@ -44,9 +44,9 @@ class Zoom extends OAuth2
/**
* @return string
*/
public function getLoginURL():string
public function getLoginURL(): string
{
return $this->endpoint . '/oauth/authorize?'. \http_build_query([
return $this->endpoint . '/oauth/authorize?' . \http_build_query([
'client_id' => $this->appID,
'redirect_uri' => $this->callback,
'response_type' => 'code',
@ -62,7 +62,7 @@ class Zoom extends OAuth2
*/
protected function getTokens(string $code): array
{
if(empty($this->tokens)) {
if (empty($this->tokens)) {
$headers = ['Authorization: Basic ' . \base64_encode($this->appID . ':' . $this->appSecret), 'Content-Type: application/x-www-form-urlencoded'];
$this->tokens = \json_decode($this->request(
'POST',
@ -84,7 +84,7 @@ class Zoom extends OAuth2
*
* @return array
*/
public function refreshTokens(string $refreshToken):array
public function refreshTokens(string $refreshToken): array
{
$headers = ['Authorization: Basic ' . \base64_encode($this->appID . ':' . $this->appSecret), 'Content-Type: application/x-www-form-urlencoded'];
$this->tokens = \json_decode($this->request(
@ -97,7 +97,7 @@ class Zoom extends OAuth2
])
), true);
if(empty($this->tokens['refresh_token'])) {
if (empty($this->tokens['refresh_token'])) {
$this->tokens['refresh_token'] = $refreshToken;
}
@ -105,24 +105,26 @@ class Zoom extends OAuth2
}
/**
* @param $accessToken
* @param string $accessToken
*
* @return string
*/
public function getUserID(string $accessToken):string
public function getUserID(string $accessToken): string
{
$response = $this->getUser($accessToken);
return $response['id'] ?? '';
}
/**
* @param $accessToken
* @param string $accessToken
*
* @return string
*/
public function getUserEmail(string $accessToken):string
public function getUserEmail(string $accessToken): string
{
$response = $this->getUser($accessToken);
return $response['email'] ?? '';
}
@ -131,7 +133,7 @@ class Zoom extends OAuth2
*
* @link https://marketplace.zoom.us/docs/api-reference/zoom-api/methods/#operation/user
*
* @param $accessToken
* @param string $accessToken
*
* @return bool
*/
@ -139,21 +141,22 @@ class Zoom extends OAuth2
{
$user = $this->getUser($accessToken);
if (isset($user['verified']) && $user['verified'] === 1) {
if (($user['verified'] ?? false) === 1) {
return true;
}
return false;
}
/**
* @param $accessToken
* @param string $accessToken
*
* @return string
*/
public function getUserName(string $accessToken):string
public function getUserName(string $accessToken): string
{
$response = $this->getUser($accessToken);
return ($response['first_name'] ?? '') . ' ' . ($response['last_name'] ?? '');
}
@ -165,7 +168,7 @@ class Zoom extends OAuth2
protected function getUser(string $accessToken)
{
$headers = [
'Authorization: Bearer '.\urlencode($accessToken)
'Authorization: Bearer ' . \urlencode($accessToken)
];
if (empty($this->user)) {