mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-24 02:02:36 -04:00
Add prefix for auth
This commit is contained in:
parent
0e12ccd6bb
commit
257ef354c6
@ -1,6 +1,9 @@
|
||||
# vi: ft=sh
|
||||
# shellcheck disable=SC2034
|
||||
|
||||
# http route prefix (will listen to $KEIBI_PREFIX/users for example)
|
||||
KEIBI_PREFIX=""
|
||||
|
||||
# Database things
|
||||
POSTGRES_USER=kyoo
|
||||
POSTGRES_PASSWORD=password
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"crypto/rsa"
|
||||
"crypto/x509"
|
||||
"encoding/pem"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/golang-jwt/jwt/v5"
|
||||
@ -13,6 +14,7 @@ import (
|
||||
)
|
||||
|
||||
type Configuration struct {
|
||||
Prefix string
|
||||
JwtPrivateKey *rsa.PrivateKey
|
||||
JwtPublicKey *rsa.PublicKey
|
||||
Issuer string
|
||||
@ -52,6 +54,8 @@ func LoadConfiguration(db *dbc.Queries) (*Configuration, error) {
|
||||
}
|
||||
}
|
||||
|
||||
ret.Prefix = os.Getenv("KEIBI_PREFIX")
|
||||
|
||||
if ret.JwtPrivateKey == nil {
|
||||
ret.JwtPrivateKey, err = rsa.GenerateKey(rand.Reader, 4096)
|
||||
if err != nil {
|
||||
|
15
auth/main.go
15
auth/main.go
@ -163,29 +163,30 @@ func main() {
|
||||
}
|
||||
h.config = conf
|
||||
|
||||
r := e.Group("")
|
||||
g := e.Group(conf.Prefix)
|
||||
r := e.Group(conf.Prefix)
|
||||
r.Use(echojwt.WithConfig(echojwt.Config{
|
||||
SigningMethod: "RS256",
|
||||
SigningKey: h.config.JwtPublicKey,
|
||||
}))
|
||||
|
||||
e.GET("/health", h.CheckHealth)
|
||||
g.GET("/health", h.CheckHealth)
|
||||
|
||||
r.GET("/users", h.ListUsers)
|
||||
r.GET("/users/:id", h.GetUser)
|
||||
r.GET("/users/me", h.GetMe)
|
||||
r.DELETE("/users/:id", h.DeleteUser)
|
||||
r.DELETE("/users/me", h.DeleteSelf)
|
||||
e.POST("/users", h.Register)
|
||||
g.POST("/users", h.Register)
|
||||
|
||||
e.POST("/sessions", h.Login)
|
||||
g.POST("/sessions", h.Login)
|
||||
r.DELETE("/sessions", h.Logout)
|
||||
r.DELETE("/sessions/:id", h.Logout)
|
||||
|
||||
e.GET("/jwt", h.CreateJwt)
|
||||
e.GET("/info", h.GetInfo)
|
||||
g.GET("/jwt", h.CreateJwt)
|
||||
g.GET("/info", h.GetInfo)
|
||||
|
||||
e.GET("/swagger/*", echoSwagger.WrapHandler)
|
||||
g.GET("/swagger/*", echoSwagger.WrapHandler)
|
||||
|
||||
e.Logger.Fatal(e.Start(":4568"))
|
||||
}
|
||||
|
@ -69,12 +69,11 @@ services:
|
||||
condition: service_healthy
|
||||
env_file:
|
||||
- ./.env
|
||||
environment:
|
||||
- KEIBI_PREFIX=/auth
|
||||
labels:
|
||||
- "traefik.enable=true"
|
||||
- "traefik.http.routers.auth.rule=PathPrefix(`/auth/`)"
|
||||
- "traefik.http.routers.auth.middlewares=auth-sp"
|
||||
- "traefik.http.middlewares.auth-sp.stripprefix.prefixes=/auth"
|
||||
- "traefik.http.middlewares.auth-sp.stripprefix.forceSlash=false"
|
||||
profiles:
|
||||
- "v5"
|
||||
|
||||
|
@ -97,14 +97,13 @@ services:
|
||||
- "4568:4568"
|
||||
env_file:
|
||||
- ./.env
|
||||
environment:
|
||||
- KEIBI_PREFIX=/auth
|
||||
volumes:
|
||||
- ./auth:/app
|
||||
labels:
|
||||
- "traefik.enable=true"
|
||||
- "traefik.http.routers.auth.rule=PathPrefix(`/auth/`)"
|
||||
- "traefik.http.routers.auth.middlewares=auth-sp"
|
||||
- "traefik.http.middlewares.auth-sp.stripprefix.prefixes=/auth"
|
||||
- "traefik.http.middlewares.auth-sp.stripprefix.forceSlash=false"
|
||||
|
||||
scanner:
|
||||
build: ./scanner
|
||||
|
Loading…
x
Reference in New Issue
Block a user