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

Method exchangeOauthCode

oauth_generic.go:71–105  ·  view source on GitHub ↗
(ctx context.Context, code string)

Source from the content-addressed store, hash-verified

69}
70
71func (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
107func (c genericOauthClient) inspectOauthAccessToken(ctx context.Context, accessToken string) (*InspectResponse, error) {
108 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