Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [2.16.0] - 2022-07-25

- UserId Mapping interface

## [2.15.0] - 2022-06-07

- Changes name of `getAllSessionHandlesForUser` to `getAllNonExpiredSessionHandlesForUser`.
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.15.0"
version = "2.16.0"

repositories {
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,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_ROLES("userroles"), USER_ID_MAPPING("useridmapping");

private final String name;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ public interface AuthRecipeStorage extends Storage {
AuthRecipeUserInfo[] getUsers(@Nonnull Integer limit, @Nonnull String timeJoinedOrder,
@Nullable RECIPE_ID[] includeRecipeIds, @Nullable String userId, @Nullable Long timeJoined)
throws StorageQueryException;

boolean doesUserIdExist(String userId) throws StorageQueryException;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* 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.useridmapping;

import javax.annotation.Nullable;

public class UserIdMapping {

public final String superTokensUserId;

public final String externalUserId;

public final @Nullable String externalUserIdInfo;

public UserIdMapping(String superTokensUserId, String externalUserId, @Nullable String externalUserIdInfo) {
this.superTokensUserId = superTokensUserId;
this.externalUserId = externalUserId;
this.externalUserIdInfo = externalUserIdInfo;
}

@Override
public boolean equals(Object other) {
if (other instanceof UserIdMapping) {
UserIdMapping otherUserIdMapping = (UserIdMapping) other;
return otherUserIdMapping.superTokensUserId.equals(this.superTokensUserId)
&& otherUserIdMapping.externalUserId.equals(this.externalUserId)
&& otherUserIdMapping.externalUserIdInfo.equals(this.externalUserIdInfo);
}
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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.useridmapping;

import io.supertokens.pluginInterface.Storage;
import io.supertokens.pluginInterface.exceptions.StorageQueryException;
import io.supertokens.pluginInterface.useridmapping.exception.UnknownSuperTokensUserIdException;
import io.supertokens.pluginInterface.useridmapping.exception.UserIdMappingAlreadyExistsException;

import javax.annotation.Nullable;

public interface UserIdMappingStorage extends Storage {

void createUserIdMapping(String superTokensUserId, String externalUserId, @Nullable String externalUserIdInfo)
throws StorageQueryException, UnknownSuperTokensUserIdException, UserIdMappingAlreadyExistsException;

boolean deleteUserIdMapping(String userId, boolean isSuperTokensUserId) throws StorageQueryException;

UserIdMapping getUserIdMapping(String userId, boolean isSuperTokensUserId) throws StorageQueryException;

UserIdMapping[] getUserIdMapping(String userId) throws StorageQueryException;

boolean updateOrDeleteExternalUserIdInfo(String userId, boolean isSuperTokensUserId,
@Nullable String externalUserIdInfo) throws StorageQueryException;

}
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.useridmapping.exception;

import java.io.Serial;

public class UnknownSuperTokensUserIdException extends UserIdMappingException {
@Serial
private static final long serialVersionUID = -2468061107846190216L;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* 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.useridmapping.exception;

import java.io.Serial;

public class UserIdMappingAlreadyExistsException extends UserIdMappingException {
@Serial
private static final long serialVersionUID = -492689371744874366L;

public final boolean doesSuperTokensUserIdExist;

public final boolean doesExternalUserIdExist;

public UserIdMappingAlreadyExistsException(boolean doesSuperTokensUserIdExist, boolean doesExternalUserIdExist) {

if (!doesExternalUserIdExist && !doesSuperTokensUserIdExist) {
throw new IllegalArgumentException("At least one of superTokensUserId or externalUserId should exist");
} else {

this.doesSuperTokensUserIdExist = doesSuperTokensUserIdExist;
this.doesExternalUserIdExist = doesExternalUserIdExist;
}
}
}
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.useridmapping.exception;

import java.io.Serial;

public class UserIdMappingException extends Exception {
@Serial
private static final long serialVersionUID = -7930311777814572808L;
}