tokidoki/auth/interface.go

32 lines
629 B
Go
Raw Normal View History

2022-02-21 09:55:02 +00:00
package auth
import (
"context"
2022-02-21 09:55:02 +00:00
"net/http"
)
type contextKey string
var authCtxKey contextKey = "auth"
type AuthContext struct {
AuthMethod string
UserName string
// TODO more?
}
func NewContext(ctx context.Context, a *AuthContext) context.Context {
return context.WithValue(ctx, authCtxKey, a)
}
func FromContext(ctx context.Context) (*AuthContext, bool) {
a, ok := ctx.Value(authCtxKey).(*AuthContext)
return a, ok
}
2022-02-21 09:55:02 +00:00
// Abstracts the authentication backend for the server.
type AuthProvider interface {
// Returns HTTP middleware for performing authentication.
Middleware() func(http.Handler) http.Handler
}