ExchangeToken calls POST /api/auth/exchange.
(exchangeCode string)
| 252 | |
| 253 | // ExchangeToken calls POST /api/auth/exchange. |
| 254 | func (c *Client) ExchangeToken(exchangeCode string) (*ExchangeResponse, error) { |
| 255 | status, data, err := c.post(CLIBaseURL+"/api/auth/exchange", map[string]string{"exchange_code": exchangeCode}, false) |
| 256 | if err != nil { |
| 257 | return nil, fmt.Errorf("failed to exchange token: %w", err) |
| 258 | } |
| 259 | if status >= 300 { |
| 260 | return nil, fmt.Errorf("exchange failed (%d): %s", status, string(data)) |
| 261 | } |
| 262 | |
| 263 | var result ExchangeResponse |
| 264 | if err := json.Unmarshal(data, &result); err != nil { |
| 265 | return nil, fmt.Errorf("failed to parse exchange response: %w (body: %s)", err, string(data)) |
| 266 | } |
| 267 | return &result, nil |
| 268 | } |
no test coverage detected