<commit_before><?php

namespace WWON\JwtGuard;

use Carbon\Carbon;
use Illuminate\Support\Facades\Config;
use WWON\JwtGuard\Exceptions\InaccessibleException;
use WWON\JwtGuard\Exceptions\MalformedException;
use WWON\JwtGuard\Exceptions\TokenExpiredException;

class Claim
{

    /**
     * subject
     *
     * @var mixed
     */
    public $sub;

    /**
     * issuer
     *
     * @var string
     */
    public $iss;

    /**
     * audience
     *
     * @var string
     */
    public $aud;

    /**
     * issued at
     *
     * @var int
     */
    public $iat;

    /**
     * expiration time
     *
     * @var int
     */
    public $exp;

    /**
     * not before
     *
     * @var int
     */
    public $nbf;

    /**
     * not after
     *
     * @var int
     */
    public $nat;

    /**
     * JWT identity
     *
     * @var string
     */
    public $jti;

    /**
     * leeway for using in comparing time
     *
     * @var int
     */
    public $leeway;

    /**
     * refreshable - whether the token can be refreshed
     *
     * @var bool
     */
    public $refresh = false;

    /**
     * timestamp when this object is instantiate
     *
     * @var int
     */
    protected $now;

    /**
     * Claim constructor
     *
     * @param array $data
     * @throws InaccessibleException
     * @throws MalformedException
     * @throws TokenExpiredException
     */
    public function __construct(array $data = [])
    {
        $data = $this->getDataMergedWithDefault($data);

        foreach ($data as $key => $value) {
            $attribute = camel_case($key);

            if (property_exists($this, $attribute)) {
                $this->{$attribute} = $value;
            }
        }

        $this->generateJti();

        $this->leeway = Config::get('jwt.leeway');

        $this->validate();
    }

    /**
     * getDataMergedWithDefault method
     *
     * @param array $data
     * @return array
     */
    protected function getDataMergedWithDefault(array $data = [])
    {
        $this->now = Carbon::now()->timestamp;
        $ttl = $this->refresh || !empty($data['refresh'])
            ? Config::get('jwt.refresh_ttl')
            : Config::get('jwt.ttl');

        $data = array_merge([
            'iss' => Config::get('app.url'),
            'iat' => $this->now,
            'exp' => intval($this->now + ($ttl * 60)),
            'nat' => intval($this->now + (Config::get('jwt.ttl') * 60))
        ], $data);

        return $data;
    }

    /**
     * generateJti method
     */
    protected function generateJti()
    {
        if (empty($this->jti)) {
            $this->jti = md5("{$this->sub}.{$this->iat}." . rand(1000, 1999));
        }
    }<commit_msg>Add audience to be part of JTI<commit_after><?php

namespace WWON\JwtGuard;

use Carbon\Carbon;
use Illuminate\Support\Facades\Config;
use WWON\JwtGuard\Exceptions\InaccessibleException;
use WWON\JwtGuard\Exceptions\MalformedException;
use WWON\JwtGuard\Exceptions\TokenExpiredException;

class Claim
{

    /**
     * subject
     *
     * @var mixed
     */
    public $sub;

    /**
     * issuer
     *
     * @var string
     */
    public $iss;

    /**
     * audience
     *
     * @var string
     */
    public $aud;

    /**
     * issued at
     *
     * @var int
     */
    public $iat;

    /**
     * expiration time
     *
     * @var int
     */
    public $exp;

    /**
     * not before
     *
     * @var int
     */
    public $nbf;

    /**
     * not after
     *
     * @var int
     */
    public $nat;

    /**
     * JWT identity
     *
     * @var string
     */
    public $jti;

    /**
     * leeway for using in comparing time
     *
     * @var int
     */
    public $leeway;

    /**
     * refreshable - whether the token can be refreshed
     *
     * @var bool
     */
    public $refresh = false;

    /**
     * timestamp when this object is instantiate
     *
     * @var int
     */
    protected $now;

    /**
     * Claim constructor
     *
     * @param array $data
     * @throws InaccessibleException
     * @throws MalformedException
     * @throws TokenExpiredException
     */
    public function __construct(array $data = [])
    {
        $data = $this->getDataMergedWithDefault($data);

        foreach ($data as $key => $value) {
            $attribute = camel_case($key);

            if (property_exists($this, $attribute)) {
                $this->{$attribute} = $value;
            }
        }

        $this->generateJti();

        $this->leeway = Config::get('jwt.leeway');

        $this->validate();
    }

    /**
     * getDataMergedWithDefault method
     *
     * @param array $data
     * @return array
     */
    protected function getDataMergedWithDefault(array $data = [])
    {
        $this->now = Carbon::now()->timestamp;
        $ttl = $this->refresh || !empty($data['refresh'])
            ? Config::get('jwt.refresh_ttl')
            : Config::get('jwt.ttl');

        $data = array_merge([
            'iss' => Config::get('app.url'),
            'iat' => $this->now,
            'exp' => intval($this->now + ($ttl * 60)),
            'nat' => intval($this->now + (Config::get('jwt.ttl') * 60))
        ], $data);

        return $data;
    }

    /**
     * generateJti method
     */
    protected function generateJti()
    {
        if (empty($this->jti)) {
            $this->jti = md5("{$this->aud}.{$this->sub}.{$this->iat}." . rand(1000, 1999));
        }
    }
{'fraction_non_alphanumeric': 0.1516258677383997, 'fraction_numerical': 0.0047497259773474606, 'mean_word_length': 1.6233828461907043, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 44, 'https://': 0, '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': '3570235', 'n_tokens_mistral': 1815, 'n_tokens_neox': 1735, 'n_words': 348}