Creates token credentials from the body response.

@param string $body

@return TokenCredentials
504912
protected function createTokenCredentials($body)
    {
        parse_str($body, $data);

        if (!$data || !is_array($data)) {
            throw new CredentialsException('Unable to parse token credentials response.');
        }

        if (isset($data['error'])) {
            throw new CredentialsException("Error [{$data['error']}] in retrieving token credentials.");
        }

        $tokenCredentials = new TokenCredentials();
        $tokenCredentials->setIdentifier($data['oauth_token']);
        $tokenCredentials->setSecret($data['oauth_token_secret']);

        return $tokenCredentials;
    }
1193253
final public static function createOtpToken (string $username)
	{
		$token = self::setOtpToken();
		return self::setUserOtpToken($username, $token);
	}
171407
protected function parseAccessToken($body)
    {
        if (!is_array($body)) {
            $body = json_decode($body, true);
        }

        if (empty($body['access_token'])) {
            throw new AuthorizeFailedException('Authorize Failed: '.json_encode($body, JSON_UNESCAPED_UNICODE), $body);
        }

        return new AccessToken($body);
    }
887952
public function createNewToken($captcha = null, $answer = null, $expire = 300)
    {
        if ((null === $captcha) || (null === $answer)) {
            $captcha = $this->generateEquation();
            $answer  = $this->evaluateEquation($captcha);
        }
        $this->token = [
            'captcha' => $captcha,
            'answer'  => $answer,
            'expire'  => (int)$expire,
            'start'   => time()
        ];
        $_SESSION['pop_captcha'] = serialize($this->token);
        return $this;
    }
281870
public static function Unauthorized($body = NULL, \Exception $previous = NULL) {
    return self::code(401, $body, $previous);
  }
440332
public function verify($credentials)
    {
        if(!array_key_exists("jwt", $credentials) || empty($credentials["jwt"])) {
            throw new \Exception("JWT is required");
        }

        // Make sure we have a secret key to decode the JWT
        if(!array_key_exists("secret_key", $credentials) || empty($credentials["secret_key"])) {
            throw new \Exception("Secret Key is required to decode this JWT");
        }

        // Get hash alg from params, default to HS256
        $hashAlgs = array("HS256");
        if(array_key_exists("hash_alg", $credentials) && !empty($credentials["hash_alg"])) {
            $hashAlgs[] = $credentials["hash_alg"];
            $hashAlgs = array_unique($hashAlgs);
        }

        $token = JWT::decode($credentials["jwt"], $credentials["secret_key"], $hashAlgs);

        // User ID is a good checksum to make sure we have a valid JWT
        if(empty($token) || empty($token->id)) {
            throw new \Exception("JWT Token invalid");
        }

        return $token;
    }
864588
public function initialize($body)
    {
        $request = $this->paystackHttpClient->post(
            Resource::INITIALIZE_TRANSACTION,
            [
                'body'  => is_array($body) ? $this->toJson($body) : $body,
            ]
        );

        return $this->processResourceRequestResponse($request);
    }
1302069
public function CreateToken()
    {
        $urlMethod = $this->GetRequestUrl('authentication_oauth');
        $requestType = $this->GetRequestType('authentication_oauth');
        $requestData = array(
            'grant_type' => 'client_credentials'
        );
        
        $rest = new RestTool(false, $this->_root);
        $authHlp = new AuthenticationHelper($this->_root);
        
        $urlDetails = parse_url($this->_root->Config->BaseUrl);
        $rest->AddRequestHttpHeader('Host: ' . @$urlDetails['host']);
        $rest->AddRequestHttpHeader('Authorization: Basic ' . $authHlp->GetHttpHeaderBasicKey());
        $rest->AddRequestHttpHeader('Content-Type: application/x-www-form-urlencoded');
        $response = $rest->Request($urlMethod, $requestType, $requestData);
        $token = $this->CastResponseToEntity($response, '\MangoPay\Libraries\OAuthToken');
        $token->autentication_key = $authHlp->GetAutenticationKey();
        
        return $token;
    }
1335098
public function getCredentials(Request $request)
    {
        // Get token and key
        $headerToken  = $request->headers->get('X-APP-TOKEN');

        if (!$headerToken) {
            // no token, nonce or app? Return null and no other methods will be called
            return;
        }

        // What you return here will be passed to getUser() as $credentials
        $token = new Token;
        $token->fromHeader($headerToken);

        return array(
            'token'     => $token,
            'header'    => $headerToken,
        );
    }
