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