From eb2392476ca2bc47c0bf6e96b6b4bd8228979265 Mon Sep 17 00:00:00 2001 From: Tamas Soltesz Date: Tue, 30 Jul 2024 11:24:55 +0200 Subject: [PATCH 1/7] feat: oauth recipe id, sqlstoreage and response type --- .../pluginInterface/RECIPE_ID.java | 2 +- .../oauth/OAuthAuthResponse.java | 34 +++++++++++++++++++ .../oauth/sqlStorage/OAuthSQLStorage.java | 23 +++++++++++++ 3 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 src/main/java/io/supertokens/pluginInterface/oauth/OAuthAuthResponse.java create mode 100644 src/main/java/io/supertokens/pluginInterface/oauth/sqlStorage/OAuthSQLStorage.java diff --git a/src/main/java/io/supertokens/pluginInterface/RECIPE_ID.java b/src/main/java/io/supertokens/pluginInterface/RECIPE_ID.java index 6aee253f..d9d0848f 100644 --- a/src/main/java/io/supertokens/pluginInterface/RECIPE_ID.java +++ b/src/main/java/io/supertokens/pluginInterface/RECIPE_ID.java @@ -22,7 +22,7 @@ public enum RECIPE_ID { EMAIL_PASSWORD("emailpassword"), THIRD_PARTY("thirdparty"), SESSION("session"), EMAIL_VERIFICATION("emailverification"), JWT("jwt"), PASSWORDLESS("passwordless"), USER_METADATA("usermetadata"), USER_ROLES("userroles"), USER_ID_MAPPING("useridmapping"), DASHBOARD("dashboard"), TOTP("totp"), - MULTITENANCY("multitenancy"), ACCOUNT_LINKING("accountlinking"), MFA("mfa"); + MULTITENANCY("multitenancy"), ACCOUNT_LINKING("accountlinking"), MFA("mfa"), OAUTH("oauth"); private final String name; diff --git a/src/main/java/io/supertokens/pluginInterface/oauth/OAuthAuthResponse.java b/src/main/java/io/supertokens/pluginInterface/oauth/OAuthAuthResponse.java new file mode 100644 index 00000000..61e95e1b --- /dev/null +++ b/src/main/java/io/supertokens/pluginInterface/oauth/OAuthAuthResponse.java @@ -0,0 +1,34 @@ +/* + * 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; + +import java.util.List; + +public class OAuthAuthResponse { + public final String redirectTo; + public final List cookies; + + public OAuthAuthResponse(String redirectTo, List cookies) { + this.redirectTo = redirectTo; + this.cookies = cookies; + } + + @Override + public String toString() { + return "redirectTo: " + redirectTo; + } +} diff --git a/src/main/java/io/supertokens/pluginInterface/oauth/sqlStorage/OAuthSQLStorage.java b/src/main/java/io/supertokens/pluginInterface/oauth/sqlStorage/OAuthSQLStorage.java new file mode 100644 index 00000000..e6814860 --- /dev/null +++ b/src/main/java/io/supertokens/pluginInterface/oauth/sqlStorage/OAuthSQLStorage.java @@ -0,0 +1,23 @@ +/* + * 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.sqlStorage; + +import io.supertokens.pluginInterface.oauth.OAuthStorage; +import io.supertokens.pluginInterface.sqlStorage.SQLStorage; + +public interface OAuthSQLStorage extends OAuthStorage, SQLStorage { +} From a1c99b5f13bf4a3876219e4673832592781b989e Mon Sep 17 00:00:00 2001 From: Tamas Soltesz Date: Wed, 31 Jul 2024 08:56:24 +0200 Subject: [PATCH 2/7] fix: review fixes --- .../oauth/OAuthAuthResponse.java | 34 ------------------- .../pluginInterface/oauth/OAuthStorage.java | 8 ++++- .../oauth/sqlStorage/OAuthSQLStorage.java | 1 + 3 files changed, 8 insertions(+), 35 deletions(-) delete mode 100644 src/main/java/io/supertokens/pluginInterface/oauth/OAuthAuthResponse.java diff --git a/src/main/java/io/supertokens/pluginInterface/oauth/OAuthAuthResponse.java b/src/main/java/io/supertokens/pluginInterface/oauth/OAuthAuthResponse.java deleted file mode 100644 index 61e95e1b..00000000 --- a/src/main/java/io/supertokens/pluginInterface/oauth/OAuthAuthResponse.java +++ /dev/null @@ -1,34 +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; - -import java.util.List; - -public class OAuthAuthResponse { - public final String redirectTo; - public final List cookies; - - public OAuthAuthResponse(String redirectTo, List cookies) { - this.redirectTo = redirectTo; - this.cookies = cookies; - } - - @Override - public String toString() { - return "redirectTo: " + redirectTo; - } -} diff --git a/src/main/java/io/supertokens/pluginInterface/oauth/OAuthStorage.java b/src/main/java/io/supertokens/pluginInterface/oauth/OAuthStorage.java index 31c0089f..ea762612 100644 --- a/src/main/java/io/supertokens/pluginInterface/oauth/OAuthStorage.java +++ b/src/main/java/io/supertokens/pluginInterface/oauth/OAuthStorage.java @@ -16,9 +16,15 @@ package io.supertokens.pluginInterface.oauth; +import io.supertokens.pluginInterface.exceptions.StorageQueryException; import io.supertokens.pluginInterface.multitenancy.AppIdentifier; import io.supertokens.pluginInterface.nonAuthRecipe.NonAuthRecipeStorage; +import io.supertokens.pluginInterface.sqlStorage.TransactionConnection; public interface OAuthStorage extends NonAuthRecipeStorage { - public boolean doesClientIdExistForThisApp(AppIdentifier appIdentifier, String clientId); + + public boolean doesClientIdExistForThisApp(AppIdentifier appIdentifier, String clientId) throws + StorageQueryException; + + public void addClientForApp(AppIdentifier appIdentifier, String clientId) throws StorageQueryException; } diff --git a/src/main/java/io/supertokens/pluginInterface/oauth/sqlStorage/OAuthSQLStorage.java b/src/main/java/io/supertokens/pluginInterface/oauth/sqlStorage/OAuthSQLStorage.java index e6814860..df28bdef 100644 --- a/src/main/java/io/supertokens/pluginInterface/oauth/sqlStorage/OAuthSQLStorage.java +++ b/src/main/java/io/supertokens/pluginInterface/oauth/sqlStorage/OAuthSQLStorage.java @@ -20,4 +20,5 @@ import io.supertokens.pluginInterface.sqlStorage.SQLStorage; public interface OAuthSQLStorage extends OAuthStorage, SQLStorage { + } From fc2cc1d28d23af63a3491ecde799b065b49ea513 Mon Sep 17 00:00:00 2001 From: Tamas Soltesz Date: Wed, 31 Jul 2024 11:20:52 +0200 Subject: [PATCH 3/7] fix: review fixes --- .../pluginInterface/oauth/OAuthStorage.java | 4 +++- .../ClientAlreadyExistsForAppException.java | 24 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 src/main/java/io/supertokens/pluginInterface/oauth/exceptions/ClientAlreadyExistsForAppException.java diff --git a/src/main/java/io/supertokens/pluginInterface/oauth/OAuthStorage.java b/src/main/java/io/supertokens/pluginInterface/oauth/OAuthStorage.java index ea762612..6498406b 100644 --- a/src/main/java/io/supertokens/pluginInterface/oauth/OAuthStorage.java +++ b/src/main/java/io/supertokens/pluginInterface/oauth/OAuthStorage.java @@ -19,6 +19,7 @@ import io.supertokens.pluginInterface.exceptions.StorageQueryException; import io.supertokens.pluginInterface.multitenancy.AppIdentifier; import io.supertokens.pluginInterface.nonAuthRecipe.NonAuthRecipeStorage; +import io.supertokens.pluginInterface.oauth.exceptions.ClientAlreadyExistsForAppException; import io.supertokens.pluginInterface.sqlStorage.TransactionConnection; public interface OAuthStorage extends NonAuthRecipeStorage { @@ -26,5 +27,6 @@ public interface OAuthStorage extends NonAuthRecipeStorage { public boolean doesClientIdExistForThisApp(AppIdentifier appIdentifier, String clientId) throws StorageQueryException; - public void addClientForApp(AppIdentifier appIdentifier, String clientId) throws StorageQueryException; + public void addClientForApp(AppIdentifier appIdentifier, String clientId) throws StorageQueryException, + ClientAlreadyExistsForAppException; } diff --git a/src/main/java/io/supertokens/pluginInterface/oauth/exceptions/ClientAlreadyExistsForAppException.java b/src/main/java/io/supertokens/pluginInterface/oauth/exceptions/ClientAlreadyExistsForAppException.java new file mode 100644 index 00000000..3ad491d1 --- /dev/null +++ b/src/main/java/io/supertokens/pluginInterface/oauth/exceptions/ClientAlreadyExistsForAppException.java @@ -0,0 +1,24 @@ +/* + * 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 ClientAlreadyExistsForAppException extends Exception{ + @Serial + private static final long serialVersionUID = 2792232552559552544L; +} From 4c362c3f294b2b9c4bc4ea5112afe9490a751a02 Mon Sep 17 00:00:00 2001 From: Tamas Soltesz Date: Thu, 1 Aug 2024 09:28:34 +0200 Subject: [PATCH 4/7] fix: review fix - renamed exception --- .../io/supertokens/pluginInterface/oauth/OAuthStorage.java | 5 ++--- ...on.java => OAuth2ClientAlreadyExistsForAppException.java} | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) rename src/main/java/io/supertokens/pluginInterface/oauth/exceptions/{ClientAlreadyExistsForAppException.java => OAuth2ClientAlreadyExistsForAppException.java} (92%) diff --git a/src/main/java/io/supertokens/pluginInterface/oauth/OAuthStorage.java b/src/main/java/io/supertokens/pluginInterface/oauth/OAuthStorage.java index 6498406b..1bea42be 100644 --- a/src/main/java/io/supertokens/pluginInterface/oauth/OAuthStorage.java +++ b/src/main/java/io/supertokens/pluginInterface/oauth/OAuthStorage.java @@ -19,8 +19,7 @@ import io.supertokens.pluginInterface.exceptions.StorageQueryException; import io.supertokens.pluginInterface.multitenancy.AppIdentifier; import io.supertokens.pluginInterface.nonAuthRecipe.NonAuthRecipeStorage; -import io.supertokens.pluginInterface.oauth.exceptions.ClientAlreadyExistsForAppException; -import io.supertokens.pluginInterface.sqlStorage.TransactionConnection; +import io.supertokens.pluginInterface.oauth.exceptions.OAuth2ClientAlreadyExistsForAppException; public interface OAuthStorage extends NonAuthRecipeStorage { @@ -28,5 +27,5 @@ public boolean doesClientIdExistForThisApp(AppIdentifier appIdentifier, String c StorageQueryException; public void addClientForApp(AppIdentifier appIdentifier, String clientId) throws StorageQueryException, - ClientAlreadyExistsForAppException; + OAuth2ClientAlreadyExistsForAppException; } diff --git a/src/main/java/io/supertokens/pluginInterface/oauth/exceptions/ClientAlreadyExistsForAppException.java b/src/main/java/io/supertokens/pluginInterface/oauth/exceptions/OAuth2ClientAlreadyExistsForAppException.java similarity index 92% rename from src/main/java/io/supertokens/pluginInterface/oauth/exceptions/ClientAlreadyExistsForAppException.java rename to src/main/java/io/supertokens/pluginInterface/oauth/exceptions/OAuth2ClientAlreadyExistsForAppException.java index 3ad491d1..e7521a44 100644 --- a/src/main/java/io/supertokens/pluginInterface/oauth/exceptions/ClientAlreadyExistsForAppException.java +++ b/src/main/java/io/supertokens/pluginInterface/oauth/exceptions/OAuth2ClientAlreadyExistsForAppException.java @@ -18,7 +18,7 @@ import java.io.Serial; -public class ClientAlreadyExistsForAppException extends Exception{ +public class OAuth2ClientAlreadyExistsForAppException extends Exception{ @Serial private static final long serialVersionUID = 2792232552559552544L; } From 1faa6f2f99b1f63e5c983d8eb820f0583335194e Mon Sep 17 00:00:00 2001 From: Tamas Soltesz Date: Thu, 1 Aug 2024 15:15:20 +0200 Subject: [PATCH 5/7] feat: OAuthStorage isClientAlreadyExists --- .../java/io/supertokens/pluginInterface/oauth/OAuthStorage.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/io/supertokens/pluginInterface/oauth/OAuthStorage.java b/src/main/java/io/supertokens/pluginInterface/oauth/OAuthStorage.java index 1bea42be..1a0da5c3 100644 --- a/src/main/java/io/supertokens/pluginInterface/oauth/OAuthStorage.java +++ b/src/main/java/io/supertokens/pluginInterface/oauth/OAuthStorage.java @@ -28,4 +28,6 @@ public boolean doesClientIdExistForThisApp(AppIdentifier appIdentifier, String c public void addClientForApp(AppIdentifier appIdentifier, String clientId) throws StorageQueryException, OAuth2ClientAlreadyExistsForAppException; + + public boolean isClientIdAlreadyExists(String clientId) throws StorageQueryException; } From 15e6f9d61bdd394cb8386aea3f30183e3d274844 Mon Sep 17 00:00:00 2001 From: Tamas Soltesz Date: Thu, 1 Aug 2024 17:37:31 +0200 Subject: [PATCH 6/7] feat: delete from oauth table --- .../java/io/supertokens/pluginInterface/oauth/OAuthStorage.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/io/supertokens/pluginInterface/oauth/OAuthStorage.java b/src/main/java/io/supertokens/pluginInterface/oauth/OAuthStorage.java index 1a0da5c3..e28995d4 100644 --- a/src/main/java/io/supertokens/pluginInterface/oauth/OAuthStorage.java +++ b/src/main/java/io/supertokens/pluginInterface/oauth/OAuthStorage.java @@ -30,4 +30,6 @@ public void addClientForApp(AppIdentifier appIdentifier, String clientId) throws OAuth2ClientAlreadyExistsForAppException; public boolean isClientIdAlreadyExists(String clientId) throws StorageQueryException; + + public void removeAppClientAssociation(AppIdentifier appIdentifier, String clientId) throws StorageQueryException; } From 090927dc6f96a15361577577b782fa3e2a469958 Mon Sep 17 00:00:00 2001 From: Tamas Soltesz Date: Mon, 5 Aug 2024 12:01:23 +0200 Subject: [PATCH 7/7] fix: removing unused/unnecessary method, change return type of other --- .../io/supertokens/pluginInterface/oauth/OAuthStorage.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/io/supertokens/pluginInterface/oauth/OAuthStorage.java b/src/main/java/io/supertokens/pluginInterface/oauth/OAuthStorage.java index e28995d4..de6e8d86 100644 --- a/src/main/java/io/supertokens/pluginInterface/oauth/OAuthStorage.java +++ b/src/main/java/io/supertokens/pluginInterface/oauth/OAuthStorage.java @@ -29,7 +29,5 @@ public boolean doesClientIdExistForThisApp(AppIdentifier appIdentifier, String c public void addClientForApp(AppIdentifier appIdentifier, String clientId) throws StorageQueryException, OAuth2ClientAlreadyExistsForAppException; - public boolean isClientIdAlreadyExists(String clientId) throws StorageQueryException; - - public void removeAppClientAssociation(AppIdentifier appIdentifier, String clientId) throws StorageQueryException; + public boolean removeAppClientAssociation(AppIdentifier appIdentifier, String clientId) throws StorageQueryException; }