TOKEN ENDPOINT
Token endpoint - used to exchange an authorization grant for an access token.
@param Request $request
@return string
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 '';
    }
1264379
protected static function getTokenFromHttpBody( ezpRestRequest $request )
    {
        $token = null;
        if ( isset( $request->post['oauth_token'] ) )
        {
            $token = $request->post['oauth_token'];
        }

        return $token;
    }
1133661
protected function tokensMatch($request)
	{
		$token = $request->input('_token') ?: $request->header('X-CSRF-TOKEN');

		if ( ! $token && $header = $request->header('X-XSRF-TOKEN'))
		{
			$token = $this->encrypter->decrypt($header);
		}

		return StringUtils::equals($request->session()->token(), $token);
	}
512223
private function authHeader(Request $request) {
		if ($request->headers->has('authorization')) {
			$auth = $request->headers->get('authorization');
			if (!empty($auth)) {
				list(, $token) = explode(' ', $auth);
				if (empty($token)) {
					return null;
				}
				return $this->authToken($token);
			}
		}
		return null;
	}
1276654
protected function getRequestToken($request)
    {
        $name = $this->getName();
        $header = 'X-' . ucwords(strtolower($name));
        if ($token = $request->getHeader($header)) {
            return $token;
        }

        // Get from request var
        return $request->requestVar($name);
    }
711128
public function requestToken(Request $request)
    {
        $client = $this->getClient($request);

        /** @var TokenInterface $accessToken */
        $accessToken = $this->accessTokenRepository->findOneByClientWithoutUser($client);

        if (is_null($accessToken) || $accessToken->isBlocked() || $accessToken->isExpired()) {
            /** @var OrchestraTokenInterface $accessToken */
            $accessToken = $this->accessTokenManager->create($client);
            if (!$accessToken->isValid($this->validator)) {
                return $accessToken->getViolations();
            }

            $this->accessTokenManager->save($accessToken);
        }

        $tokenFacade = new AccessTokenFacade();
        $tokenFacade->accessToken   = $accessToken->getCode();
        $tokenFacade->expiresAt     = $accessToken->getExpiredAt();
        $tokenFacade->refreshToken = $accessToken->getRefreshCode();

        return $tokenFacade;
    }
680322
public function requestToken(Request $request)
    {
        $client = $this->getClient($request);
        $refreshToken = $request->get('refresh_token');

        /** @var TokenInterface $accessToken */
        $accessToken = $this->accessTokenRepository->findOneByClientAndRefreshToken($client, $refreshToken);

        if (! $accessToken instanceof TokenInterface) {
            throw new TokenNotFoundHttpException();
        }
        if ($accessToken->isBlocked()) {
            throw new TokenBlockedHttpException();
        }

        $newAccessToken = $this->accessTokenManager->create($client, $accessToken->getUser());
        if (!$newAccessToken->isValid($this->validator)) {
            return $newAccessToken->getViolations();
        }

        $this->accessTokenManager->save($newAccessToken);

        $tokenFacade = new AccessTokenFacade();
        $tokenFacade->accessToken   = $newAccessToken->getCode();
        $tokenFacade->expiresAt     = $newAccessToken->getExpiredAt();
        $tokenFacade->refreshToken = $newAccessToken->getRefreshCode();

        return $tokenFacade;
    }
466293
public function fetchRequestToken($request)
    {
        $this->getVersion($request);

        $consumer = $this->getConsumer($request);

        // no token required for the initial token request
        $token = null;

        $this->checkSignature($request, $consumer, $token);

        $new_token = $this->dataStore->newRequestToken($consumer);

        return $new_token;
    }
242752
public static function token(Request $request)
    {
        $authorization = $request->getHeader('Authorization');

        if (!isset($authorization[0])) {
            throw new HeaderWithoutAuthorizationException('The request does not contain the Authorization header');
        }

        $token = preg_replace('/^\w+\s/', '', $authorization[0]);

        return Authenticator::decodeToken($token);
    }
1155866
public function getEndpoint()
    {
        $endpoint = $this->getTestMode() ? $this->testEndpoint : $this->liveEndpoint;

        return $endpoint . $this->getAccountNumber() . '/rs/authService';
    }
825818
public function authorizationEndpoint() {
		$endpoint = $this->getset('authorization_endpoint', func_get_args());
		return $this->validateEndpoint($endpoint ?: self::URI_AUTHORIZE);
	}
1360868
def token_protected_endpoint(function):
  
  @wraps(function)
  def decorated(*args, **kwargs):
    auth_token = request.form.get('auth_token')
    if not auth_token:
      return json.dumps({
        'status': 'fail',
        'reason': 'You must provide an auth_token',
      })

    data = dict(request.form)
    del data['auth_token']
    correct_token = create_token(current_app.config['SECRET_KEY'], data)

    if _compare_digest(auth_token, correct_token):
      return function(*args, **kwargs)

    else:
      return json.dumps({
        'status': 'fail',
        'reason': 'Incorrect auth_token',
      })

  return decorated
929670
public function getOAuthCallbackAction(Request $request)
	{
		$this->initSessionBag();

		$apiKeys = $this->getAppParams();
		$oauth = new \OAuth($apiKeys["api-key"], $apiKeys["api-secret"]);
		$oauth->setToken($this->sessionBag->get("oauth_token"), $this->sessionBag->get("oauth_token_secret"));

		$oauthResponse = $oauth->getAccessToken($this->getAccessTokenUrl(), null, $request->query->get("oauth_verifier"));

		$this->storeOAuthData($oauthResponse);
		return $this->returnResult($oauthResponse);
	}
1293728
private function getToken($request) {
    $hash = hash('sha256', $request.$this->psl->getUid());

    return substr($hash, 0, 4).substr($hash, 16, 4).substr($hash, 32, 4).substr($hash, 48, 4);

  }
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);
    }
538907
public function request($method, $endpoint, array $parameters = null)
    {
        $url = $this->config->getEndpoint() . $endpoint;

        // Client should always send OAuth2 tokens in its headers
        $headers = array('Authorization' => 'Bearer ' . $this->config->getAccessToken());

        return $this->client->request($method, $url, $parameters, $headers);
    }
1317930
protected function tokensMatch($request)
    {
        $token = $this->getTokenFromRequest($request);

        return is_string($request->session()->token()) &&
               is_string($token) &&
               hash_equals($request->session()->token(), $token);
    }