Require admin to create users

This commit is contained in:
Torjus Håkestad 2023-10-22 22:18:38 +02:00
parent 9625b23033
commit a6be7e929a
3 changed files with 8 additions and 1 deletions

View File

@ -1,4 +1,5 @@
FROM golang:alpine as build FROM golang:alpine as build
RUN apk add --no-cache git
WORKDIR /app WORKDIR /app
COPY go.sum /app/go.sum COPY go.sum /app/go.sum
COPY go.mod /app/go.mod COPY go.mod /app/go.mod

2
go.mod
View File

@ -11,6 +11,8 @@ require (
) )
require ( require (
git.t-juice.club/microfilm/auth v0.1.1 // indirect
github.com/golang-jwt/jwt/v5 v5.0.0 // indirect
github.com/klauspost/compress v1.17.0 // indirect github.com/klauspost/compress v1.17.0 // indirect
github.com/nats-io/nkeys v0.4.5 // indirect github.com/nats-io/nkeys v0.4.5 // indirect
github.com/nats-io/nuid v1.0.1 // indirect github.com/nats-io/nuid v1.0.1 // indirect

View File

@ -8,6 +8,8 @@ import (
"net/http" "net/http"
"os" "os"
"git.t-juice.club/microfilm/auth"
"git.t-juice.club/microfilm/auth/authmw"
"git.t-juice.club/microfilm/users" "git.t-juice.club/microfilm/users"
"git.t-juice.club/microfilm/users/store" "git.t-juice.club/microfilm/users/store"
"github.com/go-chi/chi/v5" "github.com/go-chi/chi/v5"
@ -34,8 +36,10 @@ func NewServer(config *Config) (*UserServer, error) {
r.Use(srv.MiddlewareLogging) r.Use(srv.MiddlewareLogging)
verifyAdmin := authmw.VerifyToken("http://mf-auth:8082", []string{auth.RoleAdmin})
r.Get("/info", InfoHandler) r.Get("/info", InfoHandler)
r.Post("/", srv.CreateUserHandler) r.With(verifyAdmin).Post("/", srv.CreateUserHandler)
r.Post("/{identifier}/password", srv.SetPasswordHandler) r.Post("/{identifier}/password", srv.SetPasswordHandler)
r.Post("/{identifier}/verify", srv.VerifyHandler) r.Post("/{identifier}/verify", srv.VerifyHandler)