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

Function getSessionKeyFromAuth

pkg/server/controllers/helpers.go:119–134  ·  view source on GitHub ↗

getSessionKeyFromAuth reads and returns a session key from the Authorization header

(r *http.Request)

Source from the content-addressed store, hash-verified

117
118// getSessionKeyFromAuth reads and returns a session key from the Authorization header
119func getSessionKeyFromAuth(r *http.Request) (string, error) {
120 h := r.Header.Get("Authorization")
121 if h == "" {
122 return "", nil
123 }
124
125 payload, err := parseAuthHeader(h)
126 if err != nil {
127 return "", errors.Wrap(err, "parsing the authorization header")
128 }
129 if payload.scheme != "Bearer" {
130 return "", errors.New("unsupported scheme")
131 }
132
133 return payload.credential, nil
134}
135
136func parseAuthHeader(h string) (authHeader, error) {
137 parts := strings.Split(h, " ")

Callers 1

GetCredentialFunction · 0.70

Calls 2

NewMethod · 0.80
parseAuthHeaderFunction · 0.70

Tested by

no test coverage detected