change authorization methods request priorities.

This commit is contained in:
Miroslav Šedivý 2021-03-15 13:01:35 +01:00
parent 900ae006b8
commit edfe9adde0

View File

@ -27,12 +27,6 @@ func (manager *SessionManagerCtx) Authenticate(r *http.Request) (types.Session,
}
func getToken(r *http.Request) (string, bool) {
// get from Cookie
cookie, err := r.Cookie("NEKO_SESSION")
if err == nil {
return cookie.Value, true
}
// get from Header
reqToken := r.Header.Get("Authorization")
splitToken := strings.Split(reqToken, "Bearer ")
@ -40,6 +34,12 @@ func getToken(r *http.Request) (string, bool) {
return strings.TrimSpace(splitToken[1]), true
}
// get from Cookie
cookie, err := r.Cookie("NEKO_SESSION")
if err == nil {
return cookie.Value, true
}
// get from URL
token := r.URL.Query().Get("token")
if token != "" {