(ctx context.Context, code string)
| 69 | } |
| 70 | |
| 71 | func (c genericOauthClient) exchangeOauthCode(ctx context.Context, code string) (*TokenResponse, error) { |
| 72 | form := url.Values{} |
| 73 | form.Add("client_id", c.ClientID) |
| 74 | form.Add("client_secret", c.ClientSecret) |
| 75 | form.Add("grant_type", "authorization_code") |
| 76 | form.Add("redirect_uri", c.CallbackLocation) |
| 77 | form.Add("scope", c.Scope) |
| 78 | form.Add("code", code) |
| 79 | req, err := http.NewRequest("POST", c.ExchangeLocation, strings.NewReader(form.Encode())) |
| 80 | if err != nil { |
| 81 | return nil, err |
| 82 | } |
| 83 | req.WithContext(ctx) |
| 84 | req.Header.Set("User-Agent", ServerUserAgent("")) |
| 85 | req.Header.Set("Accept", "application/json") |
| 86 | req.Header.Set("Content-Type", "application/x-www-form-urlencoded") |
| 87 | req.SetBasicAuth(c.ClientID, c.ClientSecret) |
| 88 | |
| 89 | resp, err := c.HttpClient.Do(req) |
| 90 | if err != nil { |
| 91 | return nil, err |
| 92 | } |
| 93 | if resp.StatusCode != http.StatusOK { |
| 94 | return nil, errors.New("unable to exchange code for access token") |
| 95 | } |
| 96 | |
| 97 | var tokenResponse TokenResponse |
| 98 | if err := limitedJsonUnmarshal(resp.Body, tokenRequestMaxLen, &tokenResponse); err != nil { |
| 99 | return nil, err |
| 100 | } |
| 101 | if tokenResponse.Error != "" { |
| 102 | return nil, errors.New(tokenResponse.Error) |
| 103 | } |
| 104 | return &tokenResponse, nil |
| 105 | } |
| 106 | |
| 107 | func (c genericOauthClient) inspectOauthAccessToken(ctx context.Context, accessToken string) (*InspectResponse, error) { |
| 108 | req, err := http.NewRequest("GET", c.InspectLocation, nil) |
nothing calls this directly
no test coverage detected