MCPcopy Create free account
hub / github.com/boringproxy/boringproxy / extractToken

Function extractToken

utils.go:29–55  ·  view source on GitHub ↗

Looks for auth token in query string, then headers, then cookies

(tokenName string, r *http.Request)

Source from the content-addressed store, hash-verified

27
28// Looks for auth token in query string, then headers, then cookies
29func extractToken(tokenName string, r *http.Request) (string, error) {
30
31 query := r.URL.Query()
32
33 queryToken := query.Get(tokenName)
34 if queryToken != "" {
35 return queryToken, nil
36 }
37
38 tokenHeader := r.Header.Get(tokenName)
39 if tokenHeader != "" {
40 return tokenHeader, nil
41 }
42
43 authHeader := r.Header.Get("Authorization")
44 if authHeader != "" {
45 tokenHeader := strings.Split(authHeader, " ")[1]
46 return tokenHeader, nil
47 }
48
49 tokenCookie, err := r.Cookie(tokenName)
50 if err == nil {
51 return tokenCookie.Value, nil
52 }
53
54 return "", errors.New("No token found")
55}
56
57const chars string = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
58

Callers 5

handleTunnelsMethod · 0.85
handleUsersMethod · 0.85
handleTokensMethod · 0.85
handleClientsMethod · 0.85
handleWebUiRequestMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected