Sign given request with [[signatureMethod]].
@param \yii\httpclient\Request $request request instance.
@param OAuthToken|null $token OAuth token to be used for signature, if not set [[accessToken]] will be used.
@since 2.1 this method is public.
763646
public function signRequest($request, $token = null)
    {
        $params = $request->getData();

        if (isset($params['oauth_signature_method']) || $request->hasHeaders() && $request->getHeaders()->has('authorization')) {
            // avoid double sign of request
            return;
        }

        if (empty($params)) {
            $params = $this->generateCommonRequestParams();
        } else {
            $params = array_merge($this->generateCommonRequestParams(), $params);
        }

        $url = $request->getFullUrl();

        $signatureMethod = $this->getSignatureMethod();

        $params['oauth_signature_method'] = $signatureMethod->getName();
        $signatureBaseString = $this->composeSignatureBaseString($request->getMethod(), $url, $params);
        $signatureKey = $this->composeSignatureKey($token);
        $params['oauth_signature'] = $signatureMethod->generateSignature($signatureBaseString, $signatureKey);

        if ($this->authorizationHeaderMethods === null || in_array(strtoupper($request->getMethod()), array_map('strtoupper', $this->authorizationHeaderMethods), true)) {
            $authorizationHeader = $this->composeAuthorizationHeader($params);
            if (!empty($authorizationHeader)) {
                $request->addHeaders($authorizationHeader);

                // removing authorization header params, avoiding duplicate param server error :
                foreach ($params as $key => $value) {
                    if (substr_compare($key, 'oauth', 0, 5) === 0) {
                        unset($params[$key]);
                    }
                }
            }
        }

        $request->setData($params);
    }
838001
public function token(Request $request)
    {
        $authHeader = $request->header('Authorization');

        // Get for Auth Basic
        if (strtolower(substr($authHeader, 0, 5)) !== 'basic') {
            throw new UnauthorizedHttpException('Invalid authorization header, should be type basic');
        }

        // Get credentials
        $credentials = base64_decode(trim(substr($authHeader, 5)));

        list($login, $password) = explode(':', $credentials, 2);

        // Do auth
        if (! $token = auth()->attempt(['email' => $login, 'password' => $password])) {
            throw new UnauthorizedHttpException('Unauthorized login');
        }

        return $this->respondWithToken($token);
    }
1158533
public function attempt(Token $token, $prefix = Request::PREFIX)
    {
        $auth = $this->getAuthParams($prefix);
        $body = $this->getBodyParams($prefix);

        $request   = new Request($this->method, $this->uri, $body, $auth[$prefix . 'timestamp']);
        $signature = $request->sign($token, $prefix);

        foreach ($this->guards as $guard) {
            $guard->check($auth, $signature, $prefix);
        }

        return true;
    }
756468
public function signinAction(Request $request) {
        try {
            $data = $this->getAuthClientIdentifiers($request);

            // exports $client_id, $redirect_uri
            extract($data);

            if(!(($client = $this->clientProvider->getClient($client_id)) && $this->clientProvider->isValid($client, $redirect_uri))) {
                throw new SoauthException(sprintf('No client found with id %s', $client_id));
            }

            $data['client'] = $client;

            $this->info('> Sign in request', ['method' => $request->getMethod(), 'query' => $data]);
            $response = new Response($this->renderer->renderSignInForm($data));
        } catch (BadDataException $e) {
            $this->error('Bad Data Exception: ' . $e->getMessage(), ['errors' => $e->getErrors(), 'exception' => $e]);
            $response = $this->getBadRequestResponse();
        } catch (SoauthException $e) {
            $this->error('Soauth Exception: ' . $e->getMessage(), ['exception' => $e]);
            $response = $this->getBadRequestResponse();
        }

        $this->info('< Response', ['status_code' => $response->getStatusCode()]);
        return $response;
    }
499522
def sign!(request, token = nil, request_options = {})
      request.oauth!(http, self, token, options.merge(request_options))
    end
987401
protected function resetCsrfToken($token=null)
    {
        $token || $token = $this->request->getParam($this->options['csrfTokenName']);
        FormToken::instance()->reset($token);
    }
1344194
protected function checkCsrfToken(Request $request)
    {
        if (!$request->headers->has(self::CSRF_TOKEN_HEADER)) {
            return false;
        }

        return $this->csrfTokenManager->isTokenValid(
            new CsrfToken(
                $this->csrfTokenIntention,
                $request->headers->get(self::CSRF_TOKEN_HEADER)
            )
        );
    }
644150
public function check_signature(Request $request, Consumer $consumer, Token $token, string $signature): bool
	{
		$built = $this->build_signature($request, $consumer, $token);
		return $built == $signature;
	}
553692
public function sign(HttpRequest $request) {
    // add the developer key to the request before signing it
    if ($this->developerKey) {
      $requestUrl = $request->getUrl();
      $requestUrl .= (strpos($request->getUrl(), '?') === false) ? '?' : '&';
      $requestUrl .=  'key=' . urlencode($this->developerKey);
      $request->setUrl($requestUrl);
    }

    // Cannot sign the request without an OAuth access token.
    if (null == $this->accessToken && null == $this->assertionCredentials) {
      return $request;
    }

    // If the token is set to expire in the next 30 seconds (or has already
    // expired), refresh it and set the new token.
    $expired = (null == $this->accessToken) ||
        ($this->accessToken['created'] + ($this->accessToken['expires_in'] - 30)) < time();

    if ($expired) {
      if ($this->assertionCredentials) {
        $this->refreshTokenWithAssertion();
      } else {
        if (! array_key_exists('refresh_token', $this->accessToken)) {
            throw new Exception("The OAuth 2.0 access token has expired, "
                . "and a refresh token is not available. Refresh tokens are not "
                . "returned for responses that were auto-approved.");
        }
        $this->refreshToken($this->accessToken['refresh_token']);
      }
    }

    // Add the OAuth2 header to the request
    $request->setRequestHeaders(
        array('Authorization' => 'Bearer ' . $this->accessToken['access_token'])
    );

    return $request;
  }
