24 lines
445 B
Go
24 lines
445 B
Go
package security
|
|
|
|
import (
|
|
"gitea-issue/proxy"
|
|
"github.com/gin-gonic/gin"
|
|
"net/http"
|
|
"strings"
|
|
)
|
|
|
|
func BearerToken() gin.HandlerFunc {
|
|
return func(c *gin.Context) {
|
|
token := c.GetHeader("Authorization")
|
|
if (token == "") {
|
|
c.AbortWithStatus(http.StatusBadRequest)
|
|
}
|
|
var tokenArr []string
|
|
tokenArr = strings.Split(token, " ")
|
|
if (tokenArr[1] != proxy.Bearer) {
|
|
c.AbortWithStatus(http.StatusUnauthorized)
|
|
}
|
|
c.Next()
|
|
}
|
|
}
|