MCPcopy Create free account
hub / github.com/chain/Core / cachedTokenAuthnCheck

Method cachedTokenAuthnCheck

net/http/authn/authn.go:144–162  ·  view source on GitHub ↗
(ctx context.Context, user, pw string)

Source from the content-addressed store, hash-verified

142}
143
144func (a *API) cachedTokenAuthnCheck(ctx context.Context, user, pw string) error {
145 a.tokenMu.Lock()
146 res, ok := a.tokenMap[user+pw]
147 a.tokenMu.Unlock()
148 if !ok || time.Now().After(res.lastLookup.Add(tokenExpiry)) {
149 valid, err := a.tokenAuthnCheck(ctx, user, pw)
150 if err != nil {
151 return errors.Wrap(err)
152 }
153 res = tokenResult{valid: valid, lastLookup: time.Now()}
154 a.tokenMu.Lock()
155 a.tokenMap[user+pw] = res
156 a.tokenMu.Unlock()
157 }
158 if !res.valid {
159 return errors.New("invalid token")
160 }
161 return nil
162}

Callers 1

tokenAuthnMethod · 0.95

Calls 2

tokenAuthnCheckMethod · 0.95
AddMethod · 0.45

Tested by

no test coverage detected