Devendra174's picture
Upload folder using huggingface_hub
1e92f2d verified
raw
history blame contribute delete
758 Bytes
package auth
import (
"net/http"
"strings"
)
// GetToken will return the auth token associated with a request.
//
// Supported options (in priority order):
// - `token` (field or query)
// - Authorization: Bearer header
func GetToken(req *http.Request) string {
tok := req.FormValue("token")
if tok != "" {
return tok
}
// compat
tok = req.FormValue("integrationKey")
if tok != "" {
return tok
}
// compat
tok = req.FormValue("integration_key")
if tok != "" {
return tok
}
// compat
tok = req.FormValue("key")
if tok != "" {
return tok
}
tok = strings.TrimPrefix(req.Header.Get("Authorization"), "Bearer ")
if tok != "" {
return tok
}
// compat
_, tok, _ = req.BasicAuth()
if tok != "" {
return tok
}
return ""
}