sendRawUserInfoRequest sends the specified user info request and return its raw response body.
(req *http.Request, token *oauth2.Token)
| 174 | |
| 175 | // sendRawUserInfoRequest sends the specified user info request and return its raw response body. |
| 176 | func (p *BaseProvider) sendRawUserInfoRequest(req *http.Request, token *oauth2.Token) ([]byte, error) { |
| 177 | client := p.Client(token) |
| 178 | |
| 179 | res, err := client.Do(req) |
| 180 | if err != nil { |
| 181 | return nil, err |
| 182 | } |
| 183 | defer res.Body.Close() |
| 184 | |
| 185 | result, err := io.ReadAll(res.Body) |
| 186 | if err != nil { |
| 187 | return nil, err |
| 188 | } |
| 189 | |
| 190 | // http.Client.Get doesn't treat non 2xx responses as error |
| 191 | if res.StatusCode >= 400 { |
| 192 | return nil, fmt.Errorf( |
| 193 | "failed to fetch OAuth2 user profile via %s (%d):\n%s", |
| 194 | p.userInfoURL, |
| 195 | res.StatusCode, |
| 196 | string(result), |
| 197 | ) |
| 198 | } |
| 199 | |
| 200 | return result, nil |
| 201 | } |
| 202 | |
| 203 | // oauth2Config constructs a oauth2.Config instance based on the provider settings. |
| 204 | func (p *BaseProvider) oauth2Config() *oauth2.Config { |
no test coverage detected