(tokenStore types.TokenStore, getToken func(*gin.Context) string)
| 122 | } |
| 123 | |
| 124 | func tokenAuth(tokenStore types.TokenStore, getToken func(*gin.Context) string) gin.HandlerFunc { |
| 125 | return func(c *gin.Context) { |
| 126 | if IsAuthenticated(c) { |
| 127 | c.Next() |
| 128 | return |
| 129 | } |
| 130 | |
| 131 | tokenKey := getToken(c) |
| 132 | if tokenKey == "" { |
| 133 | // no token: browse as an anonymous session |
| 134 | SetPrincipal(c, types.Principal{}) |
| 135 | c.Next() |
| 136 | return |
| 137 | } |
| 138 | token, e := tokenStore.Validate(tokenKey) |
| 139 | if e != nil { |
| 140 | _ = c.Error(e) |
| 141 | c.Abort() |
| 142 | return |
| 143 | } |
| 144 | |
| 145 | SetToken(c, token.Token) |
| 146 | SetPrincipal(c, token.Value) |
| 147 | |
| 148 | c.Next() |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | func BasicAuth(userAuth *auth.UserAuth, realm string, allowAnonymous bool) gin.HandlerFunc { |
| 153 | return func(c *gin.Context) { |
no test coverage detected