SetupAuthentication sets up the HTTP request with authentication. If Token is set directly, use it. Otherwise exchange Username+Password for a token.
(req *http.Request)
| 47 | // SetupAuthentication sets up the HTTP request with authentication. |
| 48 | // If Token is set directly, use it. Otherwise exchange Username+Password for a token. |
| 49 | func (tc *TaigaConn) SetupAuthentication(req *http.Request) errors.Error { |
| 50 | if tc.Token != "" { |
| 51 | req.Header.Set("Authorization", "Bearer "+tc.Token) |
| 52 | return nil |
| 53 | } |
| 54 | if tc.Username != "" && tc.Password != "" { |
| 55 | token, err := tc.fetchToken() |
| 56 | if err != nil { |
| 57 | return err |
| 58 | } |
| 59 | req.Header.Set("Authorization", "Bearer "+token) |
| 60 | } |
| 61 | return nil |
| 62 | } |
| 63 | |
| 64 | // fetchToken exchanges username+password for a Taiga auth token via POST /auth |
| 65 | func (tc *TaigaConn) fetchToken() (string, errors.Error) { |
nothing calls this directly
no test coverage detected