MCPcopy Create free account
hub / github.com/devld/go-drive / tokenAuth

Function tokenAuth

server/utils.go:124–150  ·  view source on GitHub ↗
(tokenStore types.TokenStore, getToken func(*gin.Context) string)

Source from the content-addressed store, hash-verified

122}
123
124func 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
152func BasicAuth(userAuth *auth.UserAuth, realm string, allowAnonymous bool) gin.HandlerFunc {
153 return func(c *gin.Context) {

Callers 2

TokenAuthWithPostParamsFunction · 0.85
TokenAuthFunction · 0.85

Calls 7

IsAuthenticatedFunction · 0.85
getTokenFunction · 0.85
SetPrincipalFunction · 0.85
SetTokenFunction · 0.85
NextMethod · 0.80
ValidateMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected