MCPcopy Index your code
hub / github.com/docker/cli / RevokeToken

Method RevokeToken

internal/oauth/api/api.go:192–212  ·  view source on GitHub ↗

RevokeToken revokes a refresh token with the tenant so that it can no longer be used to get new tokens.

(ctx context.Context, refreshToken string)

Source from the content-addressed store, hash-verified

190// RevokeToken revokes a refresh token with the tenant so that it can no longer
191// be used to get new tokens.
192func (a API) RevokeToken(ctx context.Context, refreshToken string) error {
193 data := url.Values{
194 "client_id": {a.ClientID},
195 "token": {refreshToken},
196 }
197
198 revokeURL := a.TenantURL + "/oauth/revoke"
199 resp, err := postForm(ctx, revokeURL, strings.NewReader(data.Encode()))
200 if err != nil {
201 return err
202 }
203 defer func() {
204 _ = resp.Body.Close()
205 }()
206
207 if resp.StatusCode != http.StatusOK {
208 return tryDecodeOAuthError(resp)
209 }
210
211 return nil
212}
213
214func postForm(ctx context.Context, reqURL string, data io.Reader) (*http.Response, error) {
215 req, err := http.NewRequestWithContext(ctx, http.MethodPost, reqURL, data)

Callers 1

TestRevokeFunction · 0.95

Calls 3

postFormFunction · 0.85
tryDecodeOAuthErrorFunction · 0.85
CloseMethod · 0.45

Tested by 1

TestRevokeFunction · 0.76