-
Notifications
You must be signed in to change notification settings - Fork 938
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
Feat custom user #1978
Merged
Merged
Feat custom user #1978
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c5d24b0
feat: add custom user ID
FreddyDevelop bcd40f1
test: fix build
FreddyDevelop 9b4bcbc
feat: add customUserHandle to webauthn credential
FreddyDevelop b7c366e
chore: change DB schema for user handle
FreddyDevelop db6fa7f
fix: add missing value in sql migration statement
FreddyDevelop c4437b7
chore: remove unused variables
FreddyDevelop 77b0ad8
chore: change migration
FreddyDevelop 58a0397
fix: always use custom user handle if available
FreddyDevelop 8f182ae
chore: simplify getting the webauthn user
FreddyDevelop 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 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 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 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
5 changes: 5 additions & 0 deletions
5
backend/persistence/migrations/20241118114500_change_webauthn_credentials.down.fizz
This file contains 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,5 @@ | ||
drop_foreign_key("webauthn_credentials", "webauthn_credential_user_handle_fkey", {"if_exists": false}) | ||
drop_column("webauthn_credentials", "user_handle_id") | ||
drop_table("webauthn_credential_user_handles") | ||
|
||
|
16 changes: 16 additions & 0 deletions
16
backend/persistence/migrations/20241118114500_change_webauthn_credentials.up.fizz
This file contains 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,16 @@ | ||
create_table("webauthn_credential_user_handles") { | ||
t.Column("id", "uuid", {primary: true}) | ||
t.Column("user_id", "uuid", {"null": false}) | ||
t.Column("handle", "string", {"null": false, "unique": true}) | ||
t.Timestamps() | ||
t.Index(["id", "user_id"], {"unique": true}) | ||
t.ForeignKey("user_id", {"users": ["id"]}, {"on_delete": "cascade", "on_update": "cascade"}) | ||
} | ||
|
||
add_column("webauthn_credentials", "user_handle_id", "uuid", { "null": true }) | ||
add_foreign_key("webauthn_credentials", "user_handle_id", {"webauthn_credential_user_handles": ["id"]}, { | ||
"on_delete": "set null", | ||
"on_update": "cascade", | ||
}) | ||
|
||
sql("ALTER TABLE webauthn_credentials ADD CONSTRAINT webauthn_credential_user_handle_fkey FOREIGN KEY (user_handle_id, user_id) REFERENCES webauthn_credential_user_handles(id, user_id) ON DELETE NO ACTION ON UPDATE CASCADE;") |
This file contains 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
28 changes: 28 additions & 0 deletions
28
backend/persistence/models/webauthn_credential_user_handle.go
This file contains 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,28 @@ | ||
package models | ||
|
||
import ( | ||
"github.com/gobuffalo/pop/v6" | ||
"github.com/gobuffalo/validate/v3" | ||
"github.com/gobuffalo/validate/v3/validators" | ||
"github.com/gofrs/uuid" | ||
"time" | ||
) | ||
|
||
type WebauthnCredentialUserHandle struct { | ||
ID uuid.UUID `db:"id" json:"id"` | ||
UserID uuid.UUID `db:"user_id" json:"user_id"` | ||
Handle string `db:"handle" json:"handle"` | ||
CreatedAt time.Time `db:"created_at" json:"created_at"` | ||
UpdatedAt time.Time `db:"updated_at" json:"updated_at"` | ||
} | ||
|
||
// Validate gets run every time you call a "pop.Validate*" (pop.ValidateAndSave, pop.ValidateAndCreate, pop.ValidateAndUpdate) method. | ||
func (userHandle *WebauthnCredentialUserHandle) Validate(tx *pop.Connection) (*validate.Errors, error) { | ||
return validate.Validate( | ||
&validators.UUIDIsPresent{Name: "ID", Field: userHandle.ID}, | ||
&validators.UUIDIsPresent{Name: "UserId", Field: userHandle.UserID}, | ||
&validators.StringIsPresent{Name: "handle", Field: userHandle.Handle}, | ||
&validators.TimeIsPresent{Name: "CreatedAt", Field: userHandle.CreatedAt}, | ||
&validators.TimeIsPresent{Name: "UpdatedAt", Field: userHandle.UpdatedAt}, | ||
), nil | ||
} |
This file contains 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 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it make sense to set the
email
parameter via aJWTOption
too?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that would make sense. This is just leftover from the previous implementation where a user would have a custom userID. And I forgot that its still there. Maybe we can do it in a separate PR?