MCPcopy
hub / github.com/dgraph-io/dgraph / loginHandler

Function loginHandler

dgraph/cmd/alpha/http.go:137–180  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

135}
136
137func loginHandler(w http.ResponseWriter, r *http.Request) {
138 if commonHandler(w, r) {
139 return
140 }
141
142 // Pass in PoorMan's auth, IP information if present.
143 ctx := x.AttachRemoteIP(context.Background(), r)
144 ctx = x.AttachAuthToken(ctx, r)
145
146 body := readRequest(w, r)
147 loginReq := api.LoginRequest{}
148 if err := json.Unmarshal(body, &loginReq); err != nil {
149 x.SetStatusWithData(w, x.Error, err.Error())
150 return
151 }
152
153 resp, err := (&edgraph.Server{}).Login(ctx, &loginReq)
154 if err != nil {
155 x.SetStatusWithData(w, x.ErrorInvalidRequest, err.Error())
156 return
157 }
158
159 jwt := &api.Jwt{}
160 if err := proto.Unmarshal(resp.Json, jwt); err != nil {
161 x.SetStatusWithData(w, x.Error, err.Error())
162 return
163 }
164
165 response := map[string]interface{}{}
166 mp := make(map[string]string)
167 mp["accessJWT"] = jwt.AccessJwt
168 mp["refreshJWT"] = jwt.RefreshJwt
169 response["data"] = mp
170
171 js, err := json.Marshal(response)
172 if err != nil {
173 x.SetStatusWithData(w, x.Error, err.Error())
174 return
175 }
176
177 if _, err := x.WriteResponse(w, r, js); err != nil {
178 glog.Errorf("Error while writing response: %v", err)
179 }
180}
181
182// This method should just build the request and proxy it to the Query method of dgraph.Server.
183// It can then encode the response as appropriate before sending it back to the user.

Callers

nothing calls this directly

Calls 9

AttachRemoteIPFunction · 0.92
AttachAuthTokenFunction · 0.92
SetStatusWithDataFunction · 0.92
WriteResponseFunction · 0.92
commonHandlerFunction · 0.85
readRequestFunction · 0.85
LoginMethod · 0.80
ErrorMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected