Exchange exchanges the authorization code for refresh and access tokens.
(tokenEndpoint, code string)
| 1232 | |
| 1233 | // Exchange exchanges the authorization code for refresh and access tokens. |
| 1234 | func (o *oauth) Exchange(tokenEndpoint, code string) (*token, error) { |
| 1235 | data := url.Values{} |
| 1236 | data.Set("code", code) |
| 1237 | data.Set("client_id", o.clientID) |
| 1238 | data.Set("client_secret", o.clientSecret) |
| 1239 | data.Set("redirect_uri", o.redirectURI) |
| 1240 | data.Set("grant_type", "authorization_code") |
| 1241 | data.Set("code_verifier", o.codeChallenge) |
| 1242 | |
| 1243 | resp, err := postForm(tokenEndpoint, data) |
| 1244 | if err != nil { |
| 1245 | return nil, errors.WithStack(err) |
| 1246 | } |
| 1247 | defer resp.Body.Close() |
| 1248 | |
| 1249 | var tok token |
| 1250 | if err := json.NewDecoder(resp.Body).Decode(&tok); err != nil { |
| 1251 | return nil, errors.WithStack(err) |
| 1252 | } |
| 1253 | |
| 1254 | return &tok, nil |
| 1255 | } |
| 1256 | |
| 1257 | func (o *oauth) success(w http.ResponseWriter) { |
| 1258 | w.WriteHeader(http.StatusOK) |
no test coverage detected