MCPcopy Create free account
hub / github.com/daodst/chat / ExtractAccessToken

Function ExtractAccessToken

clientapi/auth/auth.go:104–125  ·  view source on GitHub ↗

ExtractAccessToken from a request, or return an error detailing what went wrong. The error message MUST be human-readable and comprehensible to the client.

(req *http.Request)

Source from the content-addressed store, hash-verified

102// ExtractAccessToken from a request, or return an error detailing what went wrong. The
103// error message MUST be human-readable and comprehensible to the client.
104func ExtractAccessToken(req *http.Request) (string, error) {
105 // cf https://github.com/matrix-org/synapse/blob/v0.19.2/synapse/api/auth.py#L631
106 authBearer := req.Header.Get("Authorization")
107 queryToken := req.URL.Query().Get("access_token")
108 if authBearer != "" && queryToken != "" {
109 return "", fmt.Errorf("mixing Authorization headers and access_token query parameters")
110 }
111
112 if queryToken != "" {
113 return queryToken, nil
114 }
115
116 if authBearer != "" {
117 parts := strings.SplitN(authBearer, " ", 2)
118 if len(parts) != 2 || parts[0] != "Bearer" {
119 return "", fmt.Errorf("invalid Authorization header")
120 }
121 return parts[1], nil
122 }
123
124 return "", fmt.Errorf("missing access token")
125}

Callers 1

VerifyUserFromRequestFunction · 0.85

Calls 1

GetMethod · 0.65

Tested by

no test coverage detected