| 581 | } |
| 582 | |
| 583 | func (c *Config) RevokeToken(ctx context.Context, link database.ExternalAuthLink) (bool, error) { |
| 584 | if c.RevokeURL == "" { |
| 585 | return false, nil |
| 586 | } |
| 587 | |
| 588 | reqCtx, cancel := context.WithTimeout(ctx, c.RevokeTimeout) |
| 589 | defer cancel() |
| 590 | req, err := c.TokenRevocationRequest(reqCtx, link) |
| 591 | if err != nil { |
| 592 | return false, err |
| 593 | } |
| 594 | |
| 595 | res, err := c.InstrumentedOAuth2Config.Do(ctx, promoauth.SourceRevoke, req) |
| 596 | if err != nil { |
| 597 | return false, err |
| 598 | } |
| 599 | defer res.Body.Close() |
| 600 | body, err := io.ReadAll(res.Body) |
| 601 | if err != nil { |
| 602 | return false, err |
| 603 | } |
| 604 | |
| 605 | if c.TokenRevocationResponseOk(res) { |
| 606 | return true, nil |
| 607 | } |
| 608 | return false, xerrors.Errorf("failed to revoke token: %d %s", res.StatusCode, string(body)) |
| 609 | } |
| 610 | |
| 611 | func (c *Config) TokenRevocationRequest(ctx context.Context, link database.ExternalAuthLink) (*http.Request, error) { |
| 612 | if c.Type == codersdk.EnhancedExternalAuthProviderGitHub.String() { |