Repalce facebook oauth with google
This commit is contained in:
@@ -25,8 +25,9 @@ import (
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
"github.com/urfave/negroni"
|
||||
oauth2FB "golang.org/x/oauth2/facebook"
|
||||
oauth2Github "golang.org/x/oauth2/github"
|
||||
oauth2Google "golang.org/x/oauth2/google"
|
||||
"google.golang.org/api/people/v1"
|
||||
)
|
||||
|
||||
var core pwd.PWDApi
|
||||
@@ -230,15 +231,15 @@ func initOauthProviders(p *types.Playground) {
|
||||
|
||||
config.Providers[p.Id]["github"] = conf
|
||||
}
|
||||
if p.FacebookClientID != "" && p.FacebookClientSecret != "" {
|
||||
if p.GoogleClientID != "" && p.GoogleClientSecret != "" {
|
||||
conf := &oauth2.Config{
|
||||
ClientID: p.FacebookClientID,
|
||||
ClientSecret: p.FacebookClientSecret,
|
||||
Scopes: []string{"email", "public_profile"},
|
||||
Endpoint: oauth2FB.Endpoint,
|
||||
ClientID: p.GoogleClientID,
|
||||
ClientSecret: p.GoogleClientSecret,
|
||||
Scopes: []string{people.UserinfoEmailScope, people.UserinfoProfileScope},
|
||||
Endpoint: oauth2Google.Endpoint,
|
||||
}
|
||||
|
||||
config.Providers[p.Id]["facebook"] = conf
|
||||
config.Providers[p.Id]["google"] = conf
|
||||
}
|
||||
if p.DockerClientID != "" && p.DockerClientSecret != "" {
|
||||
|
||||
|
||||
@@ -12,10 +12,10 @@ import (
|
||||
|
||||
"github.com/google/go-github/github"
|
||||
"github.com/gorilla/mux"
|
||||
fb "github.com/huandu/facebook"
|
||||
"github.com/play-with-docker/play-with-docker/config"
|
||||
"github.com/play-with-docker/play-with-docker/pwd/types"
|
||||
uuid "github.com/satori/go.uuid"
|
||||
"google.golang.org/api/people/v1"
|
||||
)
|
||||
|
||||
func LoggedInUser(rw http.ResponseWriter, req *http.Request) {
|
||||
@@ -141,27 +141,31 @@ func LoginCallback(rw http.ResponseWriter, req *http.Request) {
|
||||
user.Name = u.GetName()
|
||||
user.Avatar = u.GetAvatarURL()
|
||||
user.Email = u.GetEmail()
|
||||
} else if providerName == "facebook" {
|
||||
} else if providerName == "google" {
|
||||
ts := oauth2.StaticTokenSource(
|
||||
&oauth2.Token{AccessToken: tok.AccessToken},
|
||||
)
|
||||
tc := oauth2.NewClient(ctx, ts)
|
||||
session := &fb.Session{
|
||||
Version: "v2.10",
|
||||
HttpClient: tc,
|
||||
}
|
||||
p := fb.Params{}
|
||||
p["fields"] = "email,name,picture"
|
||||
res, err := session.Get("/me", p)
|
||||
|
||||
p, err := people.New(tc)
|
||||
if err != nil {
|
||||
log.Printf("Could not get user from facebook. Got: %v\n", err)
|
||||
log.Printf("Could not initialize people service . Got: %v\n", err)
|
||||
rw.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
user.ProviderUserId = res.Get("id").(string)
|
||||
user.Name = res.Get("name").(string)
|
||||
user.Avatar = res.Get("picture.data.url").(string)
|
||||
user.Email = res.Get("email").(string)
|
||||
|
||||
person, err := p.People.Get("people/me").PersonFields("emailAddresses,names").Do()
|
||||
|
||||
if err != nil {
|
||||
log.Printf("Could not initialize people service . Got: %v\n", err)
|
||||
rw.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
user.Email = person.EmailAddresses[0].Value
|
||||
user.Name = person.Names[0].GivenName
|
||||
user.ProviderUserId = person.ResourceName
|
||||
|
||||
} else if providerName == "docker" {
|
||||
ts := oauth2.StaticTokenSource(
|
||||
&oauth2.Token{AccessToken: tok.AccessToken},
|
||||
|
||||
Reference in New Issue
Block a user