/** * Store authorization code * @param IAuthorizationCode $authorizationCode * @throws InvalidScopeException */ public function store(IAuthorizationCode $authorizationCode) { $this->context->insert($this->getTable(), array('authorization_code' => $authorizationCode->getAuthorizationCode(), 'client_id' => $authorizationCode->getClientId(), 'user_id' => $authorizationCode->getUserId(), 'expires_at' => $authorizationCode->getExpires()))->execute(); $this->context->begin(); try { foreach ($authorizationCode->getScope() as $scope) { $this->context->insert($this->getScopeTable(), array('authorization_code' => $authorizationCode->getAuthorizationCode(), 'scope_name' => $scope))->execute(); } } catch (\PDOException $e) { // MySQL error 1452 - Cannot add or update a child row: a foreign key constraint fails if (in_array(1452, $e->errorInfo)) { throw new InvalidScopeException(); } throw $e; } $this->context->commit(); }
/** * @inheritDoc */ function refreshToken($refreshToken) { $this->purgeOldTokens(); $token = $this->refreshTokenToToken($refreshToken); $this->dbConnection->begin(); // Check for existing token and lock it $existingToken = $this->dbConnection->query('SELECT * FROM %n', $this->tableName, 'WHERE [token] = %s', $token, 'FOR UPDATE')->fetch(); // No matching token found if ($existingToken === FALSE) { $this->dbConnection->rollback(); return FALSE; } $newToken = $this->generateNewToken(); $dt = new \DateTime(); $dt->modify("+" . $this->tokenTtl . " seconds"); $this->dbConnection->query('UPDATE %n', $this->tableName, 'SET [token] = %s,', $newToken, '[expires] = %t', $dt, 'WHERE [token] = %s', $token); $this->dbConnection->commit(); return new Token($newToken, $this->tokenTtl, $this->generateRefreshToken($newToken), $existingToken->parameters); }
/** * Commit transaction * * @param null $savepoint * * @throws \DibiException */ public function commit($savepoint = NULL) { $this->database->commit($savepoint); }
/** * Potvrdí transakci. * @param string $savepoint */ public function commit($savepoint = NULL) { $this->connection->commit($savepoint); }