UserWebAPI handles endpoints that accept a user authorized either via the web (cookies) or an Authorization header.
(f userHandlerFunc)
| 295 | |
| 296 | // UserWebAPI handles endpoints that accept a user authorized either via the web (cookies) or an Authorization header. |
| 297 | func (h *Handler) UserWebAPI(f userHandlerFunc) http.HandlerFunc { |
| 298 | return h.UserAll(false, f, func(app *App, r *http.Request) (*User, error) { |
| 299 | // Authorize user via cookies |
| 300 | u := getUserSession(app, r) |
| 301 | if u != nil { |
| 302 | return u, nil |
| 303 | } |
| 304 | |
| 305 | // Fall back to access token, since user isn't logged in via web |
| 306 | var err error |
| 307 | u, err = apiAuth(app, r) |
| 308 | if err != nil { |
| 309 | return nil, err |
| 310 | } |
| 311 | |
| 312 | return u, nil |
| 313 | }) |
| 314 | } |
| 315 | |
| 316 | func (h *Handler) UserAll(web bool, f userHandlerFunc, a authFunc) http.HandlerFunc { |
| 317 | return func(w http.ResponseWriter, r *http.Request) { |
no test coverage detected