Create an auth code.

@param string $token The token ID
@param int $expireTime Token expire time
@param int $sessionId Session identifier
@param string $redirectUri Client redirect uri

@return void
357473
public function create($token, $expireTime, $sessionId, $redirectUri)
    {
        $this->getConnection()->table('oauth_auth_codes')->insert([
            'id' => $token,
            'session_id' => $sessionId,
            'redirect_uri' => $redirectUri,
            'expire_time' => $expireTime,
            'created_at' => Carbon::now(),
            'updated_at' => Carbon::now(),
        ]);
    }
810274
public void setAccessToken(final String accessToken, final Long expiresIn) {
    for (Authentication auth : authentications.values()) {
      if (auth instanceof OAuth) {
        ((OAuth) auth).setAccessToken(accessToken, expiresIn);
        return;
      }
    }
    OAuth oAuth = new OAuth(null, null, null) {
      @Override
      public void applyToParams(List<Pair> queryParams, Map<String, String> headerParams) {
        headerParams.put("Authorization", "Bearer " + accessToken);
      }
    };
    oAuth.setAccessToken(accessToken, expiresIn);
    addAuthorization("docusignAccessCode", oAuth);
    // throw new RuntimeException("No OAuth2 authentication configured!");
  }
1198950
public function createCustomToken($uid, array $claims = [], \DateTimeInterface $expiresAt = null): Token
    {
        if (count($claims)) {
            $this->builder->set('claims', $claims);
        }

        $this->builder->set('uid', (string) $uid);

        $now = time();
        $expiration = $expiresAt ? $expiresAt->getTimestamp() : $now + (60 * 60);

        $token = $this->builder
            ->setIssuedAt($now)
            ->setExpiration($expiration)
            ->sign($this->signer, $this->privateKey)
            ->getToken();

        $this->builder->unsign();

        return $token;
    }
813767
protected function createToken($userId, $csrfToken, Carbon $expiration)
    {
        return JWT::encode([
            'sub' => $userId,
            'csrf' => $csrfToken,
            'expiry' => $expiration->getTimestamp(),
        ], $this->encrypter->getKey());
    }
385055
public function create($token, $expireTime, $accessToken)
    {
        $this->getDbConnection()->insert('oauth_refresh_token', [
            'refresh_token' => $token,
            'access_token' => $accessToken,
            'expire_time' => $expireTime
        ]);
    }
926776
public function setUriToken($uri = null)
	{
		$toSetUri = $uri;
		if(!$uri) {
			$toSetUri = $this->getUriPrefix().'tokens';
		}

		$this->_uriToken = $toSetUri;
	}
869145
public function auth(string $userToken = null, string $redirect = '')
    {
        return rudra()->get('auth')->access($userToken, $redirect);
    }
468096
def token_login(token):
    """"""

    expired, invalid, user = login_token_status(token)

    if invalid:
        do_flash(*get_message('INVALID_LOGIN_TOKEN'))
    if expired:
        send_login_instructions(user)
        do_flash(*get_message('LOGIN_EXPIRED', email=user.email,
                              within=_security.login_within))
    if invalid or expired:
        return redirect(url_for('login'))

    login_user(user)
    after_this_request(_commit)
    do_flash(*get_message('PASSWORDLESS_LOGIN_SUCCESSFUL'))

    return redirect(get_post_login_redirect())
301602
protected function createBodyTokenResponse(TokenInterface $token, int $tokenExpiresIn): ResponseInterface
    {
        $this->logDebug('Sending token as JSON response.');

        $scopeList  = $token->isScopeModified() === false || empty($token->getScopeIdentifiers()) === true ?
            null : $token->getScopeList();

        // for access token format @link https://tools.ietf.org/html/rfc6749#section-5.1
        $parameters = $this->filterNulls([
            'access_token'  => $token->getValue(),
            'token_type'    => $token->getType(),
            'expires_in'    => $tokenExpiresIn,
            'refresh_token' => $token->getRefreshValue(),
            'scope'         => $scopeList,
        ]);

        // extra parameters
        // https://tools.ietf.org/html/rfc6749#section-4.1.4
        // https://tools.ietf.org/html/rfc6749#section-4.3.3
        // https://tools.ietf.org/html/rfc6749#section-4.4.3
        $extraParameters = $this->getIntegration()->getBodyTokenExtraParameters($token);

        $response = new JsonResponse($parameters + $extraParameters, 200, [
            'Cache-Control' => 'no-store',
            'Pragma'        => 'no-cache'
        ]);

        return $response;
    }
