MCPcopy Index your code
hub / github.com/writefreely/writefreely / exchangeOauthCode

Method exchangeOauthCode

oauth_gitlab.go:55–87  ·  view source on GitHub ↗
(ctx context.Context, code string)

Source from the content-addressed store, hash-verified

53}
54
55func (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
89func (c gitlabOauthClient) inspectOauthAccessToken(ctx context.Context, accessToken string) (*InspectResponse, error) {
90 req, err := http.NewRequest("GET", c.InspectLocation, nil)

Callers

nothing calls this directly

Calls 3

ServerUserAgentFunction · 0.85
limitedJsonUnmarshalFunction · 0.85
DoMethod · 0.65

Tested by

no test coverage detected