-
Notifications
You must be signed in to change notification settings - Fork 938
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a custom user handle to a webauthn credential --------- Co-authored-by: bjoern-m <[email protected]>
- Loading branch information
1 parent
e172e05
commit 21fd1d4
Showing
9 changed files
with
135 additions
and
57 deletions.
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