2021-12-21 13:16:54 +00:00
|
|
|
package middlewares
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"log"
|
|
|
|
|
|
|
|
"github.com/authorizerdev/authorizer/server/constants"
|
|
|
|
"github.com/gin-contrib/location"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
)
|
|
|
|
|
|
|
|
func GinContextToContextMiddleware() gin.HandlerFunc {
|
|
|
|
return func(c *gin.Context) {
|
2021-12-31 08:22:10 +00:00
|
|
|
if constants.EnvData.AUTHORIZER_URL == "" {
|
2021-12-21 13:16:54 +00:00
|
|
|
url := location.Get(c)
|
2021-12-31 08:22:10 +00:00
|
|
|
constants.EnvData.AUTHORIZER_URL = url.Scheme + "://" + c.Request.Host
|
|
|
|
log.Println("authorizer url:", constants.EnvData.AUTHORIZER_URL)
|
2021-12-21 13:16:54 +00:00
|
|
|
}
|
|
|
|
ctx := context.WithValue(c.Request.Context(), "GinContextKey", c)
|
|
|
|
c.Request = c.Request.WithContext(ctx)
|
|
|
|
c.Next()
|
|
|
|
}
|
|
|
|
}
|