Helper Functions getClient looks up and authenticates the basic auth using the given storage. Sets an error on the response if auth fails or a server error occurs.
(auth *BasicAuth, storage Storage, w *Response)
| 527 | // getClient looks up and authenticates the basic auth using the given |
| 528 | // storage. Sets an error on the response if auth fails or a server error occurs. |
| 529 | func (s Server) getClient(auth *BasicAuth, storage Storage, w *Response) Client { |
| 530 | client, err := storage.GetClient(auth.Username) |
| 531 | if err == ErrNotFound { |
| 532 | s.setErrorAndLog(w, E_UNAUTHORIZED_CLIENT, nil, "get_client=%s", "not found") |
| 533 | return nil |
| 534 | } |
| 535 | if err != nil { |
| 536 | s.setErrorAndLog(w, E_SERVER_ERROR, err, "get_client=%s", "error finding client") |
| 537 | return nil |
| 538 | } |
| 539 | if client == nil { |
| 540 | s.setErrorAndLog(w, E_UNAUTHORIZED_CLIENT, nil, "get_client=%s", "client is nil") |
| 541 | return nil |
| 542 | } |
| 543 | |
| 544 | if !CheckClientSecret(client, auth.Password) { |
| 545 | s.setErrorAndLog(w, E_UNAUTHORIZED_CLIENT, nil, "get_client=%s, client_id=%v", "client check failed", client.GetId()) |
| 546 | return nil |
| 547 | } |
| 548 | |
| 549 | if client.GetRedirectUri() == "" { |
| 550 | s.setErrorAndLog(w, E_UNAUTHORIZED_CLIENT, nil, "get_client=%s", "client redirect uri is empty") |
| 551 | return nil |
| 552 | } |
| 553 | return client |
| 554 | } |
| 555 | |
| 556 | // setErrorAndLog sets the response error and internal error (if non-nil) and logs them along with the provided debug format string and arguments. |
| 557 | func (s Server) setErrorAndLog(w *Response, responseError string, internalError error, debugFormat string, debugArgs ...interface{}) { |