118853
protected function getTokenByClientCredentialsGrant()
    {
        $token = $this->getAuthorizationServer()->getAccessToken('client_credentials', [
            'scope' => $this->config['client_credentials']['scope'],
        ]);

        $this->getFrameworkBridge()->persistClientToken(
            $this->config['client_credentials']['client_id'],
            $token->getToken(),
            $token->getExpires(),
            $token->getValues()['role']
        );

        return $token;
    }
1211046
public static function create($body)
    {
        if (0 !== strpos($body, static::START_TOKEN)) {
            throw new InvalidArgumentException("Unexpected response body.");
        }
        if (static::END_TOKEN !== substr($body, -strlen(static::END_TOKEN))) {
            throw new InvalidArgumentException("Unexpected response body.");
        }

        $body = substr($body, strlen(static::START_TOKEN), -strlen(static::END_TOKEN));

        $parts = explode('|', trim($body, '|'));
        if (empty($parts)) {
            throw new InvalidArgumentException("Unexpected response body.");
        }

        $response = new static();

        for ($i = 0; $i < count($parts); $i++) {
            list($key, $value) = explode(':', $parts[$i], 2);

            if ($key === Config::RESULT) {
                if (0 < strpos($value, ':')) {
                    list($code, $field) = explode(':', $value, 2);
                } else {
                    $code = $value;
                    $field = 'unknown';
                }
                $response->set(Config::RESULT, $code);
                $response->set(Config::FIELD, $field);
            } else {
                $response->set($key, $value);
            }
        }

        return $response;
    }
1089990
public static function decodeCredentials($token, $auth) {
        try {
            return JWT::decode($token, $auth['key'], array('HS256'));
        } catch (SignatureInvalidException $e) {
            abortAuth(SignatureInvalidException::class);
        } catch (ExpiredException $e) {
            abortAuth(ExpiredException::class);
        }
    }
963175
public function tokenize(array $credentials)
    {
        if (empty($credentials)) {
            throw new AuthenticationException('Unable to create token, no or empty credentials');
        }

        foreach ($this->providers as $provider) {
            if (!$provider->supportsCredentials($credentials)) {
                continue;
            }

            if (!$token = $provider->tokenize($credentials)) {
                $this->stash()
                     ->destroy();

                throw new AuthenticationException(sprintf('Unable to create token, credentials could not be authenticated in provider "%s"', get_class($provider)));
            }

            $this->stash()
                 ->put($token);

            return $this;
        }

        $this->stash()
             ->destroy();

        throw new AuthenticationException(sprintf('Unable to create token, missing provider supporting credentials "%s"', implode(', ', array_keys($credentials))));
    }
695371
protected function parseAccessTokenResponse($responseBody)
    {
        $body = json_decode($responseBody, true);

        if (isset($body['error'])) {
            throw new TokenResponseException($body['hint']);
        }

        $token = new StdOAuth2Token();
        $token->setAccessToken($body['access_token']);
        $token->setRefreshToken($body['refresh_token']);
        $token->setLifetime($body['expires_in']);

        // Store the id_token as an "extra param"
        $token->setExtraParams(['id_token' => $body['id_token']]);

        return $token;
    }
478054
private function parse($body)
    {
        $body = json_decode($body, true);

        if (isset($body['response'])) {
            return new Options($body['response']);
        }

        return new Options($body);
    }
480306
public function clientCredentials($scope = 'public')
    {
        if (is_array($scope)) {
            $scope = implode(' ', $scope);
        }

        $token_response = $this->request(self::CLIENT_CREDENTIALS_TOKEN_ENDPOINT, array(
            'grant_type' => 'client_credentials',
            'scope' => $scope
        ), "POST", false);

        return $token_response;
    }
1002099
protected function buildAuthorizationHeaderForAPIRequest(
        $method,
        Url $uri,
        TokenInterface $token,
        $bodyParams = null
    ) {
        $this->signature->setTokenSecret($token->getAccessTokenSecret());
        $authParameters = $this->getBasicAuthorizationHeaderInfo();
        if (isset($authParameters[ 'oauth_callback' ])) {
            unset($authParameters[ 'oauth_callback' ]);
        }

        $authParameters = array_merge($authParameters, ['oauth_token' => $token->getAccessToken()]);

        $signatureParams = (is_array($bodyParams)) ? array_merge($authParameters, $bodyParams) : $authParameters;
        $authParameters[ 'oauth_signature' ] = $this->signature->getSignature($uri, $signatureParams, $method);

        $authorizationHeader = 'OAuth ';
        $delimiter = '';

        foreach ($authParameters as $key => $value) {
            $authorizationHeader .= $delimiter . rawurlencode($key) . '="' . rawurlencode($value) . '"';
            $delimiter = ', ';
        }

        return $authorizationHeader;
    }