getSessionKeyFromAuth reads and returns a session key from the Authorization header
(r *http.Request)
| 117 | |
| 118 | // getSessionKeyFromAuth reads and returns a session key from the Authorization header |
| 119 | func getSessionKeyFromAuth(r *http.Request) (string, error) { |
| 120 | h := r.Header.Get("Authorization") |
| 121 | if h == "" { |
| 122 | return "", nil |
| 123 | } |
| 124 | |
| 125 | payload, err := parseAuthHeader(h) |
| 126 | if err != nil { |
| 127 | return "", errors.Wrap(err, "parsing the authorization header") |
| 128 | } |
| 129 | if payload.scheme != "Bearer" { |
| 130 | return "", errors.New("unsupported scheme") |
| 131 | } |
| 132 | |
| 133 | return payload.credential, nil |
| 134 | } |
| 135 | |
| 136 | func parseAuthHeader(h string) (authHeader, error) { |
| 137 | parts := strings.Split(h, " ") |
no test coverage detected