Save the access & refresh tokens for an authorized user.

@param \League\OAuth2\Client\Token\AccessToken $token
@return void
491811
public function persistUserToken(AccessToken $token)
    {
        $northstarId = $token->getResourceOwnerId();

        /** @var NorthstarUserContract $user */
        $user = $this->getUser($northstarId);

        // If user hasn't tried to log in before, make them a local record.
        if (! $user) {
            $user = $this->createModel();
            $user->setNorthstarIdentifier($northstarId);
        }

        // And then update their token details.
        $user->setOAuthToken($token);
        $user->save();

        // Finally, tell the guard about the new token if this is the currently
        // logged-in user. (Otherwise, they wouldn't get the new token until
        // the following page load.)
        if (auth()->user() && auth()->user()->getNorthstarIdentifier() === $northstarId) {
            auth()->setUser($user);
        }
    }
571663
protected function refreshAccessToken($token)
    {
        switch ($this->grant) {
            case 'provided_token':
                throw new UnauthorizedException('[internal]', 'The provided token expired.');

            case 'client_credentials':
                return $this->getTokenByClientCredentialsGrant();

            case 'authorization_code':
                return $this->getTokenByRefreshTokenGrant($token);

            default:
                throw new \Exception('Unsupported grant type. Check $this->grant.');
        }
    }
685134
public function saveToken(Token $token)
    {
        $this->db
            ->merge('ucms_user_token')
            ->key(['uid' => $token->uid])
            ->fields([
                'token' => $token->token,
                'expiration_date' => $token->expiration_date->format('Y-m-d H:i:s'),
            ])
            ->execute();
    }
808705
public function saveAccessTokenToDB($accessToken)
	{
		$data = array(
			'access_token' => $accessToken,
			'created_at' => \Carbon\Carbon::now(),
		);

		if(\Config::get('laravel-youtube::auth') == true) {
			$data['user_id'] = \Auth::user()->id;
		}

		\DB::table(\Config::get('laravel-youtube::table_name'))->insert($data);
	}
290793
public function store ($hash, AccessToken $accessToken)
    {
        $key = $this->prefix . $hash;
        $contents = json_encode($accessToken);

        $this->memcached->set($key, $contents);
    }
393121
private function refreshAccessToken(Provider $provider, $userId, AccessToken $accessToken)
    {
        // prepare access_token request
        $tokenRequestData = [
            'grant_type' => 'refresh_token',
            'refresh_token' => $accessToken->getRefreshToken(),
            'scope' => $accessToken->getScope(),
        ];

        $response = $this->httpClient->send(
            Request::post(
                $provider->getTokenEndpoint(),
                $tokenRequestData,
                self::getAuthorizationHeader(
                    $provider->getClientId(),
                    $provider->getSecret()
                )
            )
        );

        if (false === $response->isOkay()) {
            $responseData = $response->json();
            if (\array_key_exists('error', $responseData) && 'invalid_grant' === $responseData['error']) {
                // delete the access_token, we assume the user revoked it, that
                // is why we get "invalid_grant"
                $this->tokenStorage->deleteAccessToken($userId, $accessToken);

                return false;
            }

            throw new TokenException('unable to refresh access_token', $response);
        }

        // delete old AccessToken as we'll write a new one anyway...
        $this->tokenStorage->deleteAccessToken($userId, $accessToken);

        $accessToken = AccessToken::fromRefreshResponse(
            $provider,
            $this->dateTime,
            $response->json(),
            // provide the old AccessToken to borrow some fields if the server
            // does not provide them on "refresh"
            $accessToken
        );

        // store the refreshed AccessToken
        $this->tokenStorage->storeAccessToken($userId, $accessToken);

        return $accessToken;
    }
1119839
def save_token(self, access_token):
        
        key = self._generate_cache_key(access_token.token)
        self.mc.set(key, access_token.__dict__)

        unique_token_key = self._unique_token_key(access_token.client_id,
                                                  access_token.grant_type,
                                                  access_token.user_id)
        self.mc.set(self._generate_cache_key(unique_token_key),
                    access_token.__dict__)

        if access_token.refresh_token is not None:
            rft_key = self._generate_cache_key(access_token.refresh_token)
            self.mc.set(rft_key, access_token.__dict__)
389394
public function getResourceOwner(AccessToken $token)
    {
        $this->openId = $this->getOpenId($token);

        return parent::getResourceOwner($token);
    }
170717
public function updateBitlyAccessToken($access_token)
    {
        $activeSystem = $this->getActiveSystem();
        $activeSystem->setBitlyAccessToken($access_token);
        $this->em->persist($activeSystem);
        $this->em->flush();
    }
787238
protected function store_token($token) {
        global $SESSION;

        $this->accesstoken = $token;
        $name = $this->get_tokenname();

        if ($token !== null) {
            $SESSION->{$name} = $token;
        } else {
            unset($SESSION->{$name});
        }
    }
922378
public function put($accessToken)
	{
		if ($accessToken === null)
			return unlink($this->file);

		file_put_contents($this->file, base64_encode(serialize($accessToken)));

		return file_exists($this->file);
	}
86492
public function onGenerateAccessToken()
    {
        if (!User::isAccessTokenValid($this->_user->access_token)) {
            $this->_user->generateAccessToken();
            $this->_user->save(false);
        }
    }
1361275
public function expireAuthorizationCode($token)
    {
        $authCodeDataMapper = $this->getTokenDataMapper(Entity\AuthorizationCode::class);

        $authorizationCode = $authCodeDataMapper->findByToken($token);
        $authorizationCode->setExpiryDate(new DateTime());

        $authCodeDataMapper->save($authorizationCode);
    }
1044471
public function setAccessToken($token)
    {
        $accessTokenAttribute = $this->accessTokenAttribute;
        return (is_string($accessTokenAttribute) && !empty($accessTokenAttribute)) ? $this->$accessTokenAttribute = $token : null;
    }
1202003
public function setToken($token)
    {
        $this->token = $token;
        $this->username = '';
        $this->password = '';
        $this->accessToken = '';
        return $this;
    }
78046
public function refreshToken($accessToken = null)
    {
        $accessToken = $accessToken ?: $this->accessToken;
        $this->accessToken = $this->provider->getAccessToken('refresh_token', [
            'refresh_token' => $accessToken->getRefreshToken()
        ]);
        return $this->accessToken;
    }
909473
public function setAccessToken(AccessToken $accessToken)
    {
        if (!$accessToken->isValid()) {
            $accessToken->refresh();
        }

        $this->accessToken = $accessToken;
    }