mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-03-23 01:54:28 -05:00
Return the correct error
This commit is contained in:
parent
c9c602129d
commit
62a9375f56
|
@ -4,6 +4,8 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
||||||
)
|
)
|
||||||
|
|
||||||
// VerifyAccessToken verifies that an access token was supplied in the given HTTP request
|
// VerifyAccessToken verifies that an access token was supplied in the given HTTP request
|
||||||
|
@ -12,15 +14,17 @@ import (
|
||||||
func VerifyAccessToken(req *http.Request) (userID string, err error) {
|
func VerifyAccessToken(req *http.Request) (userID string, err error) {
|
||||||
_, tokenErr := extractAccessToken(req)
|
_, tokenErr := extractAccessToken(req)
|
||||||
if tokenErr != nil {
|
if tokenErr != nil {
|
||||||
// err = MatrixError(MatrixError.M_MISSING_TOKEN, tokenErr.Error())
|
err = jsonerror.MissingToken(tokenErr.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// TODO: Do something with the token
|
// TODO: Check the token against the database
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// extractAccessToken from a request, or return an error detailing what went wrong.
|
// extractAccessToken from a request, or return an error detailing what went wrong. The
|
||||||
|
// error message MUST be human-readable and comprehensible to the client.
|
||||||
func extractAccessToken(req *http.Request) (string, error) {
|
func extractAccessToken(req *http.Request) (string, error) {
|
||||||
|
// cf https://github.com/matrix-org/synapse/blob/v0.19.2/synapse/api/auth.py#L631
|
||||||
authBearer := req.Header.Get("Authorization")
|
authBearer := req.Header.Get("Authorization")
|
||||||
queryToken := req.URL.Query().Get("access_token")
|
queryToken := req.URL.Query().Get("access_token")
|
||||||
if authBearer != "" && queryToken != "" {
|
if authBearer != "" && queryToken != "" {
|
||||||
|
|
Loading…
Reference in a new issue