-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
100 additions
and
85 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ linters: | |
enable: | ||
# Drop-in replacement of `golint`. | ||
- revive | ||
- ireturn | ||
|
||
issues: | ||
include: | ||
|
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,38 @@ | ||
// Package memory implements a session store in-memory. | ||
package memory | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/Darkness4/auth-htmx/auth/webauthn/session" | ||
"github.com/go-webauthn/webauthn/webauthn" | ||
) | ||
|
||
// Store stores the login/registration session in-memory. | ||
// | ||
// In production, you should use a Redis or ETCD, or any distributed Key-Value database. | ||
// Because of this, you cannot create replicas. | ||
type Store struct { | ||
store map[string]*webauthn.SessionData | ||
} | ||
|
||
// NewStore instanciates a session store in memory. | ||
func NewStore() *Store { | ||
return &Store{ | ||
store: make(map[string]*webauthn.SessionData), | ||
} | ||
} | ||
|
||
// Get the login or registration session. | ||
func (s *Store) Get(_ context.Context, userID []byte) (*webauthn.SessionData, error) { | ||
if v, ok := s.store[string(userID)]; ok { | ||
return v, nil | ||
} | ||
return nil, session.ErrNotFound | ||
} | ||
|
||
// Save the login or registration session. | ||
func (s *Store) Save(_ context.Context, session *webauthn.SessionData) error { | ||
s.store[string(session.UserID)] = session | ||
return 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Package session handles the login/register sessions of webauthn. | ||
package session | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
|
||
"github.com/go-webauthn/webauthn/webauthn" | ||
) | ||
|
||
// Store stores the login/registration session. | ||
type Store interface { | ||
Save(ctx context.Context, session *webauthn.SessionData) error | ||
Get(ctx context.Context, userID []byte) (*webauthn.SessionData, error) | ||
} | ||
|
||
// ErrNotFound happens when the session is not found in the store. | ||
var ErrNotFound = errors.New("not found in session store") |
This file was deleted.
Oops, something went wrong.
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,20 @@ | ||
// Package user describes the methods to handle users needed for webauthn. | ||
package user | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/Darkness4/auth-htmx/database/user" | ||
"github.com/go-webauthn/webauthn/webauthn" | ||
) | ||
|
||
// Repository defines the user methods needed for webauthn. | ||
type Repository interface { | ||
GetOrCreateByName(ctx context.Context, name string) (*user.User, error) | ||
GetByName(ctx context.Context, name string) (*user.User, error) | ||
Get(ctx context.Context, id []byte) (*user.User, error) | ||
Create(ctx context.Context, name string, displayName string) (*user.User, error) | ||
AddCredential(ctx context.Context, id []byte, credential *webauthn.Credential) error | ||
UpdateCredential(ctx context.Context, credential *webauthn.Credential) error | ||
RemoveCredential(ctx context.Context, id []byte, credentialID []byte) error | ||
} |
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
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