(data url.Values)
| 954 | var errHTTPToken = errors.New("bad request; token not returned") |
| 955 | |
| 956 | func (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. |
no test coverage detected