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

Method formatSessionResponse

rest/session_api.go:334–356  ·  view source on GitHub ↗

Formats session response similar to what is returned by CouchDB

(user auth.User, oneTimeSessionID string)

Source from the content-addressed store, hash-verified

332
333// Formats session response similar to what is returned by CouchDB
334func (h *handler) formatSessionResponse(user auth.User, oneTimeSessionID string) db.Body {
335
336 var name *string
337 allChannels := channels.TimedSet{}
338
339 if user != nil {
340 userName := user.Name()
341 if userName != "" {
342 name = &userName
343 }
344 allChannels = user.Channels()
345 }
346
347 // Return a JSON struct similar to what CouchDB returns:
348 userCtx := db.Body{"name": name, "channels": allChannels}
349 handlers := []string{"default", "cookie"}
350 response := db.Body{"ok": true, "userCtx": userCtx, "authentication_handlers": handlers}
351 if oneTimeSessionID != "" {
352 response["one_time_session_id"] = oneTimeSessionID
353 }
354 return response
355
356}
357
358// checkLoginCORS validates the auth.CORSConfig.LoginOrigin section of CORS for requests.
359// Note: Validation of the general Origin header against auth.CORSConfig.Origin happens separately in validateAndWriteHeaders.

Callers 3

handleSessionPOSTMethod · 0.95

Calls 2

NameMethod · 0.65
ChannelsMethod · 0.65

Tested by

no test coverage detected