MCPcopy
hub / github.com/smallstep/cli / Exchange

Method Exchange

command/oauth/cmd.go:1234–1255  ·  view source on GitHub ↗

Exchange exchanges the authorization code for refresh and access tokens.

(tokenEndpoint, code string)

Source from the content-addressed store, hash-verified

1232
1233// Exchange exchanges the authorization code for refresh and access tokens.
1234func (o *oauth) Exchange(tokenEndpoint, code string) (*token, error) {
1235 data := url.Values{}
1236 data.Set("code", code)
1237 data.Set("client_id", o.clientID)
1238 data.Set("client_secret", o.clientSecret)
1239 data.Set("redirect_uri", o.redirectURI)
1240 data.Set("grant_type", "authorization_code")
1241 data.Set("code_verifier", o.codeChallenge)
1242
1243 resp, err := postForm(tokenEndpoint, data)
1244 if err != nil {
1245 return nil, errors.WithStack(err)
1246 }
1247 defer resp.Body.Close()
1248
1249 var tok token
1250 if err := json.NewDecoder(resp.Body).Decode(&tok); err != nil {
1251 return nil, errors.WithStack(err)
1252 }
1253
1254 return &tok, nil
1255}
1256
1257func (o *oauth) success(w http.ResponseWriter) {
1258 w.WriteHeader(http.StatusOK)

Callers 2

DoManualAuthorizationMethod · 0.95
ServeHTTPMethod · 0.95

Calls 3

postFormFunction · 0.85
SetMethod · 0.80
CloseMethod · 0.45

Tested by

no test coverage detected