Get the given claim from the JWT.

@return mixed|null
502002
protected function getClaim($claim)
    {
        $token = $this->parseToken();

        return $token ? $token->getClaim($claim) : null;
    }
1177937
public function parseClaims($jwt)
    {
        //PHP 7 has convenient "??" operator, but we're making this
        //5.4+ compatible. So this is a simple "safe array access" that
        //won't cause warnings or errors if we try to get a non-existent key
        $get = function ($arr, $key) {
            return array_key_exists($key, $arr) ? $arr[$key] : null;
        };

        $hasResourceOwner = array_key_exists('http://byu.edu/claims/resourceowner_byu_id', $jwt);

        $jwt['byu']['client'] = [
            'byuId' =>              $get($jwt, 'http://byu.edu/claims/client_byu_id'),
            'claimSource' =>        $get($jwt, 'http://byu.edu/claims/client_claim_source'),
            'netId' =>              $get($jwt, 'http://byu.edu/claims/client_net_id'),
            'personId' =>           $get($jwt, 'http://byu.edu/claims/client_person_id'),
            'preferredFirstName' => $get($jwt, 'http://byu.edu/claims/client_preferred_first_name'),
            'prefix' =>             $get($jwt, 'http://byu.edu/claims/client_name_prefix'),
            'restOfName' =>         $get($jwt, 'http://byu.edu/claims/client_rest_of_name'),
            'sortName' =>           $get($jwt, 'http://byu.edu/claims/client_sort_name'),
            'subscriberNetId' =>    $get($jwt, 'http://byu.edu/claims/client_subscriber_net_id'),
            'suffix' =>             $get($jwt, 'http://byu.edu/claims/client_name_prefix'),
            'surname' =>            $get($jwt, 'http://byu.edu/claims/client_surname'),
            'surnamePosition' =>    $get($jwt, 'http://byu.edu/claims/client_surname_position')
        ];

        if ($hasResourceOwner) {
            $jwt['byu']['resourceOwner'] = [
                'byuId' =>              $get($jwt, 'http://byu.edu/claims/resourceowner_byu_id'),
                'netId' =>              $get($jwt, 'http://byu.edu/claims/resourceowner_net_id'),
                'personId' =>           $get($jwt, 'http://byu.edu/claims/resourceowner_person_id'),
                'preferredFirstName' => $get($jwt, 'http://byu.edu/claims/resourceowner_preferred_first_name'),
                'prefix' =>             $get($jwt, 'http://byu.edu/claims/resourceowner_prefix'),
                'restOfName' =>         $get($jwt, 'http://byu.edu/claims/resourceowner_rest_of_name'),
                'sortName' =>           $get($jwt, 'http://byu.edu/claims/resourceowner_sort_name'),
                'suffix' =>             $get($jwt, 'http://byu.edu/claims/resourceowner_suffix'),
                'surname' =>            $get($jwt, 'http://byu.edu/claims/resourceowner_surname'),
                'surnamePosition' =>    $get($jwt, 'http://byu.edu/claims/resourceowner_surname_position')
            ];
        }

        $webresCheckKey = $hasResourceOwner ? 'resourceOwner' : 'client';
        $jwt['byu']['webresCheck'] = [
            'byuId' => $jwt['byu'][$webresCheckKey]['byuId'],
            'netId' => $jwt['byu'][$webresCheckKey]['netId'],
            'personId' => $jwt['byu'][$webresCheckKey]['personId']
        ];

        $jwt['wso2'] = [
            'apiContext' =>         $get($jwt, 'http://wso2.org/claims/apicontext'),
            'application' => [
                'id' =>             $get($jwt, 'http://wso2.org/claims/applicationid'),
                'name' =>           $get($jwt, 'http://wso2.org/claims/applicationname'),
                'tier' =>           $get($jwt, 'http://wso2.org/claims/applicationtier')
            ],
            'clientId' =>           $get($jwt, 'http://wso2.org/claims/client_id'),
            'endUser' =>            $get($jwt, 'http://wso2.org/claims/enduser'),
            'endUserTenantId' =>    $get($jwt, 'http://wso2.org/claims/enduserTenantId'),
            'keyType' =>            $get($jwt, 'http://wso2.org/claims/keytype'),
            'subscriber' =>         $get($jwt, 'http://wso2.org/claims/subscriber'),
            'tier' =>               $get($jwt, 'http://wso2.org/claims/tier'),
            'userType' =>           $get($jwt, 'http://wso2.org/claims/usertype'),
            'version' =>            $get($jwt, 'http://wso2.org/claims/version')
        ];

        return $jwt;
    }
554950
public function get()
    {
        $result = null;
        switch ($this->format) {
            case 'nvp':
                $result = http_build_query($this->data);
                break;

            case 'json':
            default:
                $result = json_encode($this->data, JSON_PRETTY_PRINT);
                break;
        }

        return $result;
    }
