Auth: Add request context to UserInfo calls (#70007)

* use context for UserInfo requests

* set timeouts for oauth http client

* Update pkg/login/social/common.go

Co-authored-by: Ieva <ieva.vasiljeva@grafana.com>

---------

Co-authored-by: Ieva <ieva.vasiljeva@grafana.com>
This commit is contained in:
Jo
2023-06-14 12:30:40 +00:00
committed by GitHub
parent 1445a7cc5c
commit 914daef0fd
19 changed files with 172 additions and 138 deletions

View File

@@ -1,6 +1,7 @@
package social
import (
"context"
"encoding/json"
"fmt"
"net/http"
@@ -16,14 +17,14 @@ type SocialGoogle struct {
apiUrl string
}
func (s *SocialGoogle) UserInfo(client *http.Client, token *oauth2.Token) (*BasicUserInfo, error) {
func (s *SocialGoogle) UserInfo(ctx context.Context, client *http.Client, token *oauth2.Token) (*BasicUserInfo, error) {
var data struct {
Id string `json:"id"`
Name string `json:"name"`
Email string `json:"email"`
}
response, err := s.httpGet(client, s.apiUrl)
response, err := s.httpGet(ctx, client, s.apiUrl)
if err != nil {
return nil, fmt.Errorf("Error getting user info: %s", err)
}