Skip to content

Commit

Permalink
feat: adds addtional function for userIdmapping (#41)
Browse files Browse the repository at this point in the history
* fixes function signiture

* implements feedback

* fixes comment

* implements feedback

* plugin fixes

* implements feedback

* implements feedback

* updates CHANGELOG.md and version
  • Loading branch information
jscyo authored Aug 10, 2022
1 parent 251971e commit e16c7e1
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 7 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [2.17.0] - 2022-08-10

- Adds `getUserIdMappingForSuperTokensIds` to the UserIdMapping Interface
- Adds `isUserIdBeingUsedInNonAuthRecipe` and `addInfoToNonAuthRecipesBasedOnUserId` to the Storage Interface
- Adds `NonAuthRecipeStorage` Interface
- All non-auth recipes now extend the `NonAuthRecipeStorage` Interface

## [2.16.0] - 2022-07-25

- UserId Mapping interface
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ plugins {
id 'java-library'
}

version = "2.16.0"
version = "2.17.0"

repositories {
mavenCentral()
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/io/supertokens/pluginInterface/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,11 @@ public interface Storage {

boolean canBeUsed(String configFilePath);

// this function will be used in the createUserIdMapping and deleteUserIdMapping functions to check if the userId is
// being used in NonAuth recipes.
boolean isUserIdBeingUsedInNonAuthRecipe(String className, String userId) throws StorageQueryException;

// to be used for testing purposes only. This function will add dummy data to non-auth tables.
void addInfoToNonAuthRecipesBasedOnUserId(String className, String userId) throws StorageQueryException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
import io.supertokens.pluginInterface.Storage;
import io.supertokens.pluginInterface.emailverification.exception.DuplicateEmailVerificationTokenException;
import io.supertokens.pluginInterface.exceptions.StorageQueryException;
import io.supertokens.pluginInterface.nonAuthRecipe.NonAuthRecipeStorage;

public interface EmailVerificationStorage extends Storage {
public interface EmailVerificationStorage extends NonAuthRecipeStorage {

void addEmailVerificationToken(EmailVerificationTokenInfo emailVerificationInfo)
throws StorageQueryException, DuplicateEmailVerificationTokenException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package io.supertokens.pluginInterface.jwt;

import io.supertokens.pluginInterface.Storage;
import io.supertokens.pluginInterface.nonAuthRecipe.NonAuthRecipeStorage;

public interface JWTRecipeStorage extends Storage {
public interface JWTRecipeStorage extends NonAuthRecipeStorage {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (c) 2022, 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.nonAuthRecipe;

import io.supertokens.pluginInterface.Storage;

// All Non-Auth Recipes will extend this interface.
// We will use this interface in testing to check If the createUserIdMapping and deleteUserIdMapping functions have checks for all nonAuthRecipes
public interface NonAuthRecipeStorage extends Storage {
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@
import com.google.gson.JsonObject;
import io.supertokens.pluginInterface.Storage;
import io.supertokens.pluginInterface.exceptions.StorageQueryException;
import io.supertokens.pluginInterface.nonAuthRecipe.NonAuthRecipeStorage;

import javax.annotation.Nullable;

public interface SessionStorage extends Storage {
public interface SessionStorage extends NonAuthRecipeStorage {
void createNewSession(String sessionHandle, String userId, String refreshTokenHash2, JsonObject userDataInDatabase,
long expiry, JsonObject userDataInJWT, long createdAtTime) throws StorageQueryException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import io.supertokens.pluginInterface.useridmapping.exception.UserIdMappingAlreadyExistsException;

import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.HashMap;

public interface UserIdMappingStorage extends Storage {

Expand All @@ -37,4 +39,9 @@ void createUserIdMapping(String superTokensUserId, String externalUserId, @Nulla
boolean updateOrDeleteExternalUserIdInfo(String userId, boolean isSuperTokensUserId,
@Nullable String externalUserIdInfo) throws StorageQueryException;

// This function will be used to retrieve the userId mapping for a list of userIds. The key of the HashMap will be
// superTokensUserId and the value will be the externalUserId. If a mapping does not exist for an input userId,
// it will not be in a part of the returned HashMap
HashMap<String, String> getUserIdMappingForSuperTokensIds(ArrayList<String> userIds) throws StorageQueryException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
import com.google.gson.JsonObject;
import io.supertokens.pluginInterface.Storage;
import io.supertokens.pluginInterface.exceptions.StorageQueryException;
import io.supertokens.pluginInterface.nonAuthRecipe.NonAuthRecipeStorage;

public interface UserMetadataStorage extends Storage {
public interface UserMetadataStorage extends NonAuthRecipeStorage {
JsonObject getUserMetadata(String userId) throws StorageQueryException;

int deleteUserMetadata(String userId) throws StorageQueryException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@
import com.google.gson.JsonObject;
import io.supertokens.pluginInterface.Storage;
import io.supertokens.pluginInterface.exceptions.StorageQueryException;
import io.supertokens.pluginInterface.nonAuthRecipe.NonAuthRecipeStorage;
import io.supertokens.pluginInterface.userroles.exception.DuplicateUserRoleMappingException;
import io.supertokens.pluginInterface.userroles.exception.UnknownRoleException;

public interface UserRolesStorage extends Storage {
public interface UserRolesStorage extends NonAuthRecipeStorage {

// associate a userId with a role that exists
void addRoleToUser(String userId, String role)
Expand Down

0 comments on commit e16c7e1

Please sign in to comment.