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