deleteExternalAuthByID only deletes the link on the Coder side, does not revoke the token on the provider side. @Summary Delete external auth user link by ID @ID delete-external-auth-user-link-by-id @Security CoderSessionToken @Tags Git @Produce json @Param externalauth path string true "Git Provid
(w http.ResponseWriter, r *http.Request)
| 91 | // @Success 200 {object} codersdk.DeleteExternalAuthByIDResponse |
| 92 | // @Router /api/v2/external-auth/{externalauth} [delete] |
| 93 | func (api *API) deleteExternalAuthByID(w http.ResponseWriter, r *http.Request) { |
| 94 | config := httpmw.ExternalAuthParam(r) |
| 95 | apiKey := httpmw.APIKey(r) |
| 96 | ctx := r.Context() |
| 97 | |
| 98 | link, err := api.Database.GetExternalAuthLink(ctx, database.GetExternalAuthLinkParams{ |
| 99 | ProviderID: config.ID, |
| 100 | UserID: apiKey.UserID, |
| 101 | }) |
| 102 | if err != nil { |
| 103 | if errors.Is(err, sql.ErrNoRows) { |
| 104 | httpapi.ResourceNotFound(w) |
| 105 | return |
| 106 | } |
| 107 | httpapi.Write(ctx, w, http.StatusInternalServerError, codersdk.Response{ |
| 108 | Message: "Failed to get external auth link during deletion.", |
| 109 | Detail: err.Error(), |
| 110 | }) |
| 111 | return |
| 112 | } |
| 113 | |
| 114 | err = api.Database.DeleteExternalAuthLink(ctx, database.DeleteExternalAuthLinkParams{ |
| 115 | ProviderID: config.ID, |
| 116 | UserID: apiKey.UserID, |
| 117 | }) |
| 118 | if err != nil { |
| 119 | if errors.Is(err, sql.ErrNoRows) { |
| 120 | httpapi.ResourceNotFound(w) |
| 121 | return |
| 122 | } |
| 123 | httpapi.Write(ctx, w, http.StatusInternalServerError, codersdk.Response{ |
| 124 | Message: "Failed to delete external auth link.", |
| 125 | Detail: err.Error(), |
| 126 | }) |
| 127 | return |
| 128 | } |
| 129 | |
| 130 | ok, err := config.RevokeToken(ctx, link) |
| 131 | resp := codersdk.DeleteExternalAuthByIDResponse{TokenRevoked: ok} |
| 132 | |
| 133 | if err != nil { |
| 134 | resp.TokenRevocationError = err.Error() |
| 135 | } |
| 136 | httpapi.Write(ctx, w, http.StatusOK, resp) |
| 137 | } |
| 138 | |
| 139 | // @Summary Post external auth device by ID |
| 140 | // @ID post-external-auth-device-by-id |
nothing calls this directly
no test coverage detected