diff --git a/CHANGELOG.md b/CHANGELOG.md index d8f45ac6..6654366e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,18 +23,21 @@ CREATE TABLE IF NOT EXISTS oauth_clients ( FOREIGN KEY(app_id) REFERENCES apps(app_id) ON DELETE CASCADE ); -CREATE TABLE IF NOT EXISTS oauth_revoke ( +CREATE TABLE IF NOT EXISTS oauth_sessions ( + gid VARCHAR(255), app_id VARCHAR(64) DEFAULT 'public', - target_type VARCHAR(16) NOT NULL, - target_value VARCHAR(128) NOT NULL, - timestamp BIGINT NOT NULL, + client_id VARCHAR(255) NOT NULL, + session_handle VARCHAR(128), + external_refresh_token VARCHAR(255) UNIQUE, + internal_refresh_token VARCHAR(255) UNIQUE, + jti TEXT NOT NULL, exp BIGINT NOT NULL, - PRIMARY KEY (app_id, target_type, target_value), - FOREIGN KEY(app_id) REFERENCES apps(app_id) ON DELETE CASCADE + PRIMARY KEY (gid), + FOREIGN KEY(app_id, client_id) REFERENCES oauth_clients(app_id, client_id) ON DELETE CASCADE ); -CREATE INDEX IF NOT EXISTS oauth_revoke_timestamp_index ON oauth_revoke(timestamp DESC, app_id DESC); -CREATE INDEX IF NOT EXISTS oauth_revoke_exp_index ON oauth_revoke(exp DESC); +CREATE INDEX IF NOT EXISTS oauth_session_exp_index ON oauth_sessions(exp DESC); +CREATE INDEX IF NOT EXISTS oauth_session_external_refresh_token_index ON oauth_sessions(app_id, external_refresh_token DESC); CREATE TABLE IF NOT EXISTS oauth_m2m_tokens ( app_id VARCHAR(64) DEFAULT 'public', diff --git a/src/main/java/io/supertokens/storage/postgresql/Start.java b/src/main/java/io/supertokens/storage/postgresql/Start.java index fc2ee5fa..a7800301 100644 --- a/src/main/java/io/supertokens/storage/postgresql/Start.java +++ b/src/main/java/io/supertokens/storage/postgresql/Start.java @@ -3101,33 +3101,6 @@ public int countUsersThatHaveMoreThanOneLoginMethodOrTOTPEnabledAndActiveSince(A } } - @Override - public boolean doesOAuthClientIdExist(AppIdentifier appIdentifier, String clientId) - throws StorageQueryException { - try { - return OAuthQueries.doesOAuthClientIdExist(this, clientId, appIdentifier); - } catch (SQLException e) { - throw new StorageQueryException(e); - } - } - - @Override - public void addOrUpdateOauthClient(AppIdentifier appIdentifier, String clientId, boolean isClientCredentialsOnly) - throws StorageQueryException, TenantOrAppNotFoundException { - try { - OAuthQueries.addOrUpdateOauthClient(this, appIdentifier, clientId, isClientCredentialsOnly); - } catch (SQLException e) { - PostgreSQLConfig config = Config.getConfig(this); - if (e instanceof PSQLException) { - ServerErrorMessage serverMessage = ((PSQLException) e).getServerErrorMessage(); - - if (isForeignKeyConstraintError(serverMessage, config.getOAuthClientsTable(), "app_id")) { - throw new TenantOrAppNotFoundException(appIdentifier); - } - } - throw new StorageQueryException(e); - } - } @Override public boolean deleteOAuthClient(AppIdentifier appIdentifier, String clientId) throws StorageQueryException { @@ -3138,156 +3111,7 @@ public boolean deleteOAuthClient(AppIdentifier appIdentifier, String clientId) t } } - @Override - public List listOAuthClients(AppIdentifier appIdentifier) throws StorageQueryException { - try { - return OAuthQueries.listOAuthClients(this, appIdentifier); - } catch (SQLException e) { - throw new StorageQueryException(e); - } - } - - @Override - public void revokeOAuthTokensBasedOnTargetFields(AppIdentifier appIdentifier, OAuthRevokeTargetType targetType, String targetValue, long exp) - throws StorageQueryException, TenantOrAppNotFoundException { - try { - OAuthQueries.revokeOAuthTokensBasedOnTargetFields(this, appIdentifier, targetType, targetValue, exp); - } catch (SQLException e) { - PostgreSQLConfig config = Config.getConfig(this); - if (e instanceof PSQLException) { - ServerErrorMessage serverMessage = ((PSQLException) e).getServerErrorMessage(); - - if (isForeignKeyConstraintError(serverMessage, config.getOAuthRevokeTable(), "app_id")) { - throw new TenantOrAppNotFoundException(appIdentifier); - } - } - throw new StorageQueryException(e); - } - - } - - @Override - public boolean isOAuthTokenRevokedBasedOnTargetFields(AppIdentifier appIdentifier, OAuthRevokeTargetType[] targetTypes, String[] targetValues, long issuedAt) - throws StorageQueryException { - try { - return OAuthQueries.isOAuthTokenRevokedBasedOnTargetFields(this, appIdentifier, targetTypes, targetValues, issuedAt); - } catch (SQLException e) { - throw new StorageQueryException(e); - } - } - - @Override - public void addOAuthM2MTokenForStats(AppIdentifier appIdentifier, String clientId, long iat, long exp) - throws StorageQueryException, OAuthClientNotFoundException { - try { - OAuthQueries.addOAuthM2MTokenForStats(this, appIdentifier, clientId, iat, exp); - } catch (SQLException e) { - PostgreSQLConfig config = Config.getConfig(this); - if (e instanceof PSQLException) { - ServerErrorMessage serverMessage = ((PSQLException) e).getServerErrorMessage(); - if (isForeignKeyConstraintError(serverMessage, config.getOAuthM2MTokensTable(), "client_id")) { - throw new OAuthClientNotFoundException(); - } - } - throw new StorageQueryException(e); - } - } - - @Override - public void cleanUpExpiredAndRevokedOAuthTokensList() throws StorageQueryException { - try { - OAuthQueries.cleanUpExpiredAndRevokedOAuthTokensList(this); - } catch (SQLException e) { - throw new StorageQueryException(e); - } - } - - @Override - public void addOAuthLogoutChallenge(AppIdentifier appIdentifier, String challenge, String clientId, - String postLogoutRedirectionUri, String sessionHandle, String state, long timeCreated) - throws StorageQueryException, DuplicateOAuthLogoutChallengeException, OAuthClientNotFoundException { - try { - OAuthQueries.addOAuthLogoutChallenge(this, appIdentifier, challenge, clientId, postLogoutRedirectionUri, sessionHandle, state, timeCreated); - } catch (SQLException e) { - PostgreSQLConfig config = Config.getConfig(this); - if (e instanceof PSQLException) { - ServerErrorMessage serverMessage = ((PSQLException) e).getServerErrorMessage(); - - if (isPrimaryKeyError(serverMessage, config.getOAuthLogoutChallengesTable())) { - throw new DuplicateOAuthLogoutChallengeException(); - } else if (isForeignKeyConstraintError(serverMessage, config.getOAuthLogoutChallengesTable(), "client_id")) { - throw new OAuthClientNotFoundException(); - } - } - throw new StorageQueryException(e); - } - } - - @Override - public OAuthLogoutChallenge getOAuthLogoutChallenge(AppIdentifier appIdentifier, String challenge) throws StorageQueryException { - try { - return OAuthQueries.getOAuthLogoutChallenge(this, appIdentifier, challenge); - } catch (SQLException e) { - throw new StorageQueryException(e); - } - } - - @Override - public void deleteOAuthLogoutChallenge(AppIdentifier appIdentifier, String challenge) throws StorageQueryException { - try { - OAuthQueries.deleteOAuthLogoutChallenge(this, appIdentifier, challenge); - } catch (SQLException e) { - throw new StorageQueryException(e); - } - } - - @Override - public void deleteOAuthLogoutChallengesBefore(long time) throws StorageQueryException { - try { - OAuthQueries.deleteOAuthLogoutChallengesBefore(this, time); - } catch (SQLException e) { - throw new StorageQueryException(e); - } - } - - @Override - public int countTotalNumberOfOAuthClients(AppIdentifier appIdentifier) throws StorageQueryException { - try { - return OAuthQueries.countTotalNumberOfClients(this, appIdentifier, false); - } catch (SQLException e) { - throw new StorageQueryException(e); - } - } - - @Override - public int countTotalNumberOfClientCredentialsOnlyOAuthClients(AppIdentifier appIdentifier) - throws StorageQueryException { - try { - return OAuthQueries.countTotalNumberOfClients(this, appIdentifier, true); - } catch (SQLException e) { - throw new StorageQueryException(e); - } - } - - @Override - public int countTotalNumberOfOAuthM2MTokensCreatedSince(AppIdentifier appIdentifier, long since) - throws StorageQueryException { - try { - return OAuthQueries.countTotalNumberOfOAuthM2MTokensCreatedSince(this, appIdentifier, since); - } catch (SQLException e) { - throw new StorageQueryException(e); - } - } - - @Override - public int countTotalNumberOfOAuthM2MTokensAlive(AppIdentifier appIdentifier) throws StorageQueryException { - try { - return OAuthQueries.countTotalNumberOfOAuthM2MTokensAlive(this, appIdentifier); - } catch (SQLException e) { - throw new StorageQueryException(e); - } - } @TestOnly public int getDbActivityCount(String dbname) throws SQLException, StorageQueryException { @@ -3335,15 +3159,6 @@ public void addOrUpdateOauthClient(AppIdentifier appIdentifier, String clientId, } } - @Override - public boolean deleteOAuthClient(AppIdentifier appIdentifier, String clientId) throws StorageQueryException { - try { - return OAuthQueries.deleteOAuthClient(this, clientId, appIdentifier); - } catch (SQLException e) { - throw new StorageQueryException(e); - } - } - @Override public List getOAuthClients(AppIdentifier appIdentifier, List clientIds) throws StorageQueryException { try { diff --git a/src/main/java/io/supertokens/storage/postgresql/config/PostgreSQLConfig.java b/src/main/java/io/supertokens/storage/postgresql/config/PostgreSQLConfig.java index 3cdf80aa..095badc8 100644 --- a/src/main/java/io/supertokens/storage/postgresql/config/PostgreSQLConfig.java +++ b/src/main/java/io/supertokens/storage/postgresql/config/PostgreSQLConfig.java @@ -434,22 +434,10 @@ public String getDashboardSessionsTable() { return addSchemaAndPrefixToTableName("dashboard_user_sessions"); } - public String getOAuthClientsTable() { - return addSchemaAndPrefixToTableName("oauth_clients"); - } - public String getOAuthRevokeTable() { return addSchemaAndPrefixToTableName("oauth_revoke"); } - public String getOAuthM2MTokensTable() { - return addSchemaAndPrefixToTableName("oauth_m2m_tokens"); - } - - public String getOAuthLogoutChallengesTable() { - return addSchemaAndPrefixToTableName("oauth_logout_challenges"); - } - public String getTotpUsersTable() { return addSchemaAndPrefixToTableName("totp_users"); }