-
Notifications
You must be signed in to change notification settings - Fork 14
Passwordless #27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Passwordless #27
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
e4cefbe
Adding passwordless
6ae9756
Updated changelog
93eb812
Combined functions for phone/email + removed unnecessary non-transact…
be9b5c2
Re-added get querys to use withouth locking + removed EmptyContactInf…
dcaf6de
Reverted renaming failedAttempts
1857efb
Re-added exceptions into combined methods
b22db1f
Lint fix
c15fd06
Updated based on review in supertokens-core
fdc7b20
Removed no longer necessary method
78946d2
Consolidated arguments into objects for create operations
5871543
Removed transaction parts from updateUser
c8bc756
Update user moved into transaction
f1424c1
Added auto-generated hashCode & equals to PWLessCode
deb2d26
Removed unnecessary locking getUserById
432635d
Merge remote-tracking branch 'origin/passwordless-update_user' into p…
167b28f
Cleaned up generated equals a bit
214a772
Salting linkCodes
d42deba
Fixed param naming
20d33fd
MERGE with 2.10
866b582
changes version
super-tokens f073e67
rebuilds jar
super-tokens e56b02b
adds jar
super-tokens afa5b11
Adding delete user for pwless
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ plugins { | |
id 'java-library' | ||
} | ||
|
||
version = "2.10.0" | ||
version = "2.11.0" | ||
|
||
repositories { | ||
mavenCentral() | ||
|
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
src/main/java/io/supertokens/pluginInterface/passwordless/PasswordlessCode.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package io.supertokens.pluginInterface.passwordless; | ||
|
||
public class PasswordlessCode { | ||
public final String id; | ||
public final String deviceIdHash; | ||
public final String linkCodeHash; | ||
public final Long createdAt; | ||
|
||
public PasswordlessCode(String id, String deviceIdHash, String linkCodeHash, Long createdAt) { | ||
this.id = id; | ||
this.deviceIdHash = deviceIdHash; | ||
this.linkCodeHash = linkCodeHash; | ||
this.createdAt = createdAt; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
final int prime = 31; | ||
int result = 1; | ||
result = prime * result + ((createdAt == null) ? 0 : createdAt.hashCode()); | ||
result = prime * result + ((deviceIdHash == null) ? 0 : deviceIdHash.hashCode()); | ||
result = prime * result + ((id == null) ? 0 : id.hashCode()); | ||
result = prime * result + ((linkCodeHash == null) ? 0 : linkCodeHash.hashCode()); | ||
return result; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) { | ||
return true; | ||
} | ||
if (obj == null) { | ||
return false; | ||
} | ||
if (!(obj instanceof PasswordlessCode)) { | ||
return false; | ||
} | ||
PasswordlessCode other = (PasswordlessCode) obj; | ||
if (createdAt == null) { | ||
if (other.createdAt != null) { | ||
return false; | ||
} | ||
} else if (!createdAt.equals(other.createdAt)) { | ||
return false; | ||
} | ||
if (deviceIdHash == null) { | ||
if (other.deviceIdHash != null) { | ||
return false; | ||
} | ||
} else if (!deviceIdHash.equals(other.deviceIdHash)) { | ||
return false; | ||
} | ||
if (id == null) { | ||
if (other.id != null) { | ||
return false; | ||
} | ||
} else if (!id.equals(other.id)) { | ||
return false; | ||
} | ||
if (linkCodeHash == null) { | ||
if (other.linkCodeHash != null) { | ||
return false; | ||
} | ||
} else if (!linkCodeHash.equals(other.linkCodeHash)) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/io/supertokens/pluginInterface/passwordless/PasswordlessDevice.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright (c) 2020, 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.passwordless; | ||
|
||
public class PasswordlessDevice { | ||
public final String deviceIdHash; | ||
public final String email; | ||
public final String phoneNumber; | ||
public final String linkCodeSalt; | ||
public final int failedAttempts; | ||
|
||
public PasswordlessDevice(String deviceIdHash, String email, String phoneNumber, String linkCodeSalt, | ||
int failedAttempts) { | ||
this.deviceIdHash = deviceIdHash; | ||
this.email = email; | ||
this.phoneNumber = phoneNumber; | ||
this.failedAttempts = failedAttempts; | ||
this.linkCodeSalt = linkCodeSalt; | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
src/main/java/io/supertokens/pluginInterface/passwordless/PasswordlessStorage.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright (c) 2020, 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.passwordless; | ||
|
||
import io.supertokens.pluginInterface.authRecipe.AuthRecipeStorage; | ||
import io.supertokens.pluginInterface.emailpassword.exceptions.DuplicateEmailException; | ||
import io.supertokens.pluginInterface.emailpassword.exceptions.DuplicateUserIdException; | ||
import io.supertokens.pluginInterface.exceptions.StorageQueryException; | ||
import io.supertokens.pluginInterface.passwordless.exception.DuplicateCodeIdException; | ||
import io.supertokens.pluginInterface.passwordless.exception.DuplicateDeviceIdHashException; | ||
import io.supertokens.pluginInterface.passwordless.exception.DuplicateLinkCodeHashException; | ||
import io.supertokens.pluginInterface.passwordless.exception.DuplicatePhoneNumberException; | ||
import io.supertokens.pluginInterface.passwordless.exception.UnknownDeviceIdHash; | ||
|
||
import javax.annotation.Nonnull; | ||
import javax.annotation.Nullable; | ||
|
||
public interface PasswordlessStorage extends AuthRecipeStorage { | ||
void createDeviceWithCode(@Nullable String email, @Nullable String phoneNumber, @Nonnull String linkCodeSalt, | ||
PasswordlessCode code) throws StorageQueryException, DuplicateDeviceIdHashException, | ||
DuplicateCodeIdException, DuplicateLinkCodeHashException; | ||
|
||
void createCode(PasswordlessCode code) | ||
throws StorageQueryException, UnknownDeviceIdHash, DuplicateCodeIdException, DuplicateLinkCodeHashException; | ||
|
||
void createUser(UserInfo user) throws StorageQueryException, DuplicateEmailException, DuplicatePhoneNumberException, | ||
DuplicateUserIdException; | ||
|
||
void deletePasswordlessUser(String userId) throws StorageQueryException; | ||
|
||
PasswordlessDevice getDevice(String deviceIdHash) throws StorageQueryException; | ||
|
||
PasswordlessDevice[] getDevicesByEmail(@Nonnull String email) throws StorageQueryException; | ||
|
||
PasswordlessDevice[] getDevicesByPhoneNumber(@Nonnull String phoneNumber) throws StorageQueryException; | ||
|
||
PasswordlessCode[] getCodesOfDevice(String deviceIdHash) throws StorageQueryException; | ||
|
||
PasswordlessCode[] getCodesBefore(long time) throws StorageQueryException; | ||
|
||
PasswordlessCode getCode(String codeId) throws StorageQueryException; | ||
|
||
PasswordlessCode getCodeByLinkCodeHash(String linkCode) throws StorageQueryException; | ||
|
||
UserInfo getUserById(String userId) throws StorageQueryException; | ||
|
||
UserInfo getUserByEmail(@Nonnull String email) throws StorageQueryException; | ||
|
||
UserInfo getUserByPhoneNumber(@Nonnull String phoneNumber) throws StorageQueryException; | ||
} |
55 changes: 55 additions & 0 deletions
55
src/main/java/io/supertokens/pluginInterface/passwordless/UserInfo.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright (c) 2020, 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.passwordless; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
import io.supertokens.pluginInterface.RECIPE_ID; | ||
import io.supertokens.pluginInterface.authRecipe.AuthRecipeUserInfo; | ||
|
||
public class UserInfo extends AuthRecipeUserInfo { | ||
rishabhpoddar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
public final String email; | ||
public final String phoneNumber; | ||
|
||
public UserInfo(String id, @Nullable String email, @Nullable String phoneNumber, long timeJoined) { | ||
super(id, timeJoined); | ||
|
||
if (email == null && phoneNumber == null) { | ||
throw new IllegalArgumentException("Both email and phoneNumber cannot be null"); | ||
} | ||
|
||
this.email = email; | ||
this.phoneNumber = phoneNumber; | ||
} | ||
|
||
@Override | ||
public RECIPE_ID getRecipeId() { | ||
return RECIPE_ID.PASSWORDLESS; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other instanceof UserInfo) { | ||
UserInfo otherUserInfo = (UserInfo) other; | ||
return ((otherUserInfo.email == null && this.email == null) || otherUserInfo.email.equals(this.email)) | ||
&& ((otherUserInfo.phoneNumber == null && this.phoneNumber == null) | ||
|| otherUserInfo.phoneNumber.equals(this.phoneNumber)) | ||
&& otherUserInfo.id.equals(this.id) && otherUserInfo.timeJoined == this.timeJoined; | ||
} | ||
return false; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
.../java/io/supertokens/pluginInterface/passwordless/exception/DuplicateCodeIdException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright (c) 2020, 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.passwordless.exception; | ||
|
||
import io.supertokens.pluginInterface.emailpassword.exceptions.EmailPasswordException; | ||
|
||
public class DuplicateCodeIdException extends EmailPasswordException { | ||
private static final long serialVersionUID = 6848053563771647272L; | ||
} |
23 changes: 23 additions & 0 deletions
23
...io/supertokens/pluginInterface/passwordless/exception/DuplicateDeviceIdHashException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright (c) 2020, 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.passwordless.exception; | ||
|
||
import io.supertokens.pluginInterface.emailpassword.exceptions.EmailPasswordException; | ||
|
||
public class DuplicateDeviceIdHashException extends EmailPasswordException { | ||
private static final long serialVersionUID = 6848053563771647272L; | ||
} |
23 changes: 23 additions & 0 deletions
23
...io/supertokens/pluginInterface/passwordless/exception/DuplicateLinkCodeHashException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright (c) 2020, 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.passwordless.exception; | ||
|
||
import io.supertokens.pluginInterface.emailpassword.exceptions.EmailPasswordException; | ||
|
||
public class DuplicateLinkCodeHashException extends EmailPasswordException { | ||
private static final long serialVersionUID = 6848053563771647272L; | ||
} |
23 changes: 23 additions & 0 deletions
23
.../io/supertokens/pluginInterface/passwordless/exception/DuplicatePhoneNumberException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright (c) 2020, 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.passwordless.exception; | ||
|
||
import io.supertokens.pluginInterface.emailpassword.exceptions.EmailPasswordException; | ||
|
||
public class DuplicatePhoneNumberException extends EmailPasswordException { | ||
private static final long serialVersionUID = 6848053563771647272L; | ||
} |
23 changes: 23 additions & 0 deletions
23
.../java/io/supertokens/pluginInterface/passwordless/exception/DuplicateUserIdException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright (c) 2020, 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.passwordless.exception; | ||
|
||
import io.supertokens.pluginInterface.emailpassword.exceptions.EmailPasswordException; | ||
|
||
public class DuplicateUserIdException extends EmailPasswordException { | ||
private static final long serialVersionUID = 6848053563771647272L; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.