@Summary Get external auth by ID @ID get-external-auth-by-id @Security CoderSessionToken @Tags Git @Produce json @Param externalauth path string true "Git Provider ID" format(string) @Success 200 {object} codersdk.ExternalAuth @Router /api/v2/external-auth/{externalauth} [get]
(w http.ResponseWriter, r *http.Request)
| 29 | // @Success 200 {object} codersdk.ExternalAuth |
| 30 | // @Router /api/v2/external-auth/{externalauth} [get] |
| 31 | func (api *API) externalAuthByID(w http.ResponseWriter, r *http.Request) { |
| 32 | config := httpmw.ExternalAuthParam(r) |
| 33 | apiKey := httpmw.APIKey(r) |
| 34 | ctx := r.Context() |
| 35 | |
| 36 | res := codersdk.ExternalAuth{ |
| 37 | Authenticated: false, |
| 38 | Device: config.DeviceAuth != nil, |
| 39 | AppInstallURL: config.AppInstallURL, |
| 40 | DisplayName: config.DisplayName, |
| 41 | AppInstallations: []codersdk.ExternalAuthAppInstallation{}, |
| 42 | } |
| 43 | |
| 44 | link, err := api.Database.GetExternalAuthLink(ctx, database.GetExternalAuthLinkParams{ |
| 45 | ProviderID: config.ID, |
| 46 | UserID: apiKey.UserID, |
| 47 | }) |
| 48 | if err != nil { |
| 49 | if !errors.Is(err, sql.ErrNoRows) { |
| 50 | httpapi.Write(ctx, w, http.StatusInternalServerError, codersdk.Response{ |
| 51 | Message: "Failed to get external auth link.", |
| 52 | Detail: err.Error(), |
| 53 | }) |
| 54 | return |
| 55 | } |
| 56 | |
| 57 | httpapi.Write(ctx, w, http.StatusOK, res) |
| 58 | return |
| 59 | } |
| 60 | var eg errgroup.Group |
| 61 | eg.Go(func() (err error) { |
| 62 | res.Authenticated, res.User, err = config.ValidateToken(ctx, link.OAuthToken()) |
| 63 | return err |
| 64 | }) |
| 65 | eg.Go(func() (err error) { |
| 66 | res.AppInstallations, res.AppInstallable, err = config.AppInstallations(ctx, link.OAuthAccessToken) |
| 67 | return err |
| 68 | }) |
| 69 | err = eg.Wait() |
| 70 | if err != nil { |
| 71 | httpapi.Write(ctx, w, http.StatusInternalServerError, codersdk.Response{ |
| 72 | Message: "Failed to validate token.", |
| 73 | Detail: err.Error(), |
| 74 | }) |
| 75 | return |
| 76 | } |
| 77 | if res.AppInstallations == nil { |
| 78 | res.AppInstallations = []codersdk.ExternalAuthAppInstallation{} |
| 79 | } |
| 80 | httpapi.Write(ctx, w, http.StatusOK, res) |
| 81 | } |
| 82 | |
| 83 | // deleteExternalAuthByID only deletes the link on the Coder side, does not revoke the token on the provider side. |
| 84 | // |
nothing calls this directly
no test coverage detected