MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / getWebsocketToken

Method getWebsocketToken

rest/handler.go:1070–1089  ·  view source on GitHub ↗

verifyWebsocketToken checks for a valid websocket token in the request headers. If present, invalidate the token so it can't be reused. Returns a nil error if there is no token on the header but no user object. If the header is found,

()

Source from the content-addressed store, hash-verified

1068//
1069// Returns a nil error if there is no token on the header but no user object. If the header is found,
1070func (h *handler) getWebsocketToken() string {
1071 // go blip expects only one Sec-WebSocket-Protocol header, with comma separated values
1072 protocolHeaders := h.rq.Header.Get(secWebSocketProtocolHeader)
1073 var outputHeaders []string
1074 var sessionID string
1075 for header := range strings.SplitSeq(protocolHeaders, ",") {
1076 trimmedHeader := strings.TrimSpace(header)
1077 if !strings.HasPrefix(trimmedHeader, blipSessionIDPrefix) {
1078 outputHeaders = append(outputHeaders, header)
1079 continue
1080 }
1081 sessionID = strings.TrimPrefix(trimmedHeader, blipSessionIDPrefix)
1082 }
1083 if sessionID == "" {
1084 return ""
1085 }
1086 // Remove the websocket protocol so it doesn't get logged in BlipWebsocketServer.handshake
1087 h.rq.Header.Set(secWebSocketProtocolHeader, strings.Join(outputHeaders, ","))
1088 return sessionID
1089}
1090
1091func checkJWTIssuerStillValid(ctx context.Context, dbCtx *db.DatabaseContext, user auth.User) *auth.PrincipalConfig {
1092 issuer := user.JWTIssuer()

Callers 1

setUserForPublicAuthMethod · 0.95

Calls 2

GetMethod · 0.45
SetMethod · 0.45

Tested by

no test coverage detected