This commit is contained in:
2025-10-20 14:10:54 +02:00
parent 75ca8fd840
commit d2c1970ef8
732 changed files with 101915 additions and 2 deletions

View File

@@ -0,0 +1,44 @@
<?php
namespace Pshowsso\Scope68f5e85e9608b\League\OAuth2\Client\Provider\Exception;
use Pshowsso\Scope68f5e85e9608b\Psr\Http\Message\ResponseInterface;
class GithubIdentityProviderException extends IdentityProviderException
{
/**
* Creates client exception from response.
*
* @param ResponseInterface $response
* @param string $data Parsed response data
*
* @return IdentityProviderException
*/
public static function clientException(ResponseInterface $response, $data)
{
return static::fromResponse($response, isset($data['message']) ? $data['message'] : $response->getReasonPhrase());
}
/**
* Creates oauth exception from response.
*
* @param ResponseInterface $response
* @param string $data Parsed response data
*
* @return IdentityProviderException
*/
public static function oauthException(ResponseInterface $response, $data)
{
return static::fromResponse($response, isset($data['error']) ? $data['error'] : $response->getReasonPhrase());
}
/**
* Creates identity exception from response.
*
* @param ResponseInterface $response
* @param string $message
*
* @return IdentityProviderException
*/
protected static function fromResponse(ResponseInterface $response, $message = null)
{
return new static($message, $response->getStatusCode(), (string) $response->getBody());
}
}

View File

@@ -0,0 +1,100 @@
<?php
namespace Pshowsso\Scope68f5e85e9608b\League\OAuth2\Client\Provider;
use Pshowsso\Scope68f5e85e9608b\League\OAuth2\Client\Provider\Exception\GithubIdentityProviderException;
use Pshowsso\Scope68f5e85e9608b\League\OAuth2\Client\Token\AccessToken;
use Pshowsso\Scope68f5e85e9608b\League\OAuth2\Client\Tool\BearerAuthorizationTrait;
use Pshowsso\Scope68f5e85e9608b\Psr\Http\Message\ResponseInterface;
class Github extends AbstractProvider
{
use BearerAuthorizationTrait;
/**
* Domain
*
* @var string
*/
public $domain = 'https://github.com';
/**
* Api domain
*
* @var string
*/
public $apiDomain = 'https://api.github.com';
/**
* Get authorization url to begin OAuth flow
*
* @return string
*/
public function getBaseAuthorizationUrl()
{
return $this->domain . '/login/oauth/authorize';
}
/**
* Get access token url to retrieve token
*
* @param array $params
*
* @return string
*/
public function getBaseAccessTokenUrl(array $params)
{
return $this->domain . '/login/oauth/access_token';
}
/**
* Get provider url to fetch user details
*
* @param AccessToken $token
*
* @return string
*/
public function getResourceOwnerDetailsUrl(AccessToken $token)
{
if ($this->domain === 'https://github.com') {
return $this->apiDomain . '/user';
}
return $this->domain . '/api/v3/user';
}
/**
* Get the default scopes used by this provider.
*
* This should not be a complete list of all scopes, but the minimum
* required for the provider user interface!
*
* @return array
*/
protected function getDefaultScopes()
{
return [];
}
/**
* Check a provider response for errors.
*
* @link https://developer.github.com/v3/#client-errors
* @link https://developer.github.com/v3/oauth/#common-errors-for-the-access-token-request
* @throws IdentityProviderException
* @param ResponseInterface $response
* @param string $data Parsed response data
* @return void
*/
protected function checkResponse(ResponseInterface $response, $data)
{
if ($response->getStatusCode() >= 400) {
throw GithubIdentityProviderException::clientException($response, $data);
} elseif (isset($data['error'])) {
throw GithubIdentityProviderException::oauthException($response, $data);
}
}
/**
* Generate a user object from a successful user details request.
*
* @param array $response
* @param AccessToken $token
* @return League\OAuth2\Client\Provider\ResourceOwnerInterface
*/
protected function createResourceOwner(array $response, AccessToken $token)
{
$user = new GithubResourceOwner($response);
return $user->setDomain($this->domain);
}
}

View File

@@ -0,0 +1,97 @@
<?php
namespace Pshowsso\Scope68f5e85e9608b\League\OAuth2\Client\Provider;
use Pshowsso\Scope68f5e85e9608b\League\OAuth2\Client\Tool\ArrayAccessorTrait;
class GithubResourceOwner implements ResourceOwnerInterface
{
use ArrayAccessorTrait;
/**
* Domain
*
* @var string
*/
protected $domain;
/**
* Raw response
*
* @var array
*/
protected $response;
/**
* Creates new resource owner.
*
* @param array $response
*/
public function __construct(array $response = array())
{
$this->response = $response;
}
/**
* Get resource owner id
*
* @return string|null
*/
public function getId()
{
return $this->getValueByKey($this->response, 'id');
}
/**
* Get resource owner email
*
* @return string|null
*/
public function getEmail()
{
return $this->getValueByKey($this->response, 'email');
}
/**
* Get resource owner name
*
* @return string|null
*/
public function getName()
{
return $this->getValueByKey($this->response, 'name');
}
/**
* Get resource owner nickname
*
* @return string|null
*/
public function getNickname()
{
return $this->getValueByKey($this->response, 'login');
}
/**
* Get resource owner url
*
* @return string|null
*/
public function getUrl()
{
$urlParts = array_filter([$this->domain, $this->getNickname()]);
return count($urlParts) ? implode('/', $urlParts) : null;
}
/**
* Set resource owner domain
*
* @param string $domain
*
* @return ResourceOwner
*/
public function setDomain($domain)
{
$this->domain = $domain;
return $this;
}
/**
* Return all of the owner details available as an array.
*
* @return array
*/
public function toArray()
{
return $this->response;
}
}