{@inheritdoc}

@param string      $token
@param string      $clientId
@param string|null $userId
161627
public function setAccessToken($token, $clientId, $userId, $expiryTimestamp, $scope = null)
    {
        $authTokenDataMapper = $this->getTokenDataMapper(Entity\AccessToken::class);

        $client = $this->getClientDataMapper()->findByUuid($clientId);

        if (! $accessToken = $authTokenDataMapper->findByToken($token)) {
            $accessToken = new Entity\AccessToken(null, $token, $client);
        } else {
            $accessToken->setClient($client);
        }

        if ($userId) {
            $user = $this->getUserDataMapper()->findByUuid($userId);

            if ($user instanceof $this->userClass) {
                $accessToken->setUser($user);
            }
        }

        $expiryDate = is_int($expiryTimestamp) ? new DateTime('@' . $expiryTimestamp) : null;
        $accessToken->setExpiryDate($expiryDate);

        if ($scope) {
            $scopes = $this->getScopeDataMapper()->findScopes(explode(' ', $scope));
            $accessToken->setScopes($scopes);
        }

        $authTokenDataMapper->save($accessToken);
    }
363732
public static void initialize(String token) {
    if (token == null) {
      throw new IllegalArgumentException("Token should be defined.");
    }
    initialize(new ClientProperties(token, null, null));
  }
699905
public function execute($tokenData = null, $userId = null)
    {
        $batch   = $this->getBatch();
        $tracker = $this->loader->getTracker();
        $token   = $tracker->getToken($tokenData);

        if ($token->isCompleted()) {
            $respTrack = $token->getRespondentTrack();
            $userId    = $userId ? $userId : $this->loader->getCurrentUser()->getUserId();

            if ($result = $respTrack->handleRoundCompletion($token, $userId)) {
                $a = $batch->addToCounter('roundCompletionCauses');
                $b = $batch->addToCounter('roundCompletionChanges', $result);
                $batch->setMessage('roundCompletionChanges',
                        sprintf($this->_('%d token round completion events caused changed to %d tokens.'), $a, $b)
                        );
            }

            $trackId = $respTrack->getRespondentTrackId();
            $batch->setTask('Tracker_CheckTrackTokens', 'chktrck-' . $trackId, $trackId, $userId);
        }

        // Free memory
        $tracker->removeToken($token);
    }
144589
public function create(array $card, $customerId = null) {
        $expiryMonth    = str_pad($card['expiryMonth'], 2, '0', STR_PAD_LEFT);
        $expiryYear     = $card['expiryYear'];
        $expiresAt      = $this->getExpirationDate($expiryMonth, $expiryYear);
        $ccType         = $this->ccTypeAdapter->getFromGateway($card['paymentMethod']);

        /** @var PaymentTokenInterface $paymentToken */
        $paymentToken = $this->creditCardTokenFactory->create();
        $paymentToken->setExpiresAt($expiresAt);

        if( array_key_exists('id', $card) ) {
            $paymentToken->setGatewayToken($card['id']);
        }

        $tokenDetails = [
            'type'              => $ccType,
            'maskedCC'          => $card['last4'],
            'expirationDate'    => $expiryMonth . '/' . $expiryYear,
        ];

        $paymentToken->setTokenDetails($this->convertDetailsToJSON($tokenDetails));
        $paymentToken->setIsActive(true);
        $paymentToken->setPaymentMethodCode(ConfigProvider::CODE);

        if($customerId) {
            $paymentToken->setCustomerId($customerId);
        }

        $paymentToken->setPublicHash($this->generatePublicHash($paymentToken));

        return $paymentToken;
    }
955923
public function setEmailToken($userid = null)
	{
		$this->debug->groupCollapsed(__METHOD__);
		if (!isset($userid)) {
			$userid = $this->userid;
		}
		$this->debug->log('userid', $userid);
		$token = $this->genToken();
		/*
			remove any existing token
		*/
		$where = array( 'userid' => $userid);
		$response = $this->db->rowMan('email_tokens', null, $where);
		/*
			store hashed token in db
		*/
		$vals = array(
			'userid'		=> $userid,
			'token_hash'	=> sha1($token),
		);
		$response = $this->db->rowMan('email_tokens', $vals);
		$this->log('pwForgotTokenGen', $userid);	// @todo forgot_token_gen??
		$return = $response !== false
			? base64_encode($token)
			: false;
		$this->debug->groupEnd();
		return $return;
	}
360023
public function create(ApiClientInterface $client, UserInterface $user = null)
    {
        $tokenClass = $this->tokenClass;

        return $tokenClass::create($client, $user);
    }
506857
public function create($data, $userId = null)
    {
        if (isset($userId)) {
            return $this->client()->put($data, 'users/{userId}', ['userId' => $userId]);
        }

        return $this->client()->post($data, 'users');
    }
272598
public function activate($userId, $token, array $queryParams = [])
    {
        $response = $this->api->users()->activate($userId, $token, $queryParams);

        return new UserResponse($response);
    }
