From 1224ca826f41e2d516b43a3c2a1c51a5cae36782 Mon Sep 17 00:00:00 2001 From: Sattvik Chakravarthy Date: Wed, 25 Sep 2024 16:13:43 +0530 Subject: [PATCH] fix: oauth plugin interface updates (#160) * fix: revoke * fix: pr comments * fix: oauth storage * fix: update * fix: add m2m token * fix: revoke and cleanup --- .../pluginInterface/oauth/OAuthStorage.java | 24 +++++++++++++++---- ...th2ClientAlreadyExistsForAppException.java | 24 ------------------- 2 files changed, 19 insertions(+), 29 deletions(-) delete mode 100644 src/main/java/io/supertokens/pluginInterface/oauth/exceptions/OAuth2ClientAlreadyExistsForAppException.java diff --git a/src/main/java/io/supertokens/pluginInterface/oauth/OAuthStorage.java b/src/main/java/io/supertokens/pluginInterface/oauth/OAuthStorage.java index 501d68bd..94cb5e78 100644 --- a/src/main/java/io/supertokens/pluginInterface/oauth/OAuthStorage.java +++ b/src/main/java/io/supertokens/pluginInterface/oauth/OAuthStorage.java @@ -19,19 +19,33 @@ import io.supertokens.pluginInterface.exceptions.StorageQueryException; import io.supertokens.pluginInterface.multitenancy.AppIdentifier; import io.supertokens.pluginInterface.nonAuthRecipe.NonAuthRecipeStorage; -import io.supertokens.pluginInterface.oauth.exceptions.OAuth2ClientAlreadyExistsForAppException; import java.util.List; public interface OAuthStorage extends NonAuthRecipeStorage { - public boolean doesClientIdExistForThisApp(AppIdentifier appIdentifier, String clientId) throws + public boolean doesClientIdExistForApp(AppIdentifier appIdentifier, String clientId) throws StorageQueryException; - public void addClientForApp(AppIdentifier appIdentifier, String clientId) throws StorageQueryException, - OAuth2ClientAlreadyExistsForAppException; + public void addOrUpdateClientForApp(AppIdentifier appIdentifier, String clientId, boolean isClientCredentialsOnly) throws StorageQueryException; public boolean removeAppClientAssociation(AppIdentifier appIdentifier, String clientId) throws StorageQueryException; - List listClientsForApp(AppIdentifier appIdentifier) throws StorageQueryException; + public List listClientsForApp(AppIdentifier appIdentifier) throws StorageQueryException; + + public void revoke(AppIdentifier appIdentifier, String targetType, String targetValue, long exp) throws StorageQueryException; + + public boolean isRevoked(AppIdentifier appIdentifier, String[] targetTypes, String[] targetValues, long issuedAt) throws StorageQueryException; + + public void addM2MToken(AppIdentifier appIdentifier, String clientId, long iat, long exp) throws StorageQueryException; + + public int countTotalNumberOfClientsForApp(AppIdentifier appIdentifier) throws StorageQueryException; + + public int countTotalNumberOfClientCredentialsOnlyClientsForApp(AppIdentifier appIdentifier) throws StorageQueryException; + + public int countTotalNumberOfM2MTokensCreatedSince(AppIdentifier appIdentifier, long since) throws StorageQueryException; + + public int countTotalNumberOfM2MTokensAlive(AppIdentifier appIdentifier) throws StorageQueryException; + + public void cleanUpExpiredAndRevokedTokens(AppIdentifier appIdentifier) throws StorageQueryException; } diff --git a/src/main/java/io/supertokens/pluginInterface/oauth/exceptions/OAuth2ClientAlreadyExistsForAppException.java b/src/main/java/io/supertokens/pluginInterface/oauth/exceptions/OAuth2ClientAlreadyExistsForAppException.java deleted file mode 100644 index e7521a44..00000000 --- a/src/main/java/io/supertokens/pluginInterface/oauth/exceptions/OAuth2ClientAlreadyExistsForAppException.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 2024, VRAI Labs and/or its affiliates. All rights reserved. - * - * This software is licensed under the Apache License, Version 2.0 (the - * "License") as published by the Apache Software Foundation. - * - * You may not use this file except in compliance with the License. You may - * obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -package io.supertokens.pluginInterface.oauth.exceptions; - -import java.io.Serial; - -public class OAuth2ClientAlreadyExistsForAppException extends Exception{ - @Serial - private static final long serialVersionUID = 2792232552559552544L; -}