ExternalAuth submits a URL or provider ID to fetch an access token for. nolint:revive
(ctx context.Context, req ExternalAuthRequest)
| 730 | // ExternalAuth submits a URL or provider ID to fetch an access token for. |
| 731 | // nolint:revive |
| 732 | func (c *Client) ExternalAuth(ctx context.Context, req ExternalAuthRequest) (ExternalAuthResponse, error) { |
| 733 | q := url.Values{ |
| 734 | "id": []string{req.ID}, |
| 735 | "match": []string{req.Match}, |
| 736 | } |
| 737 | if req.Listen { |
| 738 | q.Set("listen", "true") |
| 739 | } |
| 740 | if req.GitBranch != "" { |
| 741 | q.Set("git_branch", req.GitBranch) |
| 742 | } |
| 743 | if req.GitRemoteOrigin != "" { |
| 744 | q.Set("git_remote_origin", req.GitRemoteOrigin) |
| 745 | } |
| 746 | if req.ChatID != "" { |
| 747 | q.Set("chat_id", req.ChatID) |
| 748 | } |
| 749 | reqURL := "/api/v2/workspaceagents/me/external-auth?" + q.Encode() |
| 750 | res, err := c.SDK.Request(ctx, http.MethodGet, reqURL, nil) |
| 751 | if err != nil { |
| 752 | return ExternalAuthResponse{}, xerrors.Errorf("execute request: %w", err) |
| 753 | } |
| 754 | defer res.Body.Close() |
| 755 | |
| 756 | if res.StatusCode != http.StatusOK { |
| 757 | return ExternalAuthResponse{}, codersdk.ReadBodyAsError(res) |
| 758 | } |
| 759 | |
| 760 | var authResp ExternalAuthResponse |
| 761 | return authResp, json.NewDecoder(res.Body).Decode(&authResp) |
| 762 | } |
| 763 | |
| 764 | // LogsNotifyChannel returns the channel name responsible for notifying |
| 765 | // of new logs. |