feat(identity): add server sessions and audited mail recovery
This commit is contained in:
1 parent
20c03288d6
commit
4ee53d9a74
58 files changed
+5359
-567
No files matched your search
@@ -0,0 +1,65 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"github.com/ogen-go/ogen/ogenerrors"
|
||||
|
||||
"lincodex/backend/internal/adapter/primary/http/api"
|
||||
"lincodex/backend/internal/adapter/primary/http/problem"
|
||||
"lincodex/backend/internal/usecase/identity"
|
||||
)
|
||||
|
||||
// Handler is the composite implementation of the generated api.Handler.
|
||||
// Unimplemented operations stay on ogen's embedded fallback until a business
|
||||
// handler is added for them.
|
||||
type Handler struct {
|
||||
api.UnimplementedHandler
|
||||
|
||||
health *HealthHandler
|
||||
identity *IdentityHandler
|
||||
problems *problem.Responder
|
||||
}
|
||||
|
||||
var _ api.Handler = (*Handler)(nil)
|
||||
|
||||
// HandlerOption adds a business-area handler to Handler.
|
||||
type HandlerOption func(*Handler)
|
||||
|
||||
// WithIdentity serves the configured identity operations.
|
||||
func WithIdentity(identity *IdentityHandler) HandlerOption {
|
||||
return func(handler *Handler) { handler.identity = identity }
|
||||
}
|
||||
|
||||
func NewHandler(health *HealthHandler, problems *problem.Responder, options ...HandlerOption) *Handler {
|
||||
handler := &Handler{health: health, problems: problems}
|
||||
for _, option := range options {
|
||||
option(handler)
|
||||
}
|
||||
return handler
|
||||
}
|
||||
|
||||
// NewError maps security failures to fixed public problems. Other errors are
|
||||
// passed to the responder, which logs them and does not expose their text.
|
||||
func (handler *Handler) NewError(ctx context.Context, err error) *api.ProblemStatusCode {
|
||||
var securityError *ogenerrors.SecurityError
|
||||
if errors.As(err, &securityError) {
|
||||
switch {
|
||||
case errors.Is(securityError.Err, errCsrfCheckFailed):
|
||||
return problem.New(ctx, api.ProblemCodeCsrfCheckFailed)
|
||||
case errors.Is(securityError.Err, ogenerrors.ErrSecurityRequirementIsNotSatisfied):
|
||||
if _, ok := PrincipalFromContext(ctx); ok {
|
||||
return problem.New(ctx, api.ProblemCodeCsrfCheckFailed)
|
||||
}
|
||||
return problem.New(ctx, api.ProblemCodeUnauthenticated)
|
||||
case errors.Is(securityError.Err, ogenerrors.ErrSkipServerSecurity),
|
||||
errors.Is(securityError.Err, identity.ErrUnauthenticated),
|
||||
errors.Is(securityError.Err, errSessionsNotImplemented):
|
||||
return problem.New(ctx, api.ProblemCodeUnauthenticated)
|
||||
default:
|
||||
return handler.problems.HandlerError(ctx, securityError.Err)
|
||||
}
|
||||
}
|
||||
return handler.problems.HandlerError(ctx, err)
|
||||
}
|
||||
@@ -0,0 +1,292 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"math"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"lincodex/backend/internal/adapter/primary/http/api"
|
||||
httpmiddleware "lincodex/backend/internal/adapter/primary/http/middleware"
|
||||
"lincodex/backend/internal/adapter/primary/http/problem"
|
||||
"lincodex/backend/internal/domain"
|
||||
"lincodex/backend/internal/usecase/identity"
|
||||
)
|
||||
|
||||
func (handler *Handler) RegisterAccount(
|
||||
ctx context.Context,
|
||||
request *api.RegistrationRequest,
|
||||
params api.RegisterAccountParams,
|
||||
) (api.RegisterAccountRes, error) {
|
||||
if handler.identity == nil {
|
||||
return handler.UnimplementedHandler.RegisterAccount(ctx, request, params)
|
||||
}
|
||||
return handler.identity.RegisterAccount(ctx, request, params)
|
||||
}
|
||||
|
||||
func (handler *Handler) ResendEmailVerification(
|
||||
ctx context.Context,
|
||||
request *api.EmailVerificationResendRequest,
|
||||
) (api.ResendEmailVerificationRes, error) {
|
||||
if handler.identity == nil {
|
||||
return handler.UnimplementedHandler.ResendEmailVerification(ctx, request)
|
||||
}
|
||||
return handler.identity.ResendEmailVerification(ctx, request)
|
||||
}
|
||||
|
||||
func (handler *Handler) ConfirmEmail(
|
||||
ctx context.Context,
|
||||
request *api.EmailVerificationRequest,
|
||||
params api.ConfirmEmailParams,
|
||||
) (api.ConfirmEmailRes, error) {
|
||||
if handler.identity == nil || handler.identity.confirmation == nil {
|
||||
return handler.UnimplementedHandler.ConfirmEmail(ctx, request, params)
|
||||
}
|
||||
return handler.identity.ConfirmEmail(ctx, request, params)
|
||||
}
|
||||
|
||||
func (handler *Handler) Login(ctx context.Context, request *api.LoginRequest) (api.LoginRes, error) {
|
||||
if handler.identity == nil || handler.identity.sessions == nil {
|
||||
return handler.UnimplementedHandler.Login(ctx, request)
|
||||
}
|
||||
return handler.identity.Login(ctx, request)
|
||||
}
|
||||
|
||||
func (handler *Handler) GetCurrentSession(ctx context.Context) (api.GetCurrentSessionRes, error) {
|
||||
if handler.identity == nil || handler.identity.sessions == nil {
|
||||
return handler.UnimplementedHandler.GetCurrentSession(ctx)
|
||||
}
|
||||
return handler.identity.GetCurrentSession(ctx)
|
||||
}
|
||||
|
||||
func (handler *Handler) Logout(ctx context.Context) (api.LogoutRes, error) {
|
||||
if handler.identity == nil || handler.identity.sessions == nil {
|
||||
return handler.UnimplementedHandler.Logout(ctx)
|
||||
}
|
||||
return handler.identity.Logout(ctx)
|
||||
}
|
||||
|
||||
func (handler *IdentityHandler) RegisterAccount(
|
||||
ctx context.Context,
|
||||
request *api.RegistrationRequest,
|
||||
params api.RegisterAccountParams,
|
||||
) (api.RegisterAccountRes, error) {
|
||||
err := handler.registration.Register(ctx, identity.RegisterCommand{
|
||||
IdempotencyKey: params.IdempotencyKey,
|
||||
Email: string(request.Email),
|
||||
Password: string(request.Password),
|
||||
Scenario: string(request.Scenario),
|
||||
ConsentTextVersion: string(request.ConsentC1.TextVersion),
|
||||
ClientKey: clientKey(ctx),
|
||||
})
|
||||
switch {
|
||||
case err == nil:
|
||||
return accepted(), nil
|
||||
case errors.Is(err, identity.ErrInvalidField):
|
||||
return (*api.RegisterAccountBadRequest)(&invalidFieldProblem(ctx, err).Response), nil
|
||||
case errors.Is(err, identity.ErrIdempotencyKeyReused):
|
||||
return (*api.RegisterAccountUnprocessableEntity)(&problem.New(ctx, api.ProblemCodeIdempotencyKeyReused).Response), nil
|
||||
}
|
||||
if limited, ok := rateLimited(ctx, err); ok {
|
||||
return limited, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func (handler *IdentityHandler) ResendEmailVerification(
|
||||
ctx context.Context,
|
||||
request *api.EmailVerificationResendRequest,
|
||||
) (api.ResendEmailVerificationRes, error) {
|
||||
if handler.registration == nil {
|
||||
return nil, errors.New("IdentityHandler.ResendEmailVerification - registration is not configured")
|
||||
}
|
||||
err := handler.registration.ResendVerification(ctx, identity.ResendCommand{
|
||||
Email: string(request.Email),
|
||||
ClientKey: clientKey(ctx),
|
||||
})
|
||||
switch {
|
||||
case err == nil:
|
||||
return accepted(), nil
|
||||
case errors.Is(err, identity.ErrInvalidField):
|
||||
return (*api.ResendEmailVerificationBadRequest)(&invalidFieldProblem(ctx, err).Response), nil
|
||||
}
|
||||
if limited, ok := rateLimited(ctx, err); ok {
|
||||
return limited, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func (handler *IdentityHandler) ConfirmEmail(
|
||||
ctx context.Context,
|
||||
request *api.EmailVerificationRequest,
|
||||
params api.ConfirmEmailParams,
|
||||
) (api.ConfirmEmailRes, error) {
|
||||
if handler.confirmation == nil {
|
||||
return nil, errors.New("IdentityHandler.ConfirmEmail - confirmation is not configured")
|
||||
}
|
||||
origin, ok := params.Origin.Get()
|
||||
if !ok || strings.TrimSpace(origin) == "" || origin != handler.confirmationOrigin {
|
||||
return (*api.ConfirmEmailForbidden)(&problem.New(ctx, api.ProblemCodeCsrfCheckFailed).Response), nil
|
||||
}
|
||||
|
||||
result, err := handler.confirmation.Confirm(ctx, identity.ConfirmCommand{
|
||||
Token: string(request.Token),
|
||||
Password: request.Password,
|
||||
ClientKey: clientKey(ctx),
|
||||
})
|
||||
switch {
|
||||
case err == nil:
|
||||
return &api.EmailVerificationResult{
|
||||
EmailVerified: api.EmailVerificationResultEmailVerifiedTrue,
|
||||
Scenario: api.AccountScenario(result.Scenario),
|
||||
OnboardingStep: api.OnboardingStep(result.OnboardingStep),
|
||||
}, nil
|
||||
case errors.Is(err, identity.ErrVerificationTokenInvalid):
|
||||
return (*api.ConfirmEmailBadRequest)(&problem.New(ctx, api.ProblemCodeVerificationTokenInvalid).Response), nil
|
||||
case errors.Is(err, identity.ErrVerificationTokenExpired):
|
||||
return (*api.ConfirmEmailBadRequest)(&problem.New(ctx, api.ProblemCodeVerificationTokenExpired).Response), nil
|
||||
}
|
||||
if limited, ok := rateLimited(ctx, err); ok {
|
||||
return limited, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func (handler *IdentityHandler) Login(ctx context.Context, request *api.LoginRequest) (api.LoginRes, error) {
|
||||
if !originAllowed(ctx, handler.sessionOrigin) {
|
||||
return (*api.LoginForbidden)(&problem.New(ctx, api.ProblemCodeCsrfCheckFailed).Response), nil
|
||||
}
|
||||
result, err := handler.sessions.Login(ctx, identity.LoginCommand{
|
||||
Email: string(request.Email),
|
||||
Password: string(request.Password),
|
||||
ClientKey: clientKey(ctx),
|
||||
Incoming: httpmiddleware.IncomingSessionToken(ctx),
|
||||
})
|
||||
switch {
|
||||
case err == nil:
|
||||
return &api.SessionHeaders{
|
||||
CacheControl: api.CacheControlNoStoreNoStore,
|
||||
SetCookie: sessionCookie(result.Token, result.Session),
|
||||
Response: api.Session{
|
||||
Account: accountFromUser(result.User),
|
||||
CsrfToken: api.CsrfToken(result.CSRFToken),
|
||||
},
|
||||
}, nil
|
||||
case errors.Is(err, identity.ErrInvalidField):
|
||||
return (*api.LoginBadRequest)(&invalidFieldProblem(ctx, err).Response), nil
|
||||
case errors.Is(err, identity.ErrInvalidCredentials):
|
||||
return (*api.LoginUnauthorized)(&problem.New(ctx, api.ProblemCodeInvalidCredentials).Response), nil
|
||||
case errors.Is(err, identity.ErrEmailNotVerified):
|
||||
return (*api.LoginForbidden)(&problem.New(ctx, api.ProblemCodeEmailNotVerified).Response), nil
|
||||
}
|
||||
if limited, ok := rateLimited(ctx, err); ok {
|
||||
return limited, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func (handler *IdentityHandler) GetCurrentSession(ctx context.Context) (api.GetCurrentSessionRes, error) {
|
||||
session, ok := sessionFromContext(ctx)
|
||||
if !ok || !session.EmailVerified {
|
||||
return unauthenticatedProblemResponse(ctx), nil
|
||||
}
|
||||
return &api.GetCurrentSessionOKHeaders{
|
||||
CacheControl: api.CacheControlNoStoreNoStore,
|
||||
Response: api.Session{
|
||||
Account: accountFromUser(session.User),
|
||||
CsrfToken: api.CsrfToken(session.CSRFToken),
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (handler *IdentityHandler) Logout(ctx context.Context) (api.LogoutRes, error) {
|
||||
session, ok := sessionFromContext(ctx)
|
||||
if !ok || !session.EmailVerified {
|
||||
return unauthenticatedProblemResponse(ctx), nil
|
||||
}
|
||||
if err := handler.sessions.Logout(ctx, session.SessionID); err != nil {
|
||||
if errors.Is(err, identity.ErrUnauthenticated) {
|
||||
return unauthenticatedProblemResponse(ctx), nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
return &api.LogoutNoContent{SetCookie: ExpiredSessionCookie()}, nil
|
||||
}
|
||||
|
||||
func accepted() *api.IdentityRequestAccepted {
|
||||
return &api.IdentityRequestAccepted{Status: api.IdentityRequestAcceptedStatusAccepted}
|
||||
}
|
||||
|
||||
// clientKey is the limiter key of the client address resolved through trusted
|
||||
// proxies. Without the middleware only per-address limits apply.
|
||||
func clientKey(ctx context.Context) string {
|
||||
address, ok := httpmiddleware.ClientAddr(ctx)
|
||||
if !ok {
|
||||
return ""
|
||||
}
|
||||
return httpmiddleware.LimiterKey(address)
|
||||
}
|
||||
|
||||
func invalidFieldProblem(ctx context.Context, err error) *api.ProblemStatusCode {
|
||||
field, ok := errors.AsType[*identity.InvalidFieldError](err)
|
||||
if !ok {
|
||||
return problem.InvalidField(ctx, api.ProblemFieldLocationBody, "")
|
||||
}
|
||||
location := api.ProblemFieldLocationBody
|
||||
if field.Pointer == "/Idempotency-Key" {
|
||||
location = api.ProblemFieldLocationHeader
|
||||
}
|
||||
return problem.InvalidField(ctx, location, field.Pointer)
|
||||
}
|
||||
|
||||
func rateLimited(ctx context.Context, err error) (*api.TooManyRequestsHeaders, bool) {
|
||||
limited, ok := errors.AsType[*identity.RateLimitedError](err)
|
||||
if !ok {
|
||||
return nil, false
|
||||
}
|
||||
return problem.RateLimited(ctx, wholeSeconds(limited.RetryAfter)), true
|
||||
}
|
||||
|
||||
func wholeSeconds(wait time.Duration) int32 {
|
||||
return int32(min(math.Ceil(wait.Seconds()), math.MaxInt32))
|
||||
}
|
||||
|
||||
func originAllowed(ctx context.Context, expected string) bool {
|
||||
origin, ok := httpmiddleware.RequestOrigin(ctx)
|
||||
return ok && origin == expected
|
||||
}
|
||||
|
||||
func unauthenticatedProblemResponse(ctx context.Context) *api.Problem {
|
||||
response := problem.New(ctx, api.ProblemCodeUnauthenticated).Response
|
||||
return &response
|
||||
}
|
||||
|
||||
func sessionCookie(token domain.SecretToken, session domain.Session) string {
|
||||
maxAge := int(math.Ceil(session.ExpiresAt.Sub(session.CreatedAt).Seconds()))
|
||||
cookie := &http.Cookie{
|
||||
Name: httpmiddleware.SessionCookieName,
|
||||
Value: token.Reveal(),
|
||||
Path: "/",
|
||||
MaxAge: maxAge,
|
||||
Expires: session.ExpiresAt.UTC(),
|
||||
Secure: true,
|
||||
HttpOnly: true,
|
||||
SameSite: http.SameSiteStrictMode,
|
||||
}
|
||||
return cookie.String()
|
||||
}
|
||||
|
||||
func ExpiredSessionCookie() string {
|
||||
return (&http.Cookie{
|
||||
Name: httpmiddleware.SessionCookieName,
|
||||
Value: "",
|
||||
Path: "/",
|
||||
MaxAge: -1,
|
||||
Expires: time.Unix(1, 0).UTC(),
|
||||
Secure: true,
|
||||
HttpOnly: true,
|
||||
SameSite: http.SameSiteStrictMode,
|
||||
}).String()
|
||||
}
|
||||
@@ -1,98 +0,0 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"lincodex/backend/internal/adapter/primary/http/api"
|
||||
"lincodex/backend/internal/adapter/primary/http/problem"
|
||||
)
|
||||
|
||||
// Handler is the composite implementation of the generated api.Handler.
|
||||
//
|
||||
// The embedded api.UnimplementedHandler keeps the backend compiling after the
|
||||
// contract gains an operation that has no business implementation yet. Such an
|
||||
// operation returns ht.ErrNotImplemented without side effects. The generated
|
||||
// server passes that error to the ErrorHandler configured in the router, which
|
||||
// answers 501 with code not_implemented, before it would call NewError.
|
||||
//
|
||||
// The contract's common default response makes ogen add NewError to
|
||||
// api.Handler. The embedded api.UnimplementedHandler.NewError returns a zero
|
||||
// status code that the generated encoder sends as HTTP 200, so Handler defines
|
||||
// NewError explicitly: *ogenerrors.SecurityError, which the generated server
|
||||
// passes to it directly, becomes 401, and every other error becomes 500 with a
|
||||
// fixed body and is logged here, never exposing err.Error(). Errors of the
|
||||
// generated *api.ProblemStatusCode type are encoded before NewError is called,
|
||||
// so operations return them for expected failures such as 403 or 404.
|
||||
//
|
||||
// Each implemented operation gets an explicit method here that delegates to
|
||||
// the handler owning it. Each implemented operation also gets a router test
|
||||
// through v1.NewHandler that asserts a non-501 response, because renaming an
|
||||
// operationId would otherwise silently fall back to the embedded 501 method.
|
||||
type Handler struct {
|
||||
api.UnimplementedHandler
|
||||
|
||||
health *HealthHandler
|
||||
identity *IdentityHandler
|
||||
problems *problem.Responder
|
||||
}
|
||||
|
||||
var _ api.Handler = (*Handler)(nil)
|
||||
|
||||
// HandlerOption adds the handler of a business area to Handler.
|
||||
type HandlerOption func(*Handler)
|
||||
|
||||
// WithIdentity serves the registration operations. A nil handler leaves them
|
||||
// to the embedded api.UnimplementedHandler, as when no database is
|
||||
// configured.
|
||||
func WithIdentity(identity *IdentityHandler) HandlerOption {
|
||||
return func(handler *Handler) { handler.identity = identity }
|
||||
}
|
||||
|
||||
func NewHandler(health *HealthHandler, problems *problem.Responder, options ...HandlerOption) *Handler {
|
||||
handler := &Handler{health: health, problems: problems}
|
||||
for _, option := range options {
|
||||
option(handler)
|
||||
}
|
||||
return handler
|
||||
}
|
||||
|
||||
func (handler *Handler) GetHealthz(ctx context.Context) (*api.HealthResponse, error) {
|
||||
return handler.health.GetHealthz(ctx)
|
||||
}
|
||||
|
||||
func (handler *Handler) RegisterAccount(
|
||||
ctx context.Context,
|
||||
request *api.RegistrationRequest,
|
||||
params api.RegisterAccountParams,
|
||||
) (api.RegisterAccountRes, error) {
|
||||
if handler.identity == nil {
|
||||
return handler.UnimplementedHandler.RegisterAccount(ctx, request, params)
|
||||
}
|
||||
return handler.identity.RegisterAccount(ctx, request, params)
|
||||
}
|
||||
|
||||
func (handler *Handler) ResendEmailVerification(
|
||||
ctx context.Context,
|
||||
request *api.EmailVerificationResendRequest,
|
||||
) (api.ResendEmailVerificationRes, error) {
|
||||
if handler.identity == nil {
|
||||
return handler.UnimplementedHandler.ResendEmailVerification(ctx, request)
|
||||
}
|
||||
return handler.identity.ResendEmailVerification(ctx, request)
|
||||
}
|
||||
|
||||
func (handler *Handler) ConfirmEmail(
|
||||
ctx context.Context,
|
||||
request *api.EmailVerificationRequest,
|
||||
params api.ConfirmEmailParams,
|
||||
) (api.ConfirmEmailRes, error) {
|
||||
if handler.identity == nil || handler.identity.confirmation == nil {
|
||||
return handler.UnimplementedHandler.ConfirmEmail(ctx, request, params)
|
||||
}
|
||||
return handler.identity.ConfirmEmail(ctx, request, params)
|
||||
}
|
||||
|
||||
// NewError implements api.Handler for errors returned by operations.
|
||||
func (handler *Handler) NewError(ctx context.Context, err error) *api.ProblemStatusCode {
|
||||
return handler.problems.HandlerError(ctx, err)
|
||||
}
|
||||
@@ -23,6 +23,10 @@ func (handler *HealthHandler) GetHealthz(context.Context) (*api.HealthResponse,
|
||||
return &api.HealthResponse{Status: api.HealthResponseStatusOk}, nil
|
||||
}
|
||||
|
||||
func (handler *Handler) GetHealthz(ctx context.Context) (*api.HealthResponse, error) {
|
||||
return handler.health.GetHealthz(ctx)
|
||||
}
|
||||
|
||||
func (handler *HealthHandler) Healthz(w http.ResponseWriter, _ *http.Request) {
|
||||
writeStatus(w, http.StatusOK, "ok")
|
||||
}
|
||||
|
||||
@@ -2,14 +2,7 @@ package v1
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"math"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"lincodex/backend/internal/adapter/primary/http/api"
|
||||
httpmiddleware "lincodex/backend/internal/adapter/primary/http/middleware"
|
||||
"lincodex/backend/internal/adapter/primary/http/problem"
|
||||
"lincodex/backend/internal/usecase/identity"
|
||||
)
|
||||
|
||||
@@ -28,12 +21,13 @@ type EmailConfirmation interface {
|
||||
// IdentityHandlerOption configures an optional identity operation.
|
||||
type IdentityHandlerOption func(*IdentityHandler)
|
||||
|
||||
// IdentityHandler serves anonymous registration, resend, and confirmation
|
||||
// operations.
|
||||
// IdentityHandler serves authentication and account identity operations.
|
||||
type IdentityHandler struct {
|
||||
registration AccountRegistration
|
||||
confirmation EmailConfirmation
|
||||
confirmationOrigin string
|
||||
sessions *identity.SessionService
|
||||
sessionOrigin string
|
||||
}
|
||||
|
||||
func NewIdentityHandler(registration AccountRegistration, options ...IdentityHandlerOption) *IdentityHandler {
|
||||
@@ -53,130 +47,12 @@ func WithEmailConfirmation(confirmation EmailConfirmation, publicOrigin string)
|
||||
}
|
||||
}
|
||||
|
||||
func (handler *IdentityHandler) RegisterAccount(
|
||||
ctx context.Context,
|
||||
request *api.RegistrationRequest,
|
||||
params api.RegisterAccountParams,
|
||||
) (api.RegisterAccountRes, error) {
|
||||
err := handler.registration.Register(ctx, identity.RegisterCommand{
|
||||
IdempotencyKey: params.IdempotencyKey,
|
||||
Email: string(request.Email),
|
||||
Password: string(request.Password),
|
||||
Scenario: string(request.Scenario),
|
||||
ConsentTextVersion: string(request.ConsentC1.TextVersion),
|
||||
ClientKey: clientKey(ctx),
|
||||
})
|
||||
switch {
|
||||
case err == nil:
|
||||
return accepted(), nil
|
||||
case errors.Is(err, identity.ErrInvalidField):
|
||||
return (*api.RegisterAccountBadRequest)(&invalidFieldProblem(ctx, err).Response), nil
|
||||
case errors.Is(err, identity.ErrIdempotencyKeyReused):
|
||||
return (*api.RegisterAccountUnprocessableEntity)(&problem.New(ctx, api.ProblemCodeIdempotencyKeyReused).Response), nil
|
||||
// WithSessionService serves login, current account, current session, and
|
||||
// logout against PostgreSQL-backed sessions. Unsafe browser operations compare
|
||||
// Origin exactly with the configured public origin.
|
||||
func WithSessionService(sessions *identity.SessionService, publicOrigin string) IdentityHandlerOption {
|
||||
return func(handler *IdentityHandler) {
|
||||
handler.sessions = sessions
|
||||
handler.sessionOrigin = publicOrigin
|
||||
}
|
||||
if limited, ok := rateLimited(ctx, err); ok {
|
||||
return limited, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func (handler *IdentityHandler) ResendEmailVerification(
|
||||
ctx context.Context,
|
||||
request *api.EmailVerificationResendRequest,
|
||||
) (api.ResendEmailVerificationRes, error) {
|
||||
if handler.registration == nil {
|
||||
return nil, errors.New("IdentityHandler.ResendEmailVerification - registration is not configured")
|
||||
}
|
||||
err := handler.registration.ResendVerification(ctx, identity.ResendCommand{
|
||||
Email: string(request.Email),
|
||||
ClientKey: clientKey(ctx),
|
||||
})
|
||||
switch {
|
||||
case err == nil:
|
||||
return accepted(), nil
|
||||
case errors.Is(err, identity.ErrInvalidField):
|
||||
return (*api.ResendEmailVerificationBadRequest)(&invalidFieldProblem(ctx, err).Response), nil
|
||||
}
|
||||
if limited, ok := rateLimited(ctx, err); ok {
|
||||
return limited, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func (handler *IdentityHandler) ConfirmEmail(
|
||||
ctx context.Context,
|
||||
request *api.EmailVerificationRequest,
|
||||
params api.ConfirmEmailParams,
|
||||
) (api.ConfirmEmailRes, error) {
|
||||
if handler.confirmation == nil {
|
||||
return nil, errors.New("IdentityHandler.ConfirmEmail - confirmation is not configured")
|
||||
}
|
||||
origin, ok := params.Origin.Get()
|
||||
if !ok || strings.TrimSpace(origin) == "" || origin != handler.confirmationOrigin {
|
||||
return (*api.ConfirmEmailForbidden)(&problem.New(ctx, api.ProblemCodeCsrfCheckFailed).Response), nil
|
||||
}
|
||||
|
||||
result, err := handler.confirmation.Confirm(ctx, identity.ConfirmCommand{
|
||||
Token: string(request.Token),
|
||||
Password: request.Password,
|
||||
ClientKey: clientKey(ctx),
|
||||
})
|
||||
switch {
|
||||
case err == nil:
|
||||
return &api.EmailVerificationResult{
|
||||
EmailVerified: api.EmailVerificationResultEmailVerifiedTrue,
|
||||
Scenario: api.AccountScenario(result.Scenario),
|
||||
OnboardingStep: api.OnboardingStep(result.OnboardingStep),
|
||||
}, nil
|
||||
case errors.Is(err, identity.ErrVerificationTokenInvalid):
|
||||
return (*api.ConfirmEmailBadRequest)(&problem.New(ctx, api.ProblemCodeVerificationTokenInvalid).Response), nil
|
||||
case errors.Is(err, identity.ErrVerificationTokenExpired):
|
||||
return (*api.ConfirmEmailBadRequest)(&problem.New(ctx, api.ProblemCodeVerificationTokenExpired).Response), nil
|
||||
}
|
||||
if limited, ok := rateLimited(ctx, err); ok {
|
||||
return limited, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func accepted() *api.IdentityRequestAccepted {
|
||||
return &api.IdentityRequestAccepted{Status: api.IdentityRequestAcceptedStatusAccepted}
|
||||
}
|
||||
|
||||
// clientKey is the limiter key of the client network address that the
|
||||
// ClientIP middleware resolved. Without it, for example when the middleware
|
||||
// is not mounted, the per-client limit is skipped and only the per-address
|
||||
// limits apply: a shared bucket would let one client lock everyone out.
|
||||
func clientKey(ctx context.Context) string {
|
||||
address, ok := httpmiddleware.ClientAddr(ctx)
|
||||
if !ok {
|
||||
return ""
|
||||
}
|
||||
return httpmiddleware.LimiterKey(address)
|
||||
}
|
||||
|
||||
func invalidFieldProblem(ctx context.Context, err error) *api.ProblemStatusCode {
|
||||
field, ok := errors.AsType[*identity.InvalidFieldError](err)
|
||||
if !ok {
|
||||
return problem.InvalidField(ctx, api.ProblemFieldLocationBody, "")
|
||||
}
|
||||
location := api.ProblemFieldLocationBody
|
||||
if field.Pointer == "/Idempotency-Key" {
|
||||
location = api.ProblemFieldLocationHeader
|
||||
}
|
||||
return problem.InvalidField(ctx, location, field.Pointer)
|
||||
}
|
||||
|
||||
func rateLimited(ctx context.Context, err error) (*api.TooManyRequestsHeaders, bool) {
|
||||
limited, ok := errors.AsType[*identity.RateLimitedError](err)
|
||||
if !ok {
|
||||
return nil, false
|
||||
}
|
||||
return problem.RateLimited(ctx, wholeSeconds(limited.RetryAfter)), true
|
||||
}
|
||||
|
||||
// wholeSeconds rounds a wait up, so a client that waits the stated time is
|
||||
// not refused again for the remainder.
|
||||
func wholeSeconds(wait time.Duration) int32 {
|
||||
return int32(min(math.Ceil(wait.Seconds()), math.MaxInt32))
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
"lincodex/backend/internal/domain"
|
||||
"lincodex/backend/internal/usecase/identity"
|
||||
)
|
||||
|
||||
type principalContextKey struct{}
|
||||
|
||||
type sessionContextKey struct{}
|
||||
|
||||
// Principal is the authenticated account identity available to handwritten
|
||||
// HTTP handlers. The ID comes from PostgreSQL session state, never a request
|
||||
// body or path parameter.
|
||||
type Principal struct {
|
||||
UserID uuid.UUID
|
||||
EmailVerified bool
|
||||
}
|
||||
|
||||
type authenticatedSession struct {
|
||||
Principal
|
||||
|
||||
User domain.User
|
||||
SessionID uuid.UUID
|
||||
CSRFToken string
|
||||
}
|
||||
|
||||
// PrincipalFromContext returns the account identity installed by session
|
||||
// security middleware, if the request has an authenticated session.
|
||||
func PrincipalFromContext(ctx context.Context) (Principal, bool) {
|
||||
if ctx == nil {
|
||||
return Principal{}, false
|
||||
}
|
||||
principal, ok := ctx.Value(principalContextKey{}).(Principal)
|
||||
return principal, ok && principal.UserID != uuid.Nil
|
||||
}
|
||||
|
||||
func withAuthenticatedSession(ctx context.Context, session identity.AuthenticatedSession) context.Context {
|
||||
principal := Principal{UserID: session.User.ID, EmailVerified: session.User.EmailVerified()}
|
||||
ctx = context.WithValue(ctx, principalContextKey{}, principal)
|
||||
return context.WithValue(ctx, sessionContextKey{}, authenticatedSession{
|
||||
Principal: principal,
|
||||
User: session.User,
|
||||
SessionID: session.SessionID,
|
||||
CSRFToken: session.CSRFToken,
|
||||
})
|
||||
}
|
||||
|
||||
func sessionFromContext(ctx context.Context) (authenticatedSession, bool) {
|
||||
if ctx == nil {
|
||||
return authenticatedSession{}, false
|
||||
}
|
||||
session, ok := ctx.Value(sessionContextKey{}).(authenticatedSession)
|
||||
return session, ok && session.UserID != uuid.Nil && session.SessionID != uuid.Nil
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/hmac"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/ogen-go/ogen/ogenerrors"
|
||||
|
||||
"lincodex/backend/internal/adapter/primary/http/api"
|
||||
httpmiddleware "lincodex/backend/internal/adapter/primary/http/middleware"
|
||||
"lincodex/backend/internal/usecase/identity"
|
||||
)
|
||||
|
||||
var errCsrfCheckFailed = errors.New("CSRF check failed")
|
||||
|
||||
type SessionAuthenticator interface {
|
||||
Authenticate(ctx context.Context, rawToken string) (identity.AuthenticatedSession, error)
|
||||
}
|
||||
|
||||
// SessionSecurity authenticates only the three session operations enabled in
|
||||
// this implementation. All other protected operations remain unavailable until their
|
||||
// handlers are implemented.
|
||||
type SessionSecurity struct {
|
||||
authenticator SessionAuthenticator
|
||||
publicOrigin string
|
||||
}
|
||||
|
||||
var _ api.SecurityHandler = (*SessionSecurity)(nil)
|
||||
|
||||
func NewSessionSecurity(authenticator SessionAuthenticator, publicOrigin string) *SessionSecurity {
|
||||
return &SessionSecurity{authenticator: authenticator, publicOrigin: publicOrigin}
|
||||
}
|
||||
|
||||
func (handler *IdentityHandler) SessionSecurity() *SessionSecurity {
|
||||
if handler == nil || handler.sessions == nil {
|
||||
return NewSessionSecurity(nil, "")
|
||||
}
|
||||
return NewSessionSecurity(handler.sessions, handler.sessionOrigin)
|
||||
}
|
||||
|
||||
func (security *SessionSecurity) HandleSessionCookie(
|
||||
ctx context.Context,
|
||||
operation api.OperationName,
|
||||
cookie api.SessionCookie,
|
||||
) (context.Context, error) {
|
||||
if !sessionOperationAllowed(operation) || security == nil || security.authenticator == nil ||
|
||||
!httpmiddleware.SessionCookieMatches(ctx, cookie.APIKey) {
|
||||
return ctx, ogenerrors.ErrSkipServerSecurity
|
||||
}
|
||||
authenticated, err := security.authenticator.Authenticate(ctx, cookie.APIKey)
|
||||
if errors.Is(err, identity.ErrUnauthenticated) {
|
||||
return ctx, ogenerrors.ErrSkipServerSecurity
|
||||
}
|
||||
if err != nil {
|
||||
return ctx, fmt.Errorf("SessionSecurity.HandleSessionCookie - authenticate session: %w", err)
|
||||
}
|
||||
return withAuthenticatedSession(ctx, authenticated), nil
|
||||
}
|
||||
|
||||
func (security *SessionSecurity) HandleSessionCsrf(
|
||||
ctx context.Context,
|
||||
operation api.OperationName,
|
||||
csrf api.SessionCsrf,
|
||||
) (context.Context, error) {
|
||||
if operation != api.LogoutOperation {
|
||||
return ctx, ogenerrors.ErrSkipServerSecurity
|
||||
}
|
||||
authenticated, ok := sessionFromContext(ctx)
|
||||
if !ok {
|
||||
return ctx, ogenerrors.ErrSkipServerSecurity
|
||||
}
|
||||
origin, hasOrigin := httpmiddleware.RequestOrigin(ctx)
|
||||
if security == nil || !hasOrigin || origin != security.publicOrigin || authenticated.CSRFToken == "" ||
|
||||
!hmac.Equal([]byte(authenticated.CSRFToken), []byte(csrf.APIKey)) {
|
||||
return ctx, errCsrfCheckFailed
|
||||
}
|
||||
return ctx, nil
|
||||
}
|
||||
|
||||
func sessionOperationAllowed(operation api.OperationName) bool {
|
||||
switch operation {
|
||||
case api.GetCurrentSessionOperation, api.GetCurrentAccountOperation, api.LogoutOperation:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,200 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/ogen-go/ogen/ogenerrors"
|
||||
|
||||
"lincodex/backend/internal/adapter/primary/http/api"
|
||||
httpmiddleware "lincodex/backend/internal/adapter/primary/http/middleware"
|
||||
"lincodex/backend/internal/adapter/primary/http/problem"
|
||||
"lincodex/backend/internal/domain"
|
||||
"lincodex/backend/internal/usecase/identity"
|
||||
)
|
||||
|
||||
type sessionAuthenticatorStub struct {
|
||||
result identity.AuthenticatedSession
|
||||
err error
|
||||
calls int
|
||||
}
|
||||
|
||||
func (authenticator *sessionAuthenticatorStub) Authenticate(_ context.Context, _ string) (identity.AuthenticatedSession, error) {
|
||||
authenticator.calls++
|
||||
return authenticator.result, authenticator.err
|
||||
}
|
||||
|
||||
func TestSessionSecurityAddsPrincipalOnlyForTheThreeEnabledOperations(t *testing.T) {
|
||||
token, err := domain.NewSecretToken()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
userID := uuid.New()
|
||||
verifiedAt := time.Now()
|
||||
authenticator := &sessionAuthenticatorStub{result: identity.AuthenticatedSession{
|
||||
User: domain.User{ID: userID, EmailVerifiedAt: &verifiedAt},
|
||||
SessionID: uuid.New(),
|
||||
CSRFToken: "bound-csrf-token",
|
||||
}}
|
||||
security := NewSessionSecurity(authenticator, "https://app.example.com")
|
||||
|
||||
for _, operation := range []api.OperationName{
|
||||
api.GetCurrentAccountOperation,
|
||||
api.GetCurrentSessionOperation,
|
||||
api.LogoutOperation,
|
||||
} {
|
||||
ctx := sessionRequestContext(t, token.Reveal(), "https://app.example.com")
|
||||
authenticated, err := security.HandleSessionCookie(ctx, operation, api.SessionCookie{APIKey: token.Reveal()})
|
||||
if err != nil {
|
||||
t.Fatalf("HandleSessionCookie(%s) error = %v", operation, err)
|
||||
}
|
||||
principal, ok := PrincipalFromContext(authenticated)
|
||||
if !ok || principal.UserID != userID || !principal.EmailVerified {
|
||||
t.Fatalf("PrincipalFromContext(%s) = %+v, %v", operation, principal, ok)
|
||||
}
|
||||
}
|
||||
if authenticator.calls != 3 {
|
||||
t.Fatalf("authentication calls = %d, want one for each allowed operation", authenticator.calls)
|
||||
}
|
||||
|
||||
ctx := sessionRequestContext(t, token.Reveal(), "https://app.example.com")
|
||||
_, err = security.HandleSessionCookie(ctx, api.GetMyProfileOperation, api.SessionCookie{APIKey: token.Reveal()})
|
||||
if !errors.Is(err, ogenerrors.ErrSkipServerSecurity) || authenticator.calls != 3 {
|
||||
t.Fatalf("disallowed operation error=%v authentication calls=%d", err, authenticator.calls)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLogoutRequiresExactOriginAndSessionBoundCSRF(t *testing.T) {
|
||||
token, err := domain.NewSecretToken()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
verifiedAt := time.Now()
|
||||
authenticator := &sessionAuthenticatorStub{result: identity.AuthenticatedSession{
|
||||
User: domain.User{ID: uuid.New(), EmailVerifiedAt: &verifiedAt},
|
||||
SessionID: uuid.New(),
|
||||
CSRFToken: "csrf-for-this-session",
|
||||
}}
|
||||
security := NewSessionSecurity(authenticator, "https://app.example.com")
|
||||
|
||||
for _, test := range []struct {
|
||||
name string
|
||||
origin string
|
||||
csrf string
|
||||
wantErr error
|
||||
}{
|
||||
{name: "valid pair", origin: "https://app.example.com", csrf: "csrf-for-this-session"},
|
||||
{name: "wrong token", origin: "https://app.example.com", csrf: "csrf-from-another-session", wantErr: errCsrfCheckFailed},
|
||||
{name: "wrong origin", origin: "https://attacker.example", csrf: "csrf-for-this-session", wantErr: errCsrfCheckFailed},
|
||||
{name: "missing origin", csrf: "csrf-for-this-session", wantErr: errCsrfCheckFailed},
|
||||
} {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
ctx := sessionRequestContext(t, token.Reveal(), test.origin)
|
||||
ctx, err := security.HandleSessionCookie(ctx, api.LogoutOperation, api.SessionCookie{APIKey: token.Reveal()})
|
||||
if err != nil {
|
||||
t.Fatalf("HandleSessionCookie() error = %v", err)
|
||||
}
|
||||
_, err = security.HandleSessionCsrf(ctx, api.LogoutOperation, api.SessionCsrf{APIKey: test.csrf})
|
||||
if !errors.Is(err, test.wantErr) {
|
||||
t.Fatalf("HandleSessionCsrf() error = %v, want %v", err, test.wantErr)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestSecurityErrorsMapToUnauthenticatedOrCSRFProblem(t *testing.T) {
|
||||
logger := slog.New(slog.NewTextHandler(&strings.Builder{}, nil))
|
||||
handler := NewHandler(nil, problem.NewResponder(logger))
|
||||
tests := []struct {
|
||||
name string
|
||||
ctx context.Context
|
||||
err error
|
||||
want api.ProblemCode
|
||||
wantStatus int
|
||||
}{
|
||||
{name: "missing cookie", ctx: context.Background(), err: &ogenerrors.SecurityError{Err: ogenerrors.ErrSecurityRequirementIsNotSatisfied}, want: api.ProblemCodeUnauthenticated, wantStatus: http.StatusUnauthorized},
|
||||
{name: "missing csrf with principal", ctx: principalTestContext(), err: &ogenerrors.SecurityError{Err: ogenerrors.ErrSecurityRequirementIsNotSatisfied}, want: api.ProblemCodeCsrfCheckFailed, wantStatus: http.StatusForbidden},
|
||||
{name: "bad csrf", err: &ogenerrors.SecurityError{Security: "SessionCsrf", Err: errCsrfCheckFailed}, want: api.ProblemCodeCsrfCheckFailed, wantStatus: http.StatusForbidden},
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
ctx := test.ctx
|
||||
if ctx == nil {
|
||||
ctx = context.Background()
|
||||
}
|
||||
response := handler.NewError(ctx, test.err)
|
||||
if response.StatusCode != test.wantStatus || response.Response.Code != test.want {
|
||||
t.Fatalf("NewError() = %d %s, want %d %s", response.StatusCode, response.Response.Code, test.wantStatus, test.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestSessionCookiesUseRequiredAttributesAndClearStaleValues(t *testing.T) {
|
||||
token, err := domain.NewSecretToken()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
start := time.Date(2026, time.January, 2, 3, 4, 5, 0, time.UTC)
|
||||
session, err := domain.NewSession(domain.NewSessionInput{
|
||||
UserID: uuid.New(), TokenHash: token.Hash(), StartedAt: start, AbsoluteLifetime: 168 * time.Hour,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
response := &http.Response{Header: http.Header{"Set-Cookie": {sessionCookie(token, session)}}}
|
||||
cookies := response.Cookies()
|
||||
if len(cookies) != 1 {
|
||||
t.Fatalf("login cookie count = %d", len(cookies))
|
||||
}
|
||||
cookie := cookies[0]
|
||||
if cookie.Name != httpmiddleware.SessionCookieName || cookie.Value != token.Reveal() || cookie.Path != "/" ||
|
||||
cookie.Domain != "" || !cookie.Secure || !cookie.HttpOnly || cookie.SameSite != http.SameSiteStrictMode ||
|
||||
cookie.MaxAge != int((168*time.Hour).Seconds()) || !cookie.Expires.Equal(session.ExpiresAt) {
|
||||
t.Fatalf("login cookie attributes = %+v", cookie)
|
||||
}
|
||||
|
||||
clearResponse := &http.Response{Header: http.Header{"Set-Cookie": {ExpiredSessionCookie()}}}
|
||||
cleared := clearResponse.Cookies()
|
||||
if len(cleared) != 1 || cleared[0].Name != httpmiddleware.SessionCookieName || cleared[0].Value != "" ||
|
||||
cleared[0].Path != "/" || cleared[0].MaxAge >= 0 || !cleared[0].Secure || !cleared[0].HttpOnly ||
|
||||
cleared[0].SameSite != http.SameSiteStrictMode {
|
||||
t.Fatalf("logout clearing cookie = %+v", cleared)
|
||||
}
|
||||
}
|
||||
|
||||
func sessionRequestContext(t *testing.T, rawToken, origin string) context.Context {
|
||||
t.Helper()
|
||||
request := httptest.NewRequest(http.MethodGet, "/api/v1/identity/me", nil)
|
||||
if origin != "" {
|
||||
request.Header.Set("Origin", origin)
|
||||
}
|
||||
if rawToken != "" {
|
||||
request.AddCookie(&http.Cookie{Name: httpmiddleware.SessionCookieName, Value: rawToken})
|
||||
}
|
||||
capture := &sessionContextCapture{}
|
||||
httpmiddleware.SessionRequestMetadata()(capture).ServeHTTP(httptest.NewRecorder(), request)
|
||||
if capture.ctx == nil {
|
||||
t.Fatal("session request middleware did not pass a context")
|
||||
}
|
||||
return capture.ctx
|
||||
}
|
||||
|
||||
type sessionContextCapture struct {
|
||||
ctx context.Context
|
||||
}
|
||||
|
||||
func (capture *sessionContextCapture) ServeHTTP(_ http.ResponseWriter, request *http.Request) {
|
||||
capture.ctx = request.Context()
|
||||
}
|
||||
|
||||
func principalTestContext() context.Context {
|
||||
return context.WithValue(context.Background(), principalContextKey{}, Principal{UserID: uuid.New(), EmailVerified: true})
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"lincodex/backend/internal/adapter/primary/http/api"
|
||||
"lincodex/backend/internal/domain"
|
||||
)
|
||||
|
||||
func (handler *Handler) GetCurrentAccount(ctx context.Context) (api.GetCurrentAccountRes, error) {
|
||||
if handler.identity == nil || handler.identity.sessions == nil {
|
||||
return handler.UnimplementedHandler.GetCurrentAccount(ctx)
|
||||
}
|
||||
return handler.identity.GetCurrentAccount(ctx)
|
||||
}
|
||||
|
||||
func (handler *IdentityHandler) GetCurrentAccount(ctx context.Context) (api.GetCurrentAccountRes, error) {
|
||||
session, ok := sessionFromContext(ctx)
|
||||
if !ok || !session.EmailVerified {
|
||||
return unauthenticatedProblemResponse(ctx), nil
|
||||
}
|
||||
return &api.AccountHeaders{
|
||||
CacheControl: api.CacheControlNoStoreNoStore,
|
||||
Response: accountFromUser(session.User),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func accountFromUser(user domain.User) api.Account {
|
||||
return api.Account{
|
||||
ID: user.ID,
|
||||
Email: api.EmailAddress(user.Email.Address()),
|
||||
EmailVerified: user.EmailVerified(),
|
||||
Scenario: api.AccountScenario(user.Scenario),
|
||||
OnboardingStep: api.OnboardingStep(user.OnboardingStep),
|
||||
CreatedAt: api.Timestamp(user.CreatedAt),
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user