Generate an access token to be used on subsequent requests.

@return array
541308
public function token()
    {
        $payload = [
            'auth'        => [$this->config['client_id'], $this->config['client_secret']],
            'form_params' => ['grant_type' => 'client_credentials'],
        ];

        $request = array_merge($this->requestTemplate, $payload);
        $rawResponse = $this->getHttpClient()->post($this->buildUrlFromString('oauth2/token'), $request);
        $rawResponse = $this->responseToArray($rawResponse);

        return [
            'token'  => Arr::get($rawResponse, 'access_token'),
            'type'   => Arr::get($rawResponse, 'token_type'),
            'scope'  => Arr::get($rawResponse, 'scope'),
            'expiry' => isset($rawResponse['expires_in'])
                ? time() + Arr::get($rawResponse, 'expires_in')
                : null,
        ];
    }
647675
function getAccessToken($oauth_verifier = FALSE)
    {
        $parameters = [];
        if (!empty($oauth_verifier)) {
            $parameters['oauth_verifier'] = $oauth_verifier;
        }
        $request = $this->oAuthRequest($this->accessTokenURL(), 'GET', $parameters);
        $token = OAuthUtil::parse_parameters($request);
        $this->token = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']);
        return $token;
    }
584564
public function getAccessToken()
    {
        if ( ! empty($this->token)) {
            if ($this->model->insertTokenNonce([
                'id_consumer_token' => $this->token->id,
                'nonce'             => $token[ 'nonce' ] = Oauth::generateNonce(),
                'timestamp'         => $token[ 'timestamp' ] = date('Y-m-d H:m:s'),
                'expires'           => $token[ 'expires' ] = time() + 3600,
            ])) {
                return new DataStructures\Token([
                    'key'       => $this->token->key,
                    'secret'    => $this->token->secret,
                    'nonce'     => $token[ 'nonce' ],
                    'timestamp' => $token[ 'timestamp' ],
                    'expires'   => $token[ 'expires' ],
                    'verifier'  => (new Token($this->token->key, $this->token->secret))->getVerifier(),
                ]);
            }
        }

        $token = $this->generateToken('ACCESS');
        $token = new DataStructures\Token([
            'id'       => $token[ 'id' ],
            'key'      => $token[ 'key' ],
            'secret'   => $token[ 'secret' ],
            'verifier' => (new Token($token[ 'key' ], $token[ 'secret' ]))->getVerifier(),
        ]);

        if ($this->model->insertTokenNonce([
            'id_consumer_token' => $token[ 'id' ],
            'nonce'             => $token[ 'nonce' ] = Oauth::generateNonce(),
            'timestamp'         => $token[ 'timestamp' ] = date('Y-m-d H:m:s'),
            'expires'           => $token[ 'expires' ] = time() + 3600,
        ])) {
            return $token;
        }

        return false;
    }
482994
public function forAccessTokens()
    {
        $this->router->post('/token', [
            'uses' => 'AccessTokenController@issueToken',
            'as' => 'passport.token',
            'middleware' => 'throttle',
        ]);

        $this->router->group(['middleware' => ['web', 'auth']], function ($router) {
            $router->get('/tokens', [
                'uses' => 'AuthorizedAccessTokenController@forUser',
                'as' => 'passport.tokens.index',
            ]);

            $router->delete('/tokens/{token_id}', [
                'uses' => 'AuthorizedAccessTokenController@destroy',
                'as' => 'passport.tokens.destroy',
            ]);
        });
    }
342085
public function getTokens()
    {
        $response = $this->client->post($this->uri());

        return $this->handleResponse($response);
    }
355750
public function getAccessToken()
    {
        if (is_null($this->_accessToken)) {
            if (empty($this->access_token)) {
                $this->errorServer(Yii::t('yuncms', 'The request is missing "access_token" parameter'));
            }
            if (!$this->_accessToken = OAuth2AccessToken::findOne(['access_token' => $this->access_token])) {
                $this->errorServer(Yii::t('yuncms', 'The Access Token is invalid'));
            }
        }
        return $this->_accessToken;
    }
19979
private function prepareAccessToken()
    {
        // if not exits data in the store
        if(!$this->store->getPersistentData('token_expires_at')){
            return $this->getAccessTokenWithClientCredentials();
         // if access token expires.
        }else if($this->store->getPersistentData('token_expires_at') < time()){
            try{
                return $this->getAccessTokenWithRefreshToken();    
            }catch(AuthenticationException $e){
                return $this->getAccessTokenWithClientCredentials();
            }
        }else{
            return $this->store->getPersistentData('access_token');
        }
    }
