MCPcopy
hub / github.com/tinode/chat / authFileRequest

Function authFileRequest

server/hdl_files.go:604–635  ·  view source on GitHub ↗

Authenticate non-websocket HTTP request

(authMethod, secret, sid, remoteAddr string)

Source from the content-addressed store, hash-verified

602
603// Authenticate non-websocket HTTP request
604func authFileRequest(authMethod, secret, sid, remoteAddr string) (types.Uid, []byte, error) {
605 var uid types.Uid
606 if authMethod != "" {
607 decodedSecret := make([]byte, base64.StdEncoding.DecodedLen(len(secret)))
608 n, err := base64.StdEncoding.Decode(decodedSecret, []byte(secret))
609 if err != nil {
610 logs.Info.Println("media: invalid auth secret", authMethod, "'"+secret+"'")
611 return uid, nil, types.ErrMalformed
612 }
613
614 if authhdl := store.Store.GetLogicalAuthHandler(authMethod); authhdl != nil {
615 rec, challenge, err := authhdl.Authenticate(decodedSecret[:n], remoteAddr)
616 if err != nil {
617 return uid, nil, err
618 }
619 if challenge != nil {
620 return uid, challenge, nil
621 }
622 uid = rec.Uid
623 } else {
624 logs.Info.Println("media: unknown auth method", authMethod)
625 return uid, nil, types.ErrMalformed
626 }
627 } else {
628 // Find the session, make sure it's appropriately authenticated.
629 sess := globals.sessionStore.Get(sid)
630 if sess != nil {
631 uid = sess.uid
632 }
633 }
634 return uid, nil, nil
635}

Callers 4

largeFileServeHTTPFunction · 0.85
largeFileReceiveHTTPFunction · 0.85
LargeFileServeMethod · 0.85
LargeFileReceiveMethod · 0.85

Calls 4

PrintlnMethod · 0.80
GetLogicalAuthHandlerMethod · 0.65
AuthenticateMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…