<commit_before><?php
/**
 * This file is part of Vegas package
 *
 * @author <NAME> <<EMAIL>>
 * @copyright Amsterdam Standard Sp. Z o.o.
 * @homepage https://bitbucket.org/amsdard/vegas-phalcon
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Vegas\Security\OAuth;

use OAuth\Common\Consumer\Credentials;
use OAuth\Common\Http\Client\CurlClient;
use OAuth\Common\Storage\Exception\TokenNotFoundException;
use OAuth\Common\Storage\TokenStorageInterface;
use Phalcon\DI\InjectionAwareInterface;
use Phalcon\DiInterface;
use Vegas\DI\InjectionAwareTrait;
use Vegas\Security\OAuth\Exception\FailedAuthorizationException;
use Vegas\Security\OAuth\Exception\InvalidApplicationKeyException;
use Vegas\Security\OAuth\Exception\InvalidApplicationSecretKeyException;
use Vegas\Security\OAuth\Exception\ServiceNotInitializedException;

/**
 * Class AdapterAbstract
 * @package Vegas\Security\OAuth
 */
abstract class ServiceAbstract implements InjectionAwareInterface
{
    use InjectionAwareTrait;

    /**
     * URI helper
     *
     * @var \OAuth\Common\Http\Uri\UriInterface
     */
    protected $currentUri;

    /**
     * Session storage instance
     *
     * @var Storage\Session
     */
    protected $sessionStorage;

    /**
     * Provided credentials
     *
     * @var Credentials
     */
    protected $credentials;

    /**
     * List of added provider scope
     *
     * @var array
     */
    protected $scopes = array();

    /**
     * @var \OAuth\Common\Service\ServiceInterface
     */
    protected $service;

    /**
     * Creates URI factory for building urls
     * Setups session storage
     *
     * @param DiInterface $di
     * @param TokenStorageInterface $sessionStorage
     */
    public function __construct(DiInterface $di, TokenStorageInterface $sessionStorage)
    {
        $this->setDI($di);

        $uriFactory = new \OAuth\Common\Http\Uri\UriFactory();
        $this->currentUri = $uriFactory->createFromSuperGlobalArray($_SERVER);
        $this->currentUri->setQuery('');

        $this->sessionStorage = $sessionStorage;
    }

    /**
     * @param TokenStorageInterface $sessionStorage
     * @return $this
     */
    public function setSessionStorage(TokenStorageInterface $sessionStorage)
    {
        $this->sessionStorage = $sessionStorage;

        return $this;
    }

    /**
     * Returns the name of current service
     *
     * @return mixed
     */
    abstract public function getServiceName();

    /**
     * @return mixed
     */
    abstract public function getIdentity();

    /**
     * Authorization process
     *
     * @throws \Vegas\Security\OAuth\Exception\FailedAuthorizationException
     * @return \OAuth\Common\Http\Uri\UriInterface|string
     */<commit_msg>Added retrieving access token and authorization state to ServiceAbstract;<commit_after><?php
/**
 * This file is part of Vegas package
 *
 * @author <NAME> <<EMAIL>>
 * @copyright Amsterdam Standard Sp. Z o.o.
 * @homepage https://bitbucket.org/amsdard/vegas-phalcon
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Vegas\Security\OAuth;

use OAuth\Common\Consumer\Credentials;
use OAuth\Common\Http\Client\CurlClient;
use OAuth\Common\Storage\Exception\TokenNotFoundException;
use OAuth\Common\Storage\TokenStorageInterface;
use Phalcon\DI\InjectionAwareInterface;
use Phalcon\DiInterface;
use Vegas\DI\InjectionAwareTrait;
use Vegas\Security\OAuth\Exception\FailedAuthorizationException;
use Vegas\Security\OAuth\Exception\InvalidApplicationKeyException;
use Vegas\Security\OAuth\Exception\InvalidApplicationSecretKeyException;
use Vegas\Security\OAuth\Exception\ServiceNotInitializedException;

/**
 * Class AdapterAbstract
 * @package Vegas\Security\OAuth
 */
abstract class ServiceAbstract implements InjectionAwareInterface
{
    use InjectionAwareTrait;

    /**
     * URI helper
     *
     * @var \OAuth\Common\Http\Uri\UriInterface
     */
    protected $currentUri;

    /**
     * Session storage instance
     *
     * @var Storage\Session
     */
    protected $sessionStorage;

    /**
     * Provided credentials
     *
     * @var Credentials
     */
    protected $credentials;

    /**
     * List of added provider scope
     *
     * @var array
     */
    protected $scopes = array();

    /**
     * @var \OAuth\Common\Service\ServiceInterface
     */
    protected $service;

    /**
     * Creates URI factory for building urls
     * Setups session storage
     *
     * @param DiInterface $di
     * @param TokenStorageInterface $sessionStorage
     */
    public function __construct(DiInterface $di, TokenStorageInterface $sessionStorage)
    {
        $this->setDI($di);

        $uriFactory = new \OAuth\Common\Http\Uri\UriFactory();
        $this->currentUri = $uriFactory->createFromSuperGlobalArray($_SERVER);
        $this->currentUri->setQuery('');

        $this->sessionStorage = $sessionStorage;
    }

    /**
     * @param TokenStorageInterface $sessionStorage
     * @return $this
     */
    public function setSessionStorage(TokenStorageInterface $sessionStorage)
    {
        $this->sessionStorage = $sessionStorage;

        return $this;
    }

    /**
     * Returns access token for current service
     *
     * @return \OAuth\Common\Token\TokenInterface
     */
    public function getAccessToken()
    {
        return $this->sessionStorage->retrieveAccessToken($this->getServiceName());
    }

    /**
     * Returns authorization state for current service
     *
     * @return string
     */
    public function getAuthorizationState()
    {
        return $this->sessionStorage->retrieveAuthorizationState($this->getServiceName());
    }

    /**
     * Returns the name of current service
     *
     * @return mixed
     */
    abstract public function getServiceName();

    /**
     * @return mixed
     */
    abstract public function getIdentity();

    /**
     * Authorization process
     *
     * @throws \Vegas\Security\OAuth\Exception\FailedAuthorizationException
     * @return \OAuth\Common\Http\Uri\UriInterface|string
     */
{'fraction_non_alphanumeric': 0.1051870884856271, 'fraction_numerical': 0.0, 'mean_word_length': 2.914519170333124, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 29, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7294412', 'n_tokens_mistral': 1723, 'n_tokens_neox': 1698, 'n_words': 380}