Open platform to collect and prioritize feedback
refactor: use new Google OAuth API (#453)
Guilherme Oenning879f846af7fa
diff --git a/app/pkg/jsonq/jsonq.go b/app/pkg/jsonq/jsonq.goindex 79f17174f..8d223cbaf 100644--- a/app/pkg/jsonq/jsonq.go+++ b/app/pkg/jsonq/jsonq.go@@ -96,13 +96,15 @@ func (q *Query) get(selector string) *json.RawMessage {} else {result = q.m[part]}-- var arr []*json.RawMessage- bytes, _ := result.MarshalJSON()- json.Unmarshal(bytes, &arr)- bytes, _ = arr[idx].MarshalJSON()- json.Unmarshal(bytes, ¤t)-+ if result != nil {+ var arr []*json.RawMessage+ bytes, _ := result.MarshalJSON()+ json.Unmarshal(bytes, &arr)+ if len(arr) > idx {+ bytes, _ = arr[idx].MarshalJSON()+ json.Unmarshal(bytes, ¤t)+ }+ }} else {if current != nil {diff --git a/app/pkg/jsonq/jsonq_test.go b/app/pkg/jsonq/jsonq_test.goindex 904362b41..502d095c6 100644--- a/app/pkg/jsonq/jsonq_test.go+++ b/app/pkg/jsonq/jsonq_test.go@@ -15,6 +15,13 @@ func TestGet(t *testing.T) {Expect(query.Int32("age")).Equals(23)}+func TestGetNull(t *testing.T) {+ RegisterT(t)++ query := jsonq.New(`{ "name": null }`)+ Expect(query.String("name")).Equals("")+}+func TestGet_NumberAsString(t *testing.T) {RegisterT(t)@@ -47,6 +54,15 @@ func TestGetValueFromArray(t *testing.T) {Expect(query.String("data[1].age")).Equals("23")}+func TestGetValueFromEmptyArray(t *testing.T) {+ RegisterT(t)++ query := jsonq.New(`{ "data": [] }`)+ Expect(query.String("unknown[0].name")).Equals("")+ Expect(query.String("data[0].name")).Equals("")+ Expect(query.String("data[0].age")).Equals("")+}+func TestContains(t *testing.T) {RegisterT(t)diff --git a/app/pkg/web/oauth.go b/app/pkg/web/oauth.goindex 0bdce24e9..465e79f8a 100644--- a/app/pkg/web/oauth.go+++ b/app/pkg/web/oauth.go@@ -41,15 +41,15 @@ var (&models.OAuthConfig{Provider: oauth.GoogleProvider,DisplayName: "Google",- ProfileURL: "https://www.googleapis.com/oauth2/v2/userinfo",+ ProfileURL: "https://www.googleapis.com/plus/v1/people/me",ClientID: os.Getenv("OAUTH_GOOGLE_CLIENTID"),ClientSecret: os.Getenv("OAUTH_GOOGLE_SECRET"),- Scope: "https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email",+ Scope: "profile email",AuthorizeURL: google.Endpoint.AuthURL,TokenURL: google.Endpoint.TokenURL,JSONUserIDPath: "id",- JSONNamePath: "name",- JSONEmailPath: "email",+ JSONNamePath: "displayName",+ JSONEmailPath: "emails[0].value",},&models.OAuthConfig{Provider: oauth.GitHubProvider,@@ -130,6 +130,7 @@ func (s *OAuthService) GetProfile(provider string, code string) (*oauth.UserProf//ParseProfileResponse parses profile response into UserProfile modelfunc (s *OAuthService) ParseProfileResponse(body string, config *models.OAuthConfig) (*oauth.UserProfile, error) {query := jsonq.New(body)+ println(body)profile := &oauth.UserProfile{ID: strings.TrimSpace(query.String(config.JSONUserIDPath)),Name: strings.TrimSpace(query.String(config.JSONNamePath)),diff --git a/app/pkg/web/oauth_test.go b/app/pkg/web/oauth_test.goindex 00af50594..0420205ae 100644--- a/app/pkg/web/oauth_test.go+++ b/app/pkg/web/oauth_test.go@@ -28,7 +28,7 @@ func TestGetAuthURL_Google(t *testing.T) {authURL, err := svc.GetAuthURL(oauth.GoogleProvider, "http://example.org", "123")Expect(err).IsNil()- Expect(authURL).Equals("https://accounts.google.com/o/oauth2/auth?client_id=&redirect_uri=http%3A%2F%2Flogin.test.fider.io%3A3000%2Foauth%2Fgoogle%2Fcallback&response_type=code&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email&state=http%3A%2F%2Fexample.org%7C123")+ Expect(authURL).Equals("https://accounts.google.com/o/oauth2/auth?client_id=&redirect_uri=http%3A%2F%2Flogin.test.fider.io%3A3000%2Foauth%2Fgoogle%2Fcallback&response_type=code&scope=profile+email&state=http%3A%2F%2Fexample.org%7C123")}func TestGetAuthURL_GitHub(t *testing.T) {