577799
public function authenticateToken(TokenInterface $token, UserProviderInterface $userProvider, $providerKey)
    {
        if (empty($this->secretKey) == false) {
            $captcha = $this->request->get('g-recaptcha-response');

            $reCaptcha = new ReCaptcha($this->secretKey);
            $response = $reCaptcha->verify($captcha, $this->request->getClientIp());

            if ($response->isSuccess() == false) {
                throw new AuthenticationException('Captcha not passed');
            }
        }

        try {
            $user = $userProvider->loadUserByUsername($token->getUsername());
        } catch (UsernameNotFoundException $e) {
            throw new AuthenticationException('Invalid username or password');
        }

        $passwordValid = $this->encoder->isPasswordValid($user, $token->getCredentials());

        if ($passwordValid) {
            return new UsernamePasswordToken(
                $user,
                $user->getPassword(),
                $providerKey,
                $user->getRoles()
            );
        }

        throw new AuthenticationException('Invalid username or password');
    }
854874
public function setSessionTokens($token, $tokenSecret = null)
    {
        $this->session->set(self::SESSION_TOKEN_KEY, $token);
        $this->session->set(self::SESSION_TOKEN_SECRET_KEY, $tokenSecret);
    }
590391
def request_user_auth(code, redirect_uri)
      response = http_client(MXIT_AUTH_TOKEN_URI) do |http, path|

        request = new_post_request(path, {
          "grant_type" => "authorization_code",
          "code" => code,
          "redirect_uri" => redirect_uri
        })

        http.request(request)
      end

      @auth_token = AuthToken.new(handle_response(response))
    end
543303
public function getAuthenticationGateway(
        $authorizeUri, $accessTokenUri, $redirectUri
    ) {

        if (!$this->redirector instanceof Redirector) {
            throw new \RuntimeException("A Redirector is required for authentication");
        }

        $gateway = new AuthenticationGateway($this->httpClient, $this->redirector);
        $gateway->setAuthorizeUri($authorizeUri)
                ->setAccessTokenUri($accessTokenUri)
                ->setRedirectUri($redirectUri)
                ->setClientCredentials($this->clientId, $this->clientSecret);

        return $gateway;

    }
1181294
public function authorize($redirect_uri, $scope = Client::SCOPE_READ) {
		header('Location: ' . $this->getAuthorizeUri($redirect_uri, $scope));
		exit;
	}
800376
protected function sendByHttp(string $url, string $token = null) : void
    {
        $content = ['event' => static::NAME, 'data' => $this->data];

        $request = new Request($url, $content);
        if ($token) {
            $request->addHeader(Header::AUTHORIZATION, $token);
        }

        $request->send();
    }
1372112
static function createProvider($key, $redirect) {
    switch ($key) {
      case "google":
        return self::google($redirect);
      case "facebook":
        return self::facebook($redirect);
      case "github":
        return self::github($redirect);

      break;
        throw new UserAuthenticationException("No such known OAuth2 provider '$key'");
    }
  }
1325226
protected function codeAskResourceOwnerForApproval(
        array $parameters,
        ClientInterface $client,
        string $redirectUri = null,
        int $maxStateLength = null
    ): ResponseInterface {
        $state = $this->codeGetState($parameters);
        if ($maxStateLength !== null && strlen($state) > $maxStateLength) {
            throw new OAuthCodeRedirectException(
                OAuthCodeRedirectException::ERROR_INVALID_REQUEST,
                $redirectUri,
                $state
            );
        }

        if ($client->isCodeGrantEnabled() === false) {
            throw new OAuthCodeRedirectException(
                OAuthCodeRedirectException::ERROR_UNAUTHORIZED_CLIENT,
                $redirectUri,
                $state
            );
        }

        $scope = $this->codeGetScope($parameters);
        list ($isScopeValid, $scopeList, $isScopeModified) =
            $this->codeGetIntegration()->codeValidateScope($client, $scope);
        if ($isScopeValid === false) {
            throw new OAuthCodeRedirectException(
                OAuthCodeRedirectException::ERROR_INVALID_SCOPE,
                $redirectUri,
                $state
            );
        }

        $response = $this->codeGetIntegration()->codeCreateAskResourceOwnerForApprovalResponse(
            $client,
            $redirectUri,
            $isScopeModified,
            $scopeList,
            $state
        );

        return $response;
    }