1196858
public function deleteServerToken ( $consumer_key, $token, $user_id, $user_is_admin = false )
	{
		if ($user_is_admin)
		{
			$this->query('
				DELETE oauth_consumer_token 
				FROM oauth_consumer_token
						JOIN oauth_consumer_registry
						ON oct_ocr_id_ref = ocr_id
				WHERE ocr_consumer_key	= \'%s\'
				  AND oct_token			= \'%s\'
				', $consumer_key, $token);
		}
		else
		{
			$this->query('
				DELETE oauth_consumer_token 
				FROM oauth_consumer_token
						JOIN oauth_consumer_registry
						ON oct_ocr_id_ref = ocr_id
				WHERE ocr_consumer_key	= \'%s\'
				  AND oct_token			= \'%s\'
				  AND oct_usa_id_ref	= %d
				', $consumer_key, $token, $user_id);
		}
	}
636896
public function validateToken($userToken, $name = null)
    {
        $token = $this->getToken($name);
        return !is_null($userToken) && $token === $userToken;
    }
889827
public function validate($userId, $accessToken, &$errorMessage = null)
    {
        $client = new Client($this->uri . '/me', $this->clientOptions);
        $client->setMethod('GET');
        $params = ArrayUtils::merge($this->endpointParams, ['access_token' => $accessToken]);
        $client->setParameterGet($params);

        $userData = $this->decodeBody($client->send());

        if (isset($userData->error)) {
            throw new Exception\ClientException($userData->error->message, 400);
        }

        if (! isset($userData->id)) {
            throw new Exception\ClientException('Invalid data returned by provider', 400);
        }

        if ($userData->id !== $userId) {
            $errorMessage = 'user_id mismatch';

            return false;
        }

        $this->userId = $userData->id;
        unset($userData->id);

        $this->userData = (array) $userData;

        return true;
    }
632882
public function setToken(UserSession $user, Token $token)
    {
        $item = $this->cacheItemPool->getItem($this->cacheKey($user));
        $item->set($token);
        // @todo Test that these values are compatible.
        $item->expiresAfter($token->getLifetime());
        $this->cacheItemPool->save($item);
    }
357644
public function saveSubscription(int $userId = null) : void
    {
        $json = \file_get_contents('php://input');

        if (!$json)
        {
            return;
        }

        $data = \json_decode($json, true);

        if (!$data || empty($data['endpoint']) || empty($data['publicKey']) || empty($data['authToken']))
        {
            return;
        }

        $row = $this->subscriptionTable->findActive()->where('endpoint', $data['endpoint'])->fetch();

        switch ($this->request->getMethod()) {
            case 'POST':
            case 'PUT':
            {
                if ($row)
                {
                    $row->update([
                        'user_id' => $userId ?: $row->user_id ?: null,
                        'key' => $data['publicKey'],
                        'token' => $data['authToken'],
                        'encoding' => $data['contentEncoding']
                    ]);
                    
                    return;
                }

                $row = $this->subscriptionTable->insert([
                    'user_id' => $userId,
                    'endpoint' => $data['endpoint'],
                    'key' => $data['publicKey'],
                    'token' => $data['authToken'],
                    'encoding' => $data['contentEncoding']
                ]);

                $this->sendNotification($row, 'Notifications enabled!', true);

                return;
            }
            case 'DELETE':
            {
                if ($row)
                {
                    $row->update([
                        'active' => 0
                    ]);
                }

                return;
            }
            default:
                throw new \Nette\Application\BadRequestException();
        }
    }
1275416
public function setClientUser($client_id, $user_id)
    {
        if ($this->getClientUser($client_id, $user_id)) {
            return true;
        } else {
            $created_at = date('Y-m-d H:i:s');
            $sql        = 'INSERT INTO %s (client_id, user_id, created_at) VALUES (:client_id, :user_id, :created_at)';
            $sql        = sprintf($sql, $this->config['client_user_table']);

            $params = array_map('trim', compact('client_id', 'user_id', 'created_at'));

            return $this->db->prepare($sql)->execute($params);
        }
    }
53950
public function updateRememberToken(UserContract $user, $token)
    {
        $this->conn->table($this->table)
                ->where($user->getAuthIdentifierName(), $user->getAuthIdentifier())
                ->update([$user->getRememberTokenName() => $token]);
    }
360785
public function create(User $user, $username, $password)
    {
        $this->authenticationService->create($user, $username, $password);
    }
402171
public function verify($token, $messageId = null)
    {
        $messageId = ($messageId !== null) ? $messageId : $this->messageId;

        // Throw error for empty token or empty message id, because the server will not handle this
        if (empty($token)) {
            throw new Verification\EmptyTokenException();
        }
        if (empty($messageId)) {
            throw new Verification\EmptyMessageIdException();
        }

        try {
            $this->sendApiCall(self::ACTION_RETRIEVE, sprintf('%s/%s?token=%s', $this->getCreateUrl(), urlencode($messageId), $token));
        } catch (Exception $e) {
            if (Verification\Exception::isVerificationException($e)) {
                throw new Verification\Exception($e);
            } else {
                throw $e;
            }
        }
    }