MCPcopy Index your code
hub / github.com/dnote/dnote / GetCredential

Function GetCredential

pkg/server/middleware/helpers.go:149–164  ·  view source on GitHub ↗

GetCredential extracts a session key from the request from the request header. Concretely, it first looks at the 'Cookie' and then the 'Authorization' header. If no credential is found, it returns an empty string.

(r *http.Request)

Source from the content-addressed store, hash-verified

147// it first looks at the 'Cookie' and then the 'Authorization' header. If no credential is found,
148// it returns an empty string.
149func GetCredential(r *http.Request) (string, error) {
150 ret, err := getSessionKeyFromCookie(r)
151 if err != nil {
152 return "", errors.Wrap(err, "getting session key from cookie")
153 }
154 if ret != "" {
155 return ret, nil
156 }
157
158 ret, err = getSessionKeyFromAuth(r)
159 if err != nil {
160 return "", errors.Wrap(err, "getting session key from Authorization header")
161 }
162
163 return ret, nil
164}

Callers 2

TestGetCredentialFunction · 0.70
AuthWithSessionFunction · 0.70

Calls 2

getSessionKeyFromCookieFunction · 0.70
getSessionKeyFromAuthFunction · 0.70

Tested by 1

TestGetCredentialFunction · 0.56