imports, comments and formatting
This commit is contained in:
parent
75a6ce1577
commit
91b8cc06b2
@ -26,5 +26,5 @@ func (bv *Verifier) Hash(password string) (string, error) {
|
||||
return "", fmt.Errorf("hash password: %w", err)
|
||||
}
|
||||
|
||||
return string(hash[:]), nil
|
||||
return string(hash), nil
|
||||
}
|
||||
|
@ -4,12 +4,12 @@ import (
|
||||
"os"
|
||||
)
|
||||
|
||||
// Config contains all needed configurations
|
||||
// Config contains all needed configurations.
|
||||
type Config struct {
|
||||
DatabaseConnection string
|
||||
}
|
||||
|
||||
// LoadConfig from path
|
||||
// LoadConfig from path.
|
||||
func LoadConfig() (*Config, error) {
|
||||
configuration := Config{
|
||||
DatabaseConnection: os.Getenv("BUDGETEER_DB"),
|
||||
|
@ -10,10 +10,10 @@ import (
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// TokenVerifier verifies Tokens
|
||||
// TokenVerifier verifies Tokens.
|
||||
type TokenVerifier struct{}
|
||||
|
||||
// Token contains everything to authenticate a user
|
||||
// Token contains everything to authenticate a user.
|
||||
type Token struct {
|
||||
username string
|
||||
name string
|
||||
@ -26,7 +26,7 @@ const (
|
||||
secret = "uditapbzuditagscwxuqdflgzpbu´ßiaefnlmzeßtrubiadern"
|
||||
)
|
||||
|
||||
// CreateToken creates a new token from username and name
|
||||
// CreateToken creates a new token from username and name.
|
||||
func (tv *TokenVerifier) CreateToken(user *postgres.User) (string, error) {
|
||||
token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{
|
||||
"usr": user.Email,
|
||||
@ -50,7 +50,7 @@ var (
|
||||
ErrTokenExpired = fmt.Errorf("token has expired")
|
||||
)
|
||||
|
||||
// VerifyToken verifys a given string-token
|
||||
// VerifyToken verifys a given string-token.
|
||||
func (tv *TokenVerifier) VerifyToken(tokenString string) (budgeteer.Token, error) {
|
||||
token, err := jwt.Parse(tokenString, func(token *jwt.Token) (interface{}, error) {
|
||||
if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok {
|
||||
|
@ -5,9 +5,8 @@ import (
|
||||
"embed"
|
||||
"fmt"
|
||||
|
||||
"github.com/pressly/goose/v3"
|
||||
|
||||
_ "github.com/jackc/pgx/v4/stdlib" // needed for pg connection
|
||||
"github.com/pressly/goose/v3"
|
||||
)
|
||||
|
||||
//go:embed schema/*.sql
|
||||
|
4
token.go
4
token.go
@ -5,7 +5,7 @@ import (
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// Token contains data that authenticates a user
|
||||
// Token contains data that authenticates a user.
|
||||
type Token interface {
|
||||
GetUsername() string
|
||||
GetName() string
|
||||
@ -13,7 +13,7 @@ type Token interface {
|
||||
GetID() uuid.UUID
|
||||
}
|
||||
|
||||
// TokenVerifier verifies a Token
|
||||
// TokenVerifier verifies a Token.
|
||||
type TokenVerifier interface {
|
||||
VerifyToken(string) (Token, error)
|
||||
CreateToken(*postgres.User) (string, error)
|
||||
|
Loading…
x
Reference in New Issue
Block a user