update api.go, config.yml, handler.go, middleware.go, repository.go
This commit is contained in:
1 parent
43505548f7
commit
f99ac8ffb4
5 files changed
+415
No files matched your search
@@ -0,0 +1,30 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"esforum/pkg/util"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
const (
|
||||
authorizationHeader = "Authorization"
|
||||
userCtx = "UserInfo"
|
||||
userHeader = "UserHeader"
|
||||
)
|
||||
|
||||
func (h *Handler) userIdentity(c *gin.Context) {
|
||||
header := c.GetHeader(authorizationHeader)
|
||||
if header == "" {
|
||||
util.NewErrorResponse(c, http.StatusUnauthorized, "empty auth header")
|
||||
return
|
||||
}
|
||||
|
||||
user, err := h.services.Authorization.Authorize(header)
|
||||
if err != nil {
|
||||
util.NewErrorResponse(c, http.StatusUnauthorized, err.Error())
|
||||
}
|
||||
|
||||
c.Set(userCtx, user.Id)
|
||||
c.Set(userHeader, header)
|
||||
}
|
||||
Reference in new issue
Block a user