Файловый менеджер - Редактировать - /home/wuectly/www/03cbe/Oauth2.tar
Назад
BoxEngine.php 0000604 00000001460 15245534242 0007136 0 ustar 00 <?php /** * @package akeebabackup * @copyright Copyright (c)2006-2023 Nicholas K. Dionysopoulos / Akeeba Ltd * @license GNU General Public License version 3, or later */ namespace Akeeba\Backup\Site\Model\Oauth2; defined('_JEXEC') || die; class BoxEngine extends AbstractProvider implements ProviderInterface { /** @var string */ protected $tokenEndpoint = 'https://api.box.com/oauth2/token'; /** @var string */ protected $engineNameForHumans = 'Box.com'; public function getAuthenticationUrl(): string { $this->checkConfiguration(); [$id, $secret] = $this->getIdAndSecret(); $params = [ 'response_type' => 'code', 'client_id' => $id, 'redirect_uri' => $this->getUri('step2'), ]; return 'https://account.box.com/api/oauth2/authorize?' . http_build_query($params); } } DropboxEngine.php 0000604 00000003027 15245534242 0010024 0 ustar 00 <?php /** * @package akeebabackup * @copyright Copyright (c)2006-2023 Nicholas K. Dionysopoulos / Akeeba Ltd * @license GNU General Public License version 3, or later */ namespace Akeeba\Backup\Site\Model\Oauth2; defined('_JEXEC') || die; use FOF40\Input\Input; class DropboxEngine extends AbstractProvider implements ProviderInterface { /** @var string */ protected $tokenEndpoint = 'https://api.dropboxapi.com/1/oauth2/token'; /** @var string */ protected $engineNameForHumans = 'Dropbox'; public function getAuthenticationUrl(): string { $this->checkConfiguration(); [$id, $secret] = $this->getIdAndSecret(); $params = [ 'client_id' => $id, 'response_type' => 'code', 'redirect_uri' => $this->getUri('step2'), 'scope' => implode( ' ', [ 'account_info.read', 'files.metadata.read', 'files.content.write', 'files.content.read', 'team_data.member', ] ), 'token_access_type' => 'offline', ]; return 'https://www.dropbox.com/1/oauth2/authorize?' . http_build_query($params); } protected function getResponseCustomFields(Input $input): array { $fields = parent::getResponseCustomFields($input); unset($fields['client_id']); unset($fields['client_secret']); $fields['redirect_uri'] = $this->getUri('step2'); return $fields; } protected function getRefreshCustomFields(Input $input): array { $fields = parent::getRefreshCustomFields($input); unset($fields['client_id']); unset($fields['client_secret']); return $fields; } } ProviderInterface.php 0000604 00000002137 15245534242 0010675 0 ustar 00 <?php /** * @package akeebabackup * @copyright Copyright (c)2006-2023 Nicholas K. Dionysopoulos / Akeeba Ltd * @license GNU General Public License version 3, or later */ namespace Akeeba\Backup\Site\Model\Oauth2; defined('_JEXEC') || die; use FOF40\Input\Input; /** * OAuth2 Helper provider interface * * @since 8.2.2 */ interface ProviderInterface { /** * Get the URL to redirect to for the first authentication step (consent screen). * * @return string * @since 8.4.0 */ public function getAuthenticationUrl(): string; /** * Handles the second step of the authentication (exchange code for tokens) * * @param Input $input The raw application input object * * @return TokenResponse * @since 8.4.0 */ public function handleResponse(Input $input): TokenResponse; /** * Handles exchanging a refresh token for an access token * * @param Input $input The raw application input object * * @return TokenResponse * @since 8.4.0 */ public function handleRefresh(Input $input): TokenResponse; public function getEngineNameForHumans(): string; } OAuth2UriException.php 0000604 00000001330 15245534242 0010715 0 ustar 00 <?php /** * @package akeebabackup * @copyright Copyright (c)2006-2023 Nicholas K. Dionysopoulos / Akeeba Ltd * @license GNU General Public License version 3, or later */ namespace Akeeba\Backup\Site\Model\Oauth2; defined('_JEXEC') || die; use RuntimeException; use Throwable; /** * OAuth2 Helper error redirecting to a URL * * @since 8.4.0 */ class OAuth2UriException extends RuntimeException { /** @var string */ private $url; public function __construct(string $url, Throwable $previous = null) { $message = sprintf('For more information please visit %s', $url); $this->url = $url; parent::__construct($message, 500, $previous); } public function getUrl(): string { return $this->url; } } OnedrivebusinessEngine.php 0000604 00000002756 15245534242 0011746 0 ustar 00 <?php /** * @package akeebabackup * @copyright Copyright (c)2006-2023 Nicholas K. Dionysopoulos / Akeeba Ltd * @license GNU General Public License version 3, or later */ namespace Akeeba\Backup\Site\Model\Oauth2; defined('_JEXEC') || die; use FOF40\Input\Input; class OnedrivebusinessEngine extends AbstractProvider implements ProviderInterface { /** @var string */ protected $tokenEndpoint = 'https://login.microsoftonline.com/common/oauth2/v2.0/token'; /** @var string */ protected $engineNameForHumans = 'OneDrive'; public function getAuthenticationUrl(): string { $this->checkConfiguration(); [$id, $secret] = $this->getIdAndSecret(); $params = [ 'client_id' => $id, 'response_type' => 'code', 'redirect_uri' => $this->getUri('step2'), 'response_mode' => 'query', 'scope' => implode( ' ', [ 'files.readwrite.all', 'user.read', 'offline_access', ] ), ]; return 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize?' . http_build_query($params); } protected function getResponseCustomFields(Input $input): array { return array_merge( parent::getResponseCustomFields($input), [ 'scope' => 'files.readwrite.all user.read offline_access', 'redirect_uri' => $this->getUri('step2'), ] ); } protected function getRefreshCustomFields(Input $input): array { return array_merge( parent::getRefreshCustomFields($input), [ 'redirect_uri' => $this->getUri('step2'), ] ); } } AbstractProvider.php 0000604 00000015165 15245534242 0010545 0 ustar 00 <?php /** * @package akeebabackup * @copyright Copyright (c)2006-2023 Nicholas K. Dionysopoulos / Akeeba Ltd * @license GNU General Public License version 3, or later */ namespace Akeeba\Backup\Site\Model\Oauth2; defined('_JEXEC') || die; use FOF40\Input\Input; use Joomla\CMS\Component\ComponentHelper; use Joomla\CMS\Factory; use Joomla\CMS\Language\Text; use Joomla\CMS\Uri\Uri; abstract class AbstractProvider implements ProviderInterface { /** @var string */ protected $tokenEndpoint = ''; /** @var string */ protected $engineNameForHumans = ''; public function doRedirect(string $uri) { Factory::getApplication()->redirect($uri); } public function getEngineNameForHumans(): string { return $this->engineNameForHumans; } public final function handleResponse(Input $input): TokenResponse { $this->checkConfiguration(); $code = $input->getRaw('code'); if (!$code) { throw new OAuth2Exception('no_code', 'No code has been provided in the URL.'); } $query = http_build_query($this->getResponseCustomFields($input), '', '&'); $ch = curl_init($this->tokenEndpoint); $options = [ CURLOPT_SSL_VERIFYPEER => true, CURLOPT_VERBOSE => true, CURLOPT_HEADER => false, CURLINFO_HEADER_OUT => false, CURLOPT_RETURNTRANSFER => true, CURLOPT_CAINFO => AKEEBA_CACERT_PEM, CURLOPT_FOLLOWLOCATION => true, CURLOPT_POST => 1, CURLOPT_POSTFIELDS => $query, CURLOPT_HTTPHEADER => [ 'Content-Type: application/x-www-form-urlencoded', ], ]; curl_setopt_array($ch, $options); // Get the tokens $response = curl_exec($ch); $errNo = curl_errno($ch); $error = curl_error($ch); curl_close($ch); // Did cURL die? if ($errNo) { throw new OAuth2Exception( 'curl_error', <<< HTML An error occurred communicating with $this->engineNameForHumans. Technical information:<br/><br/> Error Number: $errNo<br/> Error Description: $error<br/> HTML ); } // Decode the response $result = @json_decode($response, true); // Did we receive invalid JSON? if (!$result) { throw new OAuth2Exception( 'invalid_json', sprintf("%s failed to response with a valid token. Please try again later.", $this->engineNameForHumans) ); } // Do we have an error reported by the remote endpoint? if (isset($result['error'])) { $error = $result['error']; $errorUri = $result['error_uri'] ?? null; $errorDescription = $result['error_uri'] ?? null; if ($errorUri) { throw new OAuth2UriException($errorUri); } throw new OAuth2Exception($error, $errorDescription); } $ret = new TokenResponse(); $ret['accessToken'] = $result['access_token'] ?? ''; $ret['refreshToken'] = $result['refresh_token'] ?? ''; return $ret; } public final function handleRefresh(Input $input): TokenResponse { $refreshToken = $input->getRaw('refresh_token', null); $this->checkConfiguration(); if (empty($refreshToken)) { throw new OAuth2Exception( 'no_refresh_token', 'A refresh token was not provided. Operation aborted.' ); } // Prepare the request to get the tokens $query = http_build_query($this->getRefreshCustomFields($input), '', '&'); $ch = curl_init($this->tokenEndpoint); $options = [ CURLOPT_SSL_VERIFYPEER => true, CURLOPT_VERBOSE => true, CURLOPT_HEADER => false, CURLINFO_HEADER_OUT => false, CURLOPT_RETURNTRANSFER => true, CURLOPT_CAINFO => AKEEBA_CACERT_PEM, CURLOPT_FOLLOWLOCATION => true, CURLOPT_POST => 1, CURLOPT_POSTFIELDS => $query, CURLOPT_HTTPHEADER => [ 'Content-Type: application/x-www-form-urlencoded', ], ]; curl_setopt_array($ch, $options); // Get the tokens $response = curl_exec($ch); $errNo = curl_errno($ch); $error = curl_error($ch); curl_close($ch); // Did cURL die? if ($errNo) { throw new OAuth2Exception( 'curl_error', sprintf( "An error occurred refreshing the token. Error Number: %s -- Error Description: %s", $errNo, $error ) ); } // Decode the response $result = @json_decode($response, true); // Did we receive invalid JSON? if (!$result) { throw new OAuth2Exception( 'invalid_json', sprintf( "%s failed to respond with a valid token to our token refresh request.", $this->engineNameForHumans ) ); } $ret = new TokenResponse(); $ret['accessToken'] = $result['access_token'] ?? ''; $ret['refreshToken'] = $result['refresh_token'] ?? ''; return $ret; } protected function getResponseCustomFields(Input $input): array { [$id, $secret] = $this->getIdAndSecret(); $code = $input->getRaw('code'); return [ 'code' => $code, 'client_id' => $id, 'client_secret' => $secret, 'grant_type' => 'authorization_code', ]; } protected function getRefreshCustomFields(Input $input): array { $refreshToken = $input->getRaw('refresh_token', null); [$id, $secret] = $this->getIdAndSecret(); return [ 'refresh_token' => $refreshToken, 'client_id' => $id, 'client_secret' => $secret, 'grant_type' => 'refresh_token', ]; } protected final function getEngineName(): string { $parts = explode('\\', rtrim(get_class($this), '\\')); $name = array_pop($parts); if (substr($name, -6) === 'Engine') { $name = substr($name, 0, -6); } return strtolower($name); } protected final function checkConfiguration(): void { $engine = $this->getEngineName(); // Is the engine enabled? $cParams = ComponentHelper::getParams('com_akeeba'); if ($cParams->get('oauth2_client_' . $engine, 0) == 0) { throw new OAuth2Exception('no_access', Text::_('JERROR_ALERTNOAUTHOR')); } $id = $cParams->get($engine . '_client_id', null); $secret = $cParams->get($engine . '_client_secret', null); if (empty($id) || empty($secret)) { throw new OAuth2Exception('no_access', Text::_('JERROR_ALERTNOAUTHOR')); } } protected final function getIdAndSecret(): array { $cParams = ComponentHelper::getParams('com_akeeba'); $engine = $this->getEngineName(); $id = $cParams->get($engine . '_client_id', null); $secret = $cParams->get($engine . '_client_secret', null); return [$id, $secret]; } protected final function getUri(string $task = 'step1') { $uri = rtrim(Uri::base(), '/'); if (substr($uri, -14) === '/administrator') { $uri = substr($uri, 0, -14); } elseif (substr($uri, -4) === '/administrator') { $uri = substr($uri, 0, -4); } return sprintf( "%s/index.php?option=com_akeeba&view=oauth2&task=step2&format=raw&engine=%s", $uri, $this->getEngineName() ); } } TokenResponse.php 0000604 00000002214 15245534242 0010055 0 ustar 00 <?php /** * @package akeebabackup * @copyright Copyright (c)2006-2023 Nicholas K. Dionysopoulos / Akeeba Ltd * @license GNU General Public License version 3, or later */ namespace Akeeba\Backup\Site\Model\Oauth2; defined('_JEXEC') || die; class TokenResponse implements \ArrayAccess { /** @var string|null */ private $accessToken = null; /** @var string|null */ private $refreshToken = null; /** @inheritDoc */ public function offsetExists($offset) { return isset($this->{$offset}); } /** @inheritDoc */ public function offsetGet($offset) { return $this->{$offset} ?? null; } /** @inheritDoc */ public function offsetSet($offset, $value) { if ($this->offsetExists($offset)) { return; } $this->{$offset} = $value; } /** @inheritDoc */ public function offsetUnset($offset) { throw new \BadMethodCallException( sprintf( 'You cannot unset an offset in %s', __CLASS__ ) ); } /** * Casts the data into a plain array * * @return array * @since 8.4.0 */ public function toArray() { return [ 'accessToken' => $this->accessToken, 'refreshToken' => $this->refreshToken, ]; } } GoogledriveEngine.php 0000604 00000002247 15245534242 0010660 0 ustar 00 <?php /** * @package akeebabackup * @copyright Copyright (c)2006-2023 Nicholas K. Dionysopoulos / Akeeba Ltd * @license GNU General Public License version 3, or later */ namespace Akeeba\Backup\Site\Model\Oauth2; defined('_JEXEC') || die; use FOF40\Input\Input; class GoogledriveEngine extends AbstractProvider implements ProviderInterface { /** @var string */ protected $tokenEndpoint = 'https://www.googleapis.com/oauth2/v4/token'; /** @var string */ protected $engineNameForHumans = 'Google Drive'; public function getAuthenticationUrl(): string { $this->checkConfiguration(); [$id, $secret] = $this->getIdAndSecret(); $params = [ 'client_id' => $id, 'redirect_uri' => $this->getUri('step2'), 'scope' => 'https://www.googleapis.com/auth/drive', 'access_type' => 'offline', 'prompt' => 'consent', 'response_type' => 'code', ]; return 'https://accounts.google.com/o/oauth2/v2/auth?' . http_build_query($params); } protected function getResponseCustomFields(Input $input): array { return array_merge( parent::getResponseCustomFields($input), [ 'redirect_uri' => $this->getUri('step2'), ] ); } } OAuth2Exception.php 0000604 00000004156 15245534242 0010246 0 ustar 00 <?php /** * @package akeebabackup * @copyright Copyright (c)2006-2023 Nicholas K. Dionysopoulos / Akeeba Ltd * @license GNU General Public License version 3, or later */ namespace Akeeba\Backup\Site\Model\Oauth2; defined('_JEXEC') || die; use RuntimeException; use Throwable; /** * Generic OAuth2 Helper error * * @since 8.4.0 */ class OAuth2Exception extends RuntimeException { public function __construct(string $error, ?string $description = "", Throwable $previous = null) { $description = $description ?: $this->getDefaultErrorDescription($error); $message = sprintf('%s: %s', $error, $description); parent::__construct($message, 500, $previous); } private function getDefaultErrorDescription(string $error): string { switch ($error) { case 'invalid_request': return 'The request sent to the storage provider is invalid. Please check your Client ID and Client Secret in Akeeba Backup\'s configuration. Also, make sure the callback URI is set up correctly on the remote storage provider. If necessary, relink Akeeba Backup with the remote storage provider'; case 'invalid_client': return 'The configured Client ID is incorrect.'; case 'invalid_grant': return 'The grant type is invalid, the code has already been used (you tried to refresh the page), you failed to log into the remote storage provider, or declined to give authorisation.'; case 'unauthorized_client': return 'Your account with the remote storage provider is not allowed to be linked with your API application. Please check your API application configuration with the remote storage provider.'; case 'unsupported_grant_type': return 'The grant type requested is not supported by the remote storage provider. Please check your API application configuration with the remote storage provider.'; case 'invalid_scope': return 'The authentication scope requested is not supported by the remote storage provider. Please check your API application configuration with the remote storage provider.'; default: return 'A generic error occurred, which we do not have any further information for.'; } } }
| ver. 1.4 |
Github
|
.
| PHP 8.1.34 | Генерация страницы: 0 |
proxy
|
phpinfo
|
Настройка