1115971
protected function getAccessToken()
    {
        $response = $this->httpClient
            ->post(
                self::ENDPOINT_ACCESS_TOKEN,
                array(
                    'grant_type'    => 'client_credentials',
                    'client_id'     => $this->config['client_id'],
                    'client_secret' => $this->config['client_secret'],
                    'scope'         => implode(',', $this->config['scopes'])
                )
            )
        ;

        $data = json_decode($response->getContent(), true);

        if (json_last_error() !== JSON_ERROR_NONE) {
            $ex = new HttpResponseException('[access_token] Invalid JSON: '. json_last_error_msg());
            $ex
                ->setResponse($this->httpClient->getLastResponse())
                ->setRequest($this->httpClient->getLastRequest())
            ;

            throw $ex;
        }

        if (false === array_key_exists('access_token', $data)) {
            throw new HttpResponseException('access_token is missing from response. '. $response->getContent());
        }

        return $data;
    }
1143792
public function acquireAccessToken() {
    $grant = new PasswordGrant($this->clientId, $this->clientSecret, $this->username, $this->password, $this->scopes);
    $tokens = $grant->getTokens();

    $accessToken = $tokens->{"access_token"};
    $refreshToken = $tokens->{"refresh_token"};
    $expiresAt = Util::calculateExpiryTime($tokens->{"expires_in"});

    return new RefreshableAccessToken($this->clientId, $this->clientSecret, $accessToken, $expiresAt, $refreshToken);
  }
885052
protected function accessTokenMiddleware()
    {
        return function (callable $handler) {
            return function (RequestInterface $request, array $options) use ($handler) {
                if (!$this->accessToken) {
                    return $handler($request, $options);
                }

                $field = $this->accessToken->getQueryName();
                $token = $this->accessToken->getToken();

                $request = $request->withUri(Uri::withQueryValue($request->getUri(), $field, $token));

                return $handler($request, $options);
            };
        };
    }
89734
protected function acquireAccessToken()
    {
        $accessToken = null;

        if ($this->refreshTokenGrantType) {
            // Get an access token using the stored refresh token.
            if ($this->refreshToken) {
                $this->refreshTokenGrantType->setRefreshToken($this->refreshToken->getToken());
            }
            if ($this->refreshTokenGrantType->hasRefreshToken()) {
                $accessToken = $this->refreshTokenGrantType->getToken();
            }
        }

        if (!$accessToken && $this->grantType) {
            // Get a new access token.
            $accessToken = $this->grantType->getToken();
        }

        return $accessToken ?: null;
    }
1244078
protected function requestAuthorizationToken(): string
    {
        $result = $this->options->getAuthorizationToken();
        if ($result === '') {
            $authRequest = new AuthRequest();
            $authRequest->setAgent($this->options->getAgent())
                        ->setAccessKey($this->options->getAccessKey())
                        ->setEnabledModNames($this->options->getEnabledModNames());

            $authResponse = $this->fetchResponse($authRequest);
            if ($authResponse instanceof AuthResponse) {
                $result = $authResponse->getAuthorizationToken();
                $this->options->setAuthorizationToken($result);
            }
        }
        return $result;
    }
36021
public function requestAccessToken()
    {
        $tokenUrl = $this->processUrl($this->server->getAccessTokenUrl());
        $accessToken = $this->instance->requestAccessToken($tokenUrl);
        $this->instance->setAccessToken($accessToken);

        return $accessToken;
    }
145542
public function dataWithToken()
    {
        $auth_token = $this->generateToken();
        AuthToken::setCurrent($auth_token);

        $current_auth_token = AuthToken::current();
        $data = $this->toArray();

        $data['token'] = $auth_token->toArray();

        return $data;
    }
643057
public function getAccessToken() {
    $session = $this->getSession();
    // either user session signed, or app signed
    if ($session) {
      return $session['access_token'];
    } else {
      return $this->getAppId() .'|'. $this->getApiSecret();
    }
  }
778306
public function getAccessTokenData()
    {
        if ($this->isOauth1()) {
            return array(
                'access_token'        => $this->_access_token,
                'access_token_secret' => $this->_access_token_secret,
                'expires'             => $this->_expires,
            );
        }

        return array(
            'access_token'  => $this->_access_token,
            'expires'       => $this->_expires,
            'token_type'    => $this->_token_type,
            'refresh_token' => $this->_refresh_token
        );
    }
909947
public function getToken()
    {
        if (!$this->_restclient) {
            $this->_restclient = new RestClient();
        }
        $data = ['grant_type'    => 'client_credentials',
            'client_id'     => $this->get('CLIENT_ID'),
            'client_secret' => $this->get('CLIENT_SECRET')];
        $this->_restclient->setHttpParam('address', $this->get('base_url'));
        $response = $this->_restclient->post("/oauth/token", ['json_data' => json_encode($data)]);
        return $response['body'];
    }