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