Get API key from an HTTP request.
(req *http.Request)
| 299 | |
| 300 | // Get API key from an HTTP request. |
| 301 | func getAPIKey(req *http.Request) string { |
| 302 | // Check header. |
| 303 | apikey := req.Header.Get("X-Tinode-APIKey") |
| 304 | if apikey != "" { |
| 305 | return apikey |
| 306 | } |
| 307 | |
| 308 | // Check URL query parameters. |
| 309 | apikey = req.URL.Query().Get("apikey") |
| 310 | if apikey != "" { |
| 311 | return apikey |
| 312 | } |
| 313 | |
| 314 | // Check form values. |
| 315 | apikey = req.FormValue("apikey") |
| 316 | if apikey != "" { |
| 317 | return apikey |
| 318 | } |
| 319 | |
| 320 | // Check cookies. |
| 321 | if c, err := req.Cookie("apikey"); err == nil { |
| 322 | apikey = c.Value |
| 323 | } |
| 324 | |
| 325 | return apikey |
| 326 | } |
| 327 | |
| 328 | // Extracts authorization credentials from an HTTP request. |
| 329 | // Returns authentication method and secret. |
no test coverage detected
searching dependent graphs…