MCPcopy Index your code
hub / github.com/smallstep/cli / deviceAuthzTokenPoll

Method deviceAuthzTokenPoll

command/oauth/cmd.go:956–979  ·  view source on GitHub ↗
(data url.Values)

Source from the content-addressed store, hash-verified

954var errHTTPToken = errors.New("bad request; token not returned")
955
956func (o *oauth) deviceAuthzTokenPoll(data url.Values) (*token, error) {
957 resp, err := postForm(o.tokenEndpoint, data)
958 if err != nil {
959 return nil, errors.Wrap(err, "error doing POST to /token endpoint")
960 }
961 defer resp.Body.Close()
962 b, err := io.ReadAll(resp.Body)
963 if err != nil {
964 return nil, errors.Wrap(err, "error reading HTTP response body from /token endpoint")
965 }
966
967 switch {
968 case resp.StatusCode == http.StatusOK:
969 tok := token{}
970 if err := json.NewDecoder(bytes.NewReader(b)).Decode(&tok); err != nil {
971 return nil, errors.Wrap(err, "error parsing JSON /token response")
972 }
973 return &tok, nil
974 case resp.StatusCode >= http.StatusBadRequest && resp.StatusCode < http.StatusInternalServerError:
975 return nil, errHTTPToken
976 default:
977 return nil, errors.New(string(b))
978 }
979}
980
981// DoTwoLeggedAuthorization performs two-legged OAuth using the jwt-bearer
982// grant type.

Callers 1

DoDeviceAuthorizationMethod · 0.95

Calls 2

postFormFunction · 0.85
CloseMethod · 0.45

Tested by

no test coverage detected