551156
public function user()
    {
        if ($this->user !== null) {
            return $this->user;
        }

        if ($this->jwt->setRequest($this->request)->getToken() &&
            ($payload = $this->jwt->check(true)) &&
            $this->validateSubject()
        ) {
            return $this->user = $this->provider->retrieveById($payload['sub']);
        }
    }
322000
protected function getToken()
  {
    return $this->getRequest()->cookies->get($this->getTokenVar(), $this->getSession()->get($this->getTokenVar()));
  }
306955
public function authenticate()
    {
        $u = $this->authenticateBySession();
        if ($u) {
            return $u;
        }

        $u = $this->authenticateByToken();
        if ($u) {
            return $u;
        }

        return null;
    }
746606
public function getAccessToken()
  {
    $token = $this->getAuth()->getAccessToken();
    // The response is json encoded, so could be the string null.
    // It is arguable whether this check should be here or lower
    // in the library.
    return (null == $token || 'null' == $token || '[]' == $token) ? null : $token;
  }
154477
public function getClaim($claim, $default = null)
    {
        $context = $this->_context;

        return isset($context->claims[$claim]) ? $context->claims[$claim] : $default;
    }
516082
public function get(string $name)
    {
        $claims = $this->getAll();

        if (!array_key_exists($name, $claims)) {
            return null;
        }

        return $claims[$name];
    }
1063369
protected function getLoggedUser()
    {
        $user = $this->get('security.token_storage')->getToken()->getUser();
        if (is_string($user)) {
            $user = null;
        }

        return $user;
    }
666347
public function getToken()
    {
        if ($this->token === null) {
            try {
                $this->parseToken();
            } catch (JWTException $e) {
                $this->token = null;
            }
        }

        return $this->token;
    }
780641
public function getAuthToken()
    {
        if(!isset($this->__token))
        {
            $token   = false;
            $request = $this->getObject('request');

            if($request->headers->has('Authorization'))
            {
                $header = $request->headers->get('Authorization');

                if(stripos($header, 'jwt') === 0) {
                    $token = substr($header , 4);
                }
            }

            if($request->isSafe())
            {
                if($request->query->has('auth_token')) {
                    $token = $request->query->get('auth_token', 'url');
                }
            }
            else
            {
                if($request->data->has('auth_token')) {
                    $token = $request->data->get('auth_token', 'url');
                }
            }

            if($token) {
                $token = $this->getObject('lib:http.token')->fromString($token);
            }

            $this->__token = $token;
        }

        return $this->__token;
    }
769809
protected function getTokenFromHeader()
    {
        // if there is no authorization header present.
        if (!$this->getRequest()->headers->has('Authorization')) {
            // abort by returning null.
            return null;
        }

        // gets the full header string.
        $header = $this->getRequest()->headers->get('Authorization');

        // returns the token without the 'Bearer ' prefix.
        return Str::replaceFirst('Bearer ', '', $header);
    }
1004637
protected function _get($token = null)
    {
        $token = $this->_token($token);

        $subject = $this->_subject([
            'success' => true,
            'entity' => $this->_table()->newEntity(),
            'token' => $token
        ]);

        $this->_trigger('beforeRender', $subject);
    }
839750
protected function parseToken()
    {
        $request = $this->requestHandler->getRequest();
        if (! $request->hasHeader('Authorization')) {
            return null;
        }

        try {
            // Attempt to parse and validate the JWT
            $jwt = $request->bearerToken();
            $token = (new Parser())->parse($jwt);
            if (! $token->verify(new Sha256(), file_get_contents($this->publicKey))) {
                throw new AccessDeniedException(
                    'Access token could not be verified.',
                    'Check authorization and resource environment match & that token has not been tampered with.'
                );
            }

            // Ensure access token hasn't expired
            $data = new ValidationData();
            $data->setCurrentTime(Carbon::now()->timestamp);
            if ($token->validate($data) === false) {
                throw new AccessDeniedException('Access token is invalid or expired.');
            }

            // We've made it! Save the details on the validator.
            return $token;
        } catch (\InvalidArgumentException $exception) {
            throw new AccessDeniedException('Could not parse JWT.', $exception->getMessage());
        } catch (\RuntimeException $exception) {
            throw new AccessDeniedException('Error while decoding JWT contents.');
        }
    }
374767
public function user()
    {
        /*
         * If we have already retrieved the user for the current request we can
         * just return it back immediately.
         */
        if (! is_null($this->user)) {
            return $this->user;
        }

        // Attempt to retrieve the token from the request
        $token = $this->jwt->getToken();
        if (! $token) {
            return null;
        }

        // Get the user associated with the token
        try {
            $user = $this->jwt->toUser($token);
        } catch (JWTException $e) {
            return null;
        }

        return $this->user = $user;
    }
43505
public function getAccessToken() 
    {
        $result = null;
        $options = $this->config->getAccessTokenConfiguration();
        $token = $this->getResponse('/oauth/token', $options);
        if (isset($token['access_token'])) {
            $this->config->setBearer($token['access_token']);
        }else {
            echo 'ERROR: no access token in API response';
        }
    }