1348619
public function activateAction(Request $request, $token)
    {
        /** @var $formFactory \FOS\UserBundle\Form\Factory\FactoryInterface */
        $formFactory = $this->get('fos_user.resetting.form.factory');
        /** @var $userManager \FOS\UserBundle\Model\UserManagerInterface */
        $userManager = $this->get('fos_user.user_manager');
        /** @var $dispatcher \Symfony\Component\EventDispatcher\EventDispatcherInterface */
        $dispatcher = $this->get('event_dispatcher');

        $user = $userManager->findUserByConfirmationToken($token);

        if (!is_object($user) || !$user instanceof UserInterface) {
            return $this->redirectToRoute('fos_user_security_login');
        }

        $event = new GetResponseUserEvent($user, $request);
        $dispatcher->dispatch(FOSUserEvents::RESETTING_RESET_INITIALIZE, $event);

        if (null !== $event->getResponse()) {
            return $event->getResponse();
        }

        $form = $formFactory->createForm();
        $form->setData($user);

        $form->handleRequest($request);

        if ($form->isSubmitted() && $form->isValid()) {
            $event = new FormEvent($form, $request);
            $dispatcher->dispatch(FOSUserEvents::RESETTING_RESET_SUCCESS, $event);

            $userManager->updateUser($user);

            if (null === $response = $event->getResponse()) {
                $url = $this->generateUrl('fos_user_profile_show');
                $response = new RedirectResponse($url);
            }

            // remove the flash message listener
            $dispatcher->removeListener(
                FOSUserEvents::RESETTING_RESET_COMPLETED,
                [$this->get('fos_user.listener.flash'), 'addSuccessFlash']
            );

            $dispatcher->dispatch(
                FOSUserEvents::RESETTING_RESET_COMPLETED,
                new FilterUserResponseEvent($user, $request, $response)
            );

            $this->addFlash(
                'success',
                $this->get('translator')->trans('xm_security.activate.success', [], 'XMSecurityBundle')
            );

            return $response;
        }

        return $this->render('@XMSecurity/Activate/activate.html.twig', array(
            'token'       => $token,
            'form'        => $form->createView(),
            'target_path' => $this->getTargetPath($request),
        ));
    }
910200
public function sign(Request $request) : Request
    {
        $algorithmHeader = $this->configuration->getAlgorithmHeader();
        $signatureHeader = $this->configuration->getSignatureHeader();

        $algorithm = $this->configuration->getSigningAlgorithm();
        $key = $this->configuration->getSigningKey();

        $request = $request->withHeader('X-SIGNED-ID', (string) Uuid::uuid4());
        $request = $request->withHeader(
            'X-SIGNED-TIMESTAMP',
            Carbon::now()->format('Y-m-d H:i:s')
        );

        $signature = new Signature(new Payload($request), $algorithm, $key);

        return $request
            ->withHeader($algorithmHeader, (string) $algorithm)
            ->withHeader($signatureHeader, (string) $signature);
    }
496768
private function authCookie(Request $request) {
		if ($request->cookies->has(self::COOKIE_TOKEN_NAME)) {
			$token = $request->cookies->get(self::COOKIE_TOKEN_NAME);
			return $this->authToken($token);
		}
		return null;
	}
152430
private function readToken(Request $request)
    {
        if (!$request->hasRedirectHeader('HTTP_AUTHORIZATION')) {
            return null;
        }

        return $request->readRedirectHeader('HTTP_AUTHORIZATION')
                ->withFilter(TokenFilter::instance());
    }
341817
public function tokenAction(Request $request)
    {
        /** @var PropertyAccess $config */
        $config = $this->app['conf'];

        if ( ! $request->isSecure() && $config->get(['main', 'api_require_ssl'], true) == true) {
            throw new HttpException(400, 'This route requires the use of the https scheme: ' . $config->get(['main', 'api_require_ssl']), null, ['content-type' => 'application/json']);
        }

        $this->oAuth2Adapter->grantAccessToken();
        ob_flush();
        flush();

        // As OAuth2 library already outputs response content, we need to send an empty
        // response to avoid breaking silex controller
        return '';
    }
1016303
public function setToken($token = null)
    {
        if ( ! $token and $this->session->has('googleapi_token') )
        {
            $token = $this->session->get('googleapi_token');
        }

        return $this->client->setAccessToken($token);
    }
1005351
public function getOAuthAction(Request $request)
	{
		$this->initSession($request);

		$apiKeys = $this->getAppParams();

		$oauth = new \OAuth($apiKeys["api-key"], $apiKeys["api-secret"]);

		$tokens = $oauth->getRequestToken($this->getRequestTokenUrl(), $this->getCallbackUrl($request));
		$this->sessionBag->set("oauth_token", $tokens["oauth_token"]);
		$this->sessionBag->set("oauth_token_secret", $tokens["oauth_token_secret"]);

		return $this->redirect(
			$this->getAuthenticateUrl($tokens["oauth_token"])
// 			302,
// 			["Authorization" => $oauth->getRequestHeader("POST", $this->getRequestTokenUrl())]
		);
	}
1061223
protected function signRequest($request)
    {
        $url = $request->getUrl(true);
        $url->getQuery()->add('key', $this->key);

        $request->setUrl($url);
    }