MCPcopy Create free account
hub / github.com/dnote/dnote / GetCredential

Function GetCredential

pkg/server/controllers/helpers.go:87–102  ·  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

85// it first looks at the 'Cookie' and then the 'Authorization' header. If no credential is found,
86// it returns an empty string.
87func GetCredential(r *http.Request) (string, error) {
88 ret, err := getSessionKeyFromCookie(r)
89 if err != nil {
90 return "", errors.Wrap(err, "getting session key from cookie")
91 }
92 if ret != "" {
93 return ret, nil
94 }
95
96 ret, err = getSessionKeyFromAuth(r)
97 if err != nil {
98 return "", errors.Wrap(err, "getting session key from Authorization header")
99 }
100
101 return ret, nil
102}
103
104// getSessionKeyFromCookie reads and returns a session key from the cookie sent by the
105// request. If no session key is found, it returns an empty string

Callers 1

logoutMethod · 0.70

Calls 2

getSessionKeyFromCookieFunction · 0.70
getSessionKeyFromAuthFunction · 0.70

Tested by

no test coverage detected