<commit_before><?php
/**
 * @copyright Copyright (c) 2013-2016 Voodoo Mobile Consulting Group LLC
 * @link      https://voodoo.rocks
 * @license   http://opensource.org/licenses/MIT The MIT License (MIT)
 */
namespace vm\api\components\auth;

use vm\core\ArrayObject;
use yii\filters\auth\AuthMethod;
use yii\helpers\ArrayHelper;
use yii\helpers\Json;
use yii\web\UnauthorizedHttpException;

/**
 * Class TokenAuth
 * @package vm\api\components\auth
 */
class TokenAuth extends AuthMethod
{
    /**
     * @var array
     */
    public $accessTokenPath = ['token', 'hash'];

    /**
     * Authenticates the current user.
     *
     * @param \yii\web\User     $user
     * @param \yii\web\Request  $request
     * @param \yii\web\Response $response
     *
     * @return \yii\web\IdentityInterface the authenticated user identity. If authentication information is not
     *                                    provided, null will be returned.
     * @throws \yii\web\UnauthorizedHttpException if authentication information is provided but is invalid.
     */
    public function authenticate($user, $request, $response)
    {
        $identity = true;
        $json     = new ArrayObject(Json::decode($request->rawBody));

        /** @var ArrayObject $request */
        /** @noinspection PhpUndefinedFieldInspection */
        $request = $json->request;
        if (is_a($request, 'vm\core\ArrayObject')
            && $request->has(ArrayHelper::getValue($this->accessTokenPath, 0))
        ) {
            $token = $request;
            foreach ($this->accessTokenPath as $part) {
                $token = $token->{$part};
            }

            $identity = $user->loginByAccessToken($token);

            if (!$identity) {
                throw new UnauthorizedHttpException('Incorrect or expired token provided');
            }
        } else {
            if (!$user->isGuest) {
                $user->logout();
            }
        }

        return $identity;
    }
}<commit_msg>[!] Fixed authorization by token hash<commit_after><?php
/**
 * @copyright Copyright (c) 2013-2016 Voodoo Mobile Consulting Group LLC
 * @link      https://voodoo.rocks
 * @license   http://opensource.org/licenses/MIT The MIT License (MIT)
 */
namespace vm\api\components\auth;

use vm\core\ArrayObject;
use yii\filters\auth\AuthMethod;
use yii\helpers\ArrayHelper;
use yii\helpers\Json;
use yii\web\UnauthorizedHttpException;

/**
 * Class TokenAuth
 * @package vm\api\components\auth
 */
class TokenAuth extends AuthMethod
{
    /**
     * @var array
     */
    public $accessTokenPath = ['token', 'hash'];

    /**
     * Authenticates the current user.
     *
     * @param \yii\web\User     $user
     * @param \yii\web\Request  $request
     * @param \yii\web\Response $response
     *
     * @return \yii\web\IdentityInterface the authenticated user identity. If authentication information is not
     *                                    provided, null will be returned.
     * @throws \yii\web\UnauthorizedHttpException if authentication information is provided but is invalid.
     */
    public function authenticate($user, $request, $response)
    {
        $identity = true;

        /** @var ArrayObject $request */
        /** @noinspection PhpUndefinedFieldInspection */
        $request     = new ArrayObject(Json::decode($request->rawBody));

        if (is_a($request, 'vm\core\ArrayObject')
            && $request->has(ArrayHelper::getValue($this->accessTokenPath, 0))
        ) {
            $token = $request;
            foreach ($this->accessTokenPath as $part) {
                $token = $token->{$part};
            }

            $identity = $user->loginByAccessToken($token);

            if (!$identity) {
                throw new UnauthorizedHttpException('Incorrect or expired token provided');
            }
        } else {
            if (!$user->isGuest) {
                $user->logout();
            }
        }

        return $identity;
    }
}
{'fraction_non_alphanumeric': 0.12591103292284495, 'fraction_numerical': 0.004523749685850716, 'mean_word_length': 2.1612390786338365, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 20, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6939602', 'n_tokens_mistral': 1145, 'n_tokens_neox': 1107, 'n_words': 263}