src/UserTrait.php
public function getJWT()
    {
        // Collect all the data
        $secret      = static::getSecretKey();
        $currentTime = time();
        $request     = Yii::$app->request;
        $hostInfo    = '';

        // There is also a \yii\console\Request that doesn't have this property
        if ($request instanceof WebRequest) {
            $hostInfo = $request->hostInfo;
        }

        // Merge token with presets not to miss any params in custom
        // configuration
        $token = array_merge([
            'iss' => $hostInfo,
            'aud' => $hostInfo,
            'iat' => $currentTime,
            'nbf' => $currentTime
        ], static::getHeaderToken());

        // Set up id
        $token['jti'] = $this->getJTI();

        return JWT::encode($token, $secret, static::getAlgo());
    }
public function getJWT()
    {
        // Collect all the data
        $secret      = static::getSecretKey();
        $currentTime = time();
        $request     = Yii::$app->request;
        $hostInfo    = '';

        // There is also a \yii\console\Request that doesn't have this property
        if ($request instanceof WebRequest) {
            $hostInfo = $request->hostInfo;
        }

        // Merge token with presets not to miss any params in custom
        // configuration
        $token = array_merge([
            'iss' => $hostInfo,
            'aud' => $hostInfo,
            'iat' => $currentTime,
            'nbf' => $currentTime
        ], static::getHeaderToken());

        // Set up id
        $token['jti'] = $this->getJTI();

        return JWT::encode($token, $secret, static::getAlgo());
    }
public function getJWT ( ) { // Collect all the data $ secret = static :: getSecretKey ( ) ; $ currentTime = time ( ) ; $ request = Yii :: $ app -> request ; $ hostInfo = '' ; // There is also a \yii\console\Request that doesn't have this property if ( $ request instanceof WebRequest ) { $ hostInfo = $ request -> hostInfo ; } // Merge token with presets not to miss any params in custom // configuration $ token = array_merge ( [ 'iss' => $ hostInfo , 'aud' => $ hostInfo , 'iat' => $ currentTime , 'nbf' => $ currentTime ] , static :: getHeaderToken ( ) ) ; // Set up id $ token [ 'jti' ] = $ this -> getJTI ( ) ; return JWT :: encode ( $ token , $ secret , static :: getAlgo ( ) ) ; }
Encodes model data to create custom JWT with model.id set in it
@return string encoded JWT
Encodes model data to create custom JWT with model . id set in it