ExtractBearerToken extracts the token from a "Bearer " authorization header.
(auth string)
| 4 | |
| 5 | // ExtractBearerToken extracts the token from a "Bearer <token>" authorization header. |
| 6 | func ExtractBearerToken(auth string) string { |
| 7 | if auth := strings.TrimSpace(auth); auth != "" { |
| 8 | fields := strings.Fields(auth) |
| 9 | if len(fields) == 2 && strings.EqualFold(fields[0], "Bearer") { |
| 10 | return fields[1] |
| 11 | } |
| 12 | } |
| 13 | return "" |
| 14 | } |