implement auth using Auth0
This commit is contained in:
@@ -17,6 +17,7 @@ import (
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
|
||||
"ruben/inventory2/internal/domains/accounts"
|
||||
"ruben/inventory2/internal/domains/authentication"
|
||||
etsy_platform "ruben/inventory2/internal/domains/platforms/etsy"
|
||||
"ruben/inventory2/internal/domains/raw_events"
|
||||
"ruben/inventory2/internal/site"
|
||||
@@ -49,7 +50,12 @@ func runApp(ctx context.Context) error {
|
||||
|
||||
// start http server
|
||||
|
||||
srvErrCh := runServer(ctx, connPool)
|
||||
auth, err := authentication.New(ctx, connPool)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to construct authenticator: %w", err)
|
||||
}
|
||||
|
||||
srvErrCh := runServer(ctx, connPool, auth)
|
||||
|
||||
// wait for interrupt signal or unrecoverable failure, then shutdown
|
||||
|
||||
@@ -85,10 +91,10 @@ func runApp(ctx context.Context) error {
|
||||
return errors.Join(errs...)
|
||||
}
|
||||
|
||||
func runServer(ctx context.Context, connPool *pgxpool.Pool) <-chan error {
|
||||
func runServer(ctx context.Context, connPool *pgxpool.Pool, auth *authentication.Authenticator) <-chan error {
|
||||
srv := &http.Server{
|
||||
Addr: ":8082", // local
|
||||
Handler: buildHTTPHandler(connPool),
|
||||
Handler: buildHTTPHandler(connPool, auth),
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
@@ -139,7 +145,7 @@ func runServer(ctx context.Context, connPool *pgxpool.Pool) <-chan error {
|
||||
return errCh
|
||||
}
|
||||
|
||||
func buildHTTPHandler(connPool *pgxpool.Pool) http.Handler {
|
||||
func buildHTTPHandler(connPool *pgxpool.Pool, auth *authentication.Authenticator) http.Handler {
|
||||
eventsDB := raw_events.NewStore(connPool)
|
||||
etsy := etsy_platform.NewPlatform(
|
||||
func(acctID int64) string {
|
||||
@@ -158,8 +164,7 @@ func buildHTTPHandler(connPool *pgxpool.Pool) http.Handler {
|
||||
OAuthRedirectURIWithAcctIDParam: "/oauth/account/{acctID}/auth_code",
|
||||
},
|
||||
})))
|
||||
mux.Handle("/site/", http.StripPrefix("/site", site.NewSiteHandler("./internal/site", eventsDB, accts, etsy)))
|
||||
mux.Handle("/", http.RedirectHandler("/site", http.StatusPermanentRedirect))
|
||||
mux.Handle("/", site.NewServer("./internal/site", eventsDB, accts, etsy, auth))
|
||||
|
||||
return mux
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user