Вход Регистрация
Файл: concrete5.7.5.6/concrete/src/Authentication/Type/Community/Service/Community.php
Строк: 124
<?php
namespace ConcreteCoreAuthenticationTypeCommunityService;

use 
OAuthCommonHttpExceptionTokenResponseException;
use 
OAuthCommonHttpUriUri;
use 
OAuthCommonHttpUriUriInterface;
use 
OAuthCommonTokenTokenInterface;
use 
OAuthOAuth2ServiceAbstractService;
use 
OAuthOAuth2TokenStdOAuth2Token;

class 
Community extends AbstractService
{

    
/**
     * Parses the access token response and returns a TokenInterface.
     *
     *
     * @param string $responseBody
     *
     * @return TokenInterface
     *
     * @throws TokenResponseException
     */
    
protected function parseAccessTokenResponse($responseBody)
    {
        
$request Request::getInstance();
        if (
$request->get('error')){
            
$reason $request->get('error_description');
            throw new 
TokenResponseException($reason);
        }

        
$data json_decode($responseBodytrue);

        if (
null === $data || !is_array($data)) {
            throw new 
TokenResponseException('Unable to parse response.');
        } elseif (isset(
$data['error'])) {
            throw new 
TokenResponseException('Error in retrieving token: "' $data['error'] . '"');
        }

        
$token = new StdOAuth2Token();
        
$token->setAccessToken($data['access_token']);
        
$token->setLifetime($data['expires_in']);

        if (isset(
$data['refresh_token'])) {
            
$token->setRefreshToken($data['refresh_token']);
            unset(
$data['refresh_token']);
        }

        unset(
$data['access_token']);
        unset(
$data['expires_in']);

        
$data['state'] = $request->get('state');

        
$token->setExtraParams($data);

        return 
$token;
    }

    
/**
     * Returns the authorization API endpoint.
     *
     * @return UriInterface
     */
    
public function getAuthorizationEndpoint()
    {
        return new 
Uri(Config::get('concrete.urls.concrete5_secure') . '/api/v1/-/authorize');
    }

    
/**
     * Returns the access token API endpoint.
     *
     * @return UriInterface
     */
    
public function getAccessTokenEndpoint()
    {
        return new 
Uri(Config::get('concrete.urls.concrete5_secure') . '/api/v1/-/token');
    }

    protected function 
getAuthorizationMethod()
    {
        return 
self::AUTHORIZATION_METHOD_HEADER_BEARER;
    }

}
Онлайн: 0
Реклама