feat: token based authentication, authenticate route, token storage
This commit is contained in:
@@ -14,18 +14,20 @@ import (
|
||||
// Define constants for the token scope. For now we just define the scope "activation"
|
||||
// but we'll add additional scopes later in the book.
|
||||
const (
|
||||
ScopeActivation = "activation"
|
||||
ScopeActivation = "activation"
|
||||
ScopeAuthentication = "authentication" // Include a new authentication scope.
|
||||
|
||||
)
|
||||
|
||||
// Define a Token struct to hold the data for an individual token. This includes the
|
||||
// plaintext and hashed versions of the token, associated user ID, expiry time and
|
||||
// scope.
|
||||
type Token struct {
|
||||
Plaintext string
|
||||
Hash []byte
|
||||
UserID int64
|
||||
Expiry time.Time
|
||||
Scope string
|
||||
Plaintext string `json:"token"`
|
||||
Hash []byte `json:"-"`
|
||||
UserID int64 `json:"-"`
|
||||
Expiry time.Time `json:"expiry"`
|
||||
Scope string `json:"-"`
|
||||
}
|
||||
|
||||
func generateToken(userID int64, ttl time.Duration, scope string) (*Token, error) {
|
||||
|
||||
Reference in New Issue
Block a user