5454import io .supertokens .pluginInterface .multitenancy .exceptions .DuplicateThirdPartyIdException ;
5555import io .supertokens .pluginInterface .multitenancy .exceptions .TenantOrAppNotFoundException ;
5656import io .supertokens .pluginInterface .multitenancy .sqlStorage .MultitenancySQLStorage ;
57+ import io .supertokens .pluginInterface .oauth .OAuthLogoutChallenge ;
58+ import io .supertokens .pluginInterface .oauth .OAuthRevokeTargetType ;
59+ import io .supertokens .pluginInterface .oauth .OAuthStorage ;
60+ import io .supertokens .pluginInterface .oauth .exception .DuplicateOAuthLogoutChallengeException ;
61+ import io .supertokens .pluginInterface .oauth .exception .OAuthClientNotFoundException ;
5762import io .supertokens .pluginInterface .passwordless .PasswordlessCode ;
5863import io .supertokens .pluginInterface .passwordless .PasswordlessDevice ;
5964import io .supertokens .pluginInterface .passwordless .exception .*;
@@ -106,7 +111,7 @@ public class Start
106111 implements SessionSQLStorage , EmailPasswordSQLStorage , EmailVerificationSQLStorage , ThirdPartySQLStorage ,
107112 JWTRecipeSQLStorage , PasswordlessSQLStorage , UserMetadataSQLStorage , UserRolesSQLStorage , UserIdMappingStorage ,
108113 UserIdMappingSQLStorage , MultitenancyStorage , MultitenancySQLStorage , DashboardSQLStorage , TOTPSQLStorage ,
109- ActiveUsersStorage , ActiveUsersSQLStorage , AuthRecipeSQLStorage {
114+ ActiveUsersStorage , ActiveUsersSQLStorage , AuthRecipeSQLStorage , OAuthStorage {
110115
111116 // these configs are protected from being modified / viewed by the dev using the SuperTokens
112117 // SaaS. If the core is not running in SuperTokens SaaS, this array has no effect.
@@ -121,7 +126,6 @@ public class Start
121126 private ResourceDistributor resourceDistributor = new ResourceDistributor ();
122127 private String processId ;
123128 private HikariLoggingAppender appender ;
124- private static final String APP_ID_KEY_NAME = "app_id" ;
125129 private static final String ACCESS_TOKEN_SIGNING_KEY_NAME = "access_token_signing_key" ;
126130 private static final String REFRESH_TOKEN_KEY_NAME = "refresh_token_key" ;
127131 public static boolean isTesting = false ;
@@ -864,6 +868,8 @@ public void addInfoToNonAuthRecipesBasedOnUserId(TenantIdentifier tenantIdentifi
864868 }
865869 } else if (className .equals (JWTRecipeStorage .class .getName ())) {
866870 /* Since JWT recipe tables do not store userId we do not add any data to them */
871+ } else if (className .equals (OAuthStorage .class .getName ())) {
872+ /* Since OAuth recipe tables do not store userId we do not add any data to them */
867873 } else if (className .equals (ActiveUsersStorage .class .getName ())) {
868874 try {
869875 ActiveUsersQueries .updateUserLastActive (this , tenantIdentifier .toAppIdentifier (), userId );
@@ -3089,6 +3095,194 @@ public int countUsersThatHaveMoreThanOneLoginMethodOrTOTPEnabledAndActiveSince(A
30893095 }
30903096 }
30913097
3098+ @ Override
3099+ public boolean doesOAuthClientIdExist (AppIdentifier appIdentifier , String clientId )
3100+ throws StorageQueryException {
3101+ try {
3102+ return OAuthQueries .doesOAuthClientIdExist (this , clientId , appIdentifier );
3103+ } catch (SQLException e ) {
3104+ throw new StorageQueryException (e );
3105+ }
3106+ }
3107+
3108+ @ Override
3109+ public void addOrUpdateOauthClient (AppIdentifier appIdentifier , String clientId , boolean isClientCredentialsOnly )
3110+ throws StorageQueryException , TenantOrAppNotFoundException {
3111+ try {
3112+ OAuthQueries .addOrUpdateOauthClient (this , appIdentifier , clientId , isClientCredentialsOnly );
3113+ } catch (SQLException e ) {
3114+ PostgreSQLConfig config = Config .getConfig (this );
3115+ if (e instanceof PSQLException ) {
3116+ ServerErrorMessage serverMessage = ((PSQLException ) e ).getServerErrorMessage ();
3117+
3118+ if (isForeignKeyConstraintError (serverMessage , config .getOAuthClientsTable (), "app_id" )) {
3119+ throw new TenantOrAppNotFoundException (appIdentifier );
3120+ }
3121+ }
3122+ throw new StorageQueryException (e );
3123+ }
3124+ }
3125+
3126+ @ Override
3127+ public boolean deleteOAuthClient (AppIdentifier appIdentifier , String clientId ) throws StorageQueryException {
3128+ try {
3129+ return OAuthQueries .deleteOAuthClient (this , clientId , appIdentifier );
3130+ } catch (SQLException e ) {
3131+ throw new StorageQueryException (e );
3132+ }
3133+ }
3134+
3135+ @ Override
3136+ public List <String > listOAuthClients (AppIdentifier appIdentifier ) throws StorageQueryException {
3137+ try {
3138+ return OAuthQueries .listOAuthClients (this , appIdentifier );
3139+ } catch (SQLException e ) {
3140+ throw new StorageQueryException (e );
3141+ }
3142+ }
3143+
3144+ @ Override
3145+ public void revokeOAuthTokensBasedOnTargetFields (AppIdentifier appIdentifier , OAuthRevokeTargetType targetType , String targetValue , long exp )
3146+ throws StorageQueryException , TenantOrAppNotFoundException {
3147+ try {
3148+ OAuthQueries .revokeOAuthTokensBasedOnTargetFields (this , appIdentifier , targetType , targetValue , exp );
3149+ } catch (SQLException e ) {
3150+ PostgreSQLConfig config = Config .getConfig (this );
3151+ if (e instanceof PSQLException ) {
3152+ ServerErrorMessage serverMessage = ((PSQLException ) e ).getServerErrorMessage ();
3153+
3154+ if (isForeignKeyConstraintError (serverMessage , config .getOAuthRevokeTable (), "app_id" )) {
3155+ throw new TenantOrAppNotFoundException (appIdentifier );
3156+ }
3157+ }
3158+ throw new StorageQueryException (e );
3159+ }
3160+
3161+ }
3162+
3163+ @ Override
3164+ public boolean isOAuthTokenRevokedBasedOnTargetFields (AppIdentifier appIdentifier , OAuthRevokeTargetType [] targetTypes , String [] targetValues , long issuedAt )
3165+ throws StorageQueryException {
3166+ try {
3167+ return OAuthQueries .isOAuthTokenRevokedBasedOnTargetFields (this , appIdentifier , targetTypes , targetValues , issuedAt );
3168+ } catch (SQLException e ) {
3169+ throw new StorageQueryException (e );
3170+ }
3171+ }
3172+
3173+ @ Override
3174+ public void addOAuthM2MTokenForStats (AppIdentifier appIdentifier , String clientId , long iat , long exp )
3175+ throws StorageQueryException , OAuthClientNotFoundException {
3176+ try {
3177+ OAuthQueries .addOAuthM2MTokenForStats (this , appIdentifier , clientId , iat , exp );
3178+ } catch (SQLException e ) {
3179+ PostgreSQLConfig config = Config .getConfig (this );
3180+ if (e instanceof PSQLException ) {
3181+ ServerErrorMessage serverMessage = ((PSQLException ) e ).getServerErrorMessage ();
3182+
3183+ if (isForeignKeyConstraintError (serverMessage , config .getOAuthM2MTokensTable (), "client_id" )) {
3184+ throw new OAuthClientNotFoundException ();
3185+ }
3186+ }
3187+ throw new StorageQueryException (e );
3188+ }
3189+ }
3190+
3191+ @ Override
3192+ public void cleanUpExpiredAndRevokedOAuthTokensList () throws StorageQueryException {
3193+ try {
3194+ OAuthQueries .cleanUpExpiredAndRevokedOAuthTokensList (this );
3195+ } catch (SQLException e ) {
3196+ throw new StorageQueryException (e );
3197+ }
3198+ }
3199+
3200+ @ Override
3201+ public void addOAuthLogoutChallenge (AppIdentifier appIdentifier , String challenge , String clientId ,
3202+ String postLogoutRedirectionUri , String sessionHandle , String state , long timeCreated )
3203+ throws StorageQueryException , DuplicateOAuthLogoutChallengeException , OAuthClientNotFoundException {
3204+ try {
3205+ OAuthQueries .addOAuthLogoutChallenge (this , appIdentifier , challenge , clientId , postLogoutRedirectionUri , sessionHandle , state , timeCreated );
3206+ } catch (SQLException e ) {
3207+ PostgreSQLConfig config = Config .getConfig (this );
3208+ if (e instanceof PSQLException ) {
3209+ ServerErrorMessage serverMessage = ((PSQLException ) e ).getServerErrorMessage ();
3210+
3211+ if (isPrimaryKeyError (serverMessage , config .getOAuthLogoutChallengesTable ())) {
3212+ throw new DuplicateOAuthLogoutChallengeException ();
3213+ } else if (isForeignKeyConstraintError (serverMessage , config .getOAuthLogoutChallengesTable (), "client_id" )) {
3214+ throw new OAuthClientNotFoundException ();
3215+ }
3216+ }
3217+ throw new StorageQueryException (e );
3218+ }
3219+ }
3220+
3221+ @ Override
3222+ public OAuthLogoutChallenge getOAuthLogoutChallenge (AppIdentifier appIdentifier , String challenge ) throws StorageQueryException {
3223+ try {
3224+ return OAuthQueries .getOAuthLogoutChallenge (this , appIdentifier , challenge );
3225+ } catch (SQLException e ) {
3226+ throw new StorageQueryException (e );
3227+ }
3228+ }
3229+
3230+ @ Override
3231+ public void deleteOAuthLogoutChallenge (AppIdentifier appIdentifier , String challenge ) throws StorageQueryException {
3232+ try {
3233+ OAuthQueries .deleteOAuthLogoutChallenge (this , appIdentifier , challenge );
3234+ } catch (SQLException e ) {
3235+ throw new StorageQueryException (e );
3236+ }
3237+ }
3238+
3239+ @ Override
3240+ public void deleteOAuthLogoutChallengesBefore (long time ) throws StorageQueryException {
3241+ try {
3242+ OAuthQueries .deleteOAuthLogoutChallengesBefore (this , time );
3243+ } catch (SQLException e ) {
3244+ throw new StorageQueryException (e );
3245+ }
3246+ }
3247+
3248+ @ Override
3249+ public int countTotalNumberOfOAuthClients (AppIdentifier appIdentifier ) throws StorageQueryException {
3250+ try {
3251+ return OAuthQueries .countTotalNumberOfClients (this , appIdentifier , false );
3252+ } catch (SQLException e ) {
3253+ throw new StorageQueryException (e );
3254+ }
3255+ }
3256+
3257+ @ Override
3258+ public int countTotalNumberOfClientCredentialsOnlyOAuthClients (AppIdentifier appIdentifier )
3259+ throws StorageQueryException {
3260+ try {
3261+ return OAuthQueries .countTotalNumberOfClients (this , appIdentifier , true );
3262+ } catch (SQLException e ) {
3263+ throw new StorageQueryException (e );
3264+ }
3265+ }
3266+
3267+ @ Override
3268+ public int countTotalNumberOfOAuthM2MTokensCreatedSince (AppIdentifier appIdentifier , long since )
3269+ throws StorageQueryException {
3270+ try {
3271+ return OAuthQueries .countTotalNumberOfOAuthM2MTokensCreatedSince (this , appIdentifier , since );
3272+ } catch (SQLException e ) {
3273+ throw new StorageQueryException (e );
3274+ }
3275+ }
3276+
3277+ @ Override
3278+ public int countTotalNumberOfOAuthM2MTokensAlive (AppIdentifier appIdentifier ) throws StorageQueryException {
3279+ try {
3280+ return OAuthQueries .countTotalNumberOfOAuthM2MTokensAlive (this , appIdentifier );
3281+ } catch (SQLException e ) {
3282+ throw new StorageQueryException (e );
3283+ }
3284+ }
3285+
30923286 @ TestOnly
30933287 public int getDbActivityCount (String dbname ) throws SQLException , StorageQueryException {
30943288 String QUERY = "SELECT COUNT(*) as c FROM pg_stat_activity WHERE datname = ?;" ;
0 commit comments