MCPcopy
hub / github.com/writefreely/writefreely / apiAuth

Function apiAuth

handle.go:251–263  ·  view source on GitHub ↗
(app *App, r *http.Request)

Source from the content-addressed store, hash-verified

249}
250
251func apiAuth(app *App, r *http.Request) (*User, error) {
252 // Authorize user from Authorization header
253 t := r.Header.Get("Authorization")
254 if t == "" {
255 return nil, ErrNoAccessToken
256 }
257 u := &User{ID: app.db.GetUserID(t)}
258 if u.ID == -1 {
259 return nil, ErrBadAccessToken
260 }
261
262 return u, nil
263}
264
265// optionalAPIAuth is used for endpoints that accept authenticated requests via
266// Authorization header or cookie, unlike apiAuth. It returns a different err

Callers 1

UserWebAPIMethod · 0.85

Calls 1

GetUserIDMethod · 0.65

Tested by

no test coverage detected