mirror of
https://github.com/vcscsvcscs/GenerationsHeritage.git
synced 2025-08-14 14:59:07 +02:00
move auth to auth
This commit is contained in:
23
cmd/auth/auth.go
Normal file
23
cmd/auth/auth.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/zitadel/zitadel-go/v3/pkg/authorization/oauth"
|
||||
"github.com/zitadel/zitadel-go/v3/pkg/http/middleware"
|
||||
)
|
||||
|
||||
func auth(mw *middleware.Interceptor[*oauth.IntrospectionContext]) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
mw.RequireAuthorization()(http.HandlerFunc(authHTTPHandler(mw, c))).ServeHTTP(c.Writer, c.Request)
|
||||
}
|
||||
}
|
||||
|
||||
func authHTTPHandler(mw *middleware.Interceptor[*oauth.IntrospectionContext], c *gin.Context) func(w http.ResponseWriter, r *http.Request) {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
authCtx := mw.Context(r.Context())
|
||||
w.Header().Set("id", authCtx.UserID())
|
||||
c.JSON(http.StatusOK, gin.H{"id": authCtx.UserID(), "status": "ok"})
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user