mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* break out go and js build commands * support oauth providers that return errors via redirect * remove extra call to get grafana.net org membership * removed GitHub specifics from generic OAuth * readded ability to name generic source * revert to a backward-compatible state, refactor and clean up * streamline oauth user creation, make generic oauth support more generic
51 lines
919 B
Go
51 lines
919 B
Go
package social
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
|
|
"github.com/grafana/grafana/pkg/models"
|
|
|
|
"golang.org/x/oauth2"
|
|
)
|
|
|
|
type SocialGoogle struct {
|
|
*oauth2.Config
|
|
allowedDomains []string
|
|
apiUrl string
|
|
allowSignup bool
|
|
}
|
|
|
|
func (s *SocialGoogle) Type() int {
|
|
return int(models.GOOGLE)
|
|
}
|
|
|
|
func (s *SocialGoogle) IsEmailAllowed(email string) bool {
|
|
return isEmailAllowed(email, s.allowedDomains)
|
|
}
|
|
|
|
func (s *SocialGoogle) IsSignupAllowed() bool {
|
|
return s.allowSignup
|
|
}
|
|
|
|
func (s *SocialGoogle) UserInfo(client *http.Client) (*BasicUserInfo, error) {
|
|
var data struct {
|
|
Name string `json:"name"`
|
|
Email string `json:"email"`
|
|
}
|
|
var err error
|
|
|
|
r, err := client.Get(s.apiUrl)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer r.Body.Close()
|
|
if err = json.NewDecoder(r.Body).Decode(&data); err != nil {
|
|
return nil, err
|
|
}
|
|
return &BasicUserInfo{
|
|
Name: data.Name,
|
|
Email: data.Email,
|
|
}, nil
|
|
}
|