Repository: amp-labs/connectors
Pull request #228 (2024-04-17 11:53:45)

StackExchange: Update TokenURL
Update the TokenURL to wrap the response in JSON format


Patch:
diff --git a/providers/catalog.go b/providers/catalog.go
index a41df975..20177215 100644
--- a/providers/catalog.go
+++ b/providers/catalog.go
@@ -46,6 +46,8 @@ const (
 	Atlassian                           Provider = "atlassian"
 	Webflow                             Provider = "webflow"
 	StackExchange                       Provider = "stackExchange"
+	GoogleContacts                      Provider = "googleContacts"
+	GoogleMail                          Provider = "googleMail"
 )
 
 // ================================================================================
@@ -997,7 +999,7 @@ var catalog = CatalogType{ // nolint:gochecknoglobals
 			AuthURL:                   "https://api.timelyapp.com/1.1/oauth/authorize",
 			TokenURL:                  "https://api.timelyapp.com/1.1/oauth/token",
 			ExplicitScopesRequired:    false,
-            ExplicitWorkspaceRequired: false,
+			ExplicitWorkspaceRequired: false,
 			TokenMetadataFields: TokenMetadataFields{
 				ScopesField: "scope",
 			},
@@ -1015,7 +1017,7 @@ var catalog = CatalogType{ // nolint:gochecknoglobals
 			Write:     false,
 		},
 	},
-      
+
 	// Atlassian configuration
 	Atlassian: {
 		AuthType: Oauth2,
@@ -1026,7 +1028,7 @@ var catalog = CatalogType{ // nolint:gochecknoglobals
 			TokenURL:                  "https://auth.atlassian.com/oauth/token",
 			ExplicitScopesRequired:    true,
 			ExplicitWorkspaceRequired: false,
-    },
+		},
 		Support: Support{
 			BulkWrite: BulkWriteSupport{
 				Insert: false,
@@ -1040,7 +1042,7 @@ var catalog = CatalogType{ // nolint:gochecknoglobals
 			Write:     false,
 		},
 	},
-  
+
 	// Webflow Support Configuration
 	Webflow: {
 		AuthType: Oauth2,
@@ -1075,7 +1077,63 @@ var catalog = CatalogType{ // nolint:gochecknoglobals
 		OauthOpts: OauthOpts{
 			GrantType:                 AuthorizationCode,
 			AuthURL:                   "https://stackoverflow.com/oauth",
-			TokenURL:                  "https://stackoverflow.com/oauth/access_token",
+			TokenURL:                  "https://stackoverflow.com/oauth/access_token/json",
+			ExplicitScopesRequired:    true,
+			ExplicitWorkspaceRequired: false,
+			TokenMetadataFields: TokenMetadataFields{
+				ScopesField: "scope",
+			},
+		},
+		Support: Support{
+			BulkWrite: BulkWriteSupport{
+				Insert: false,
+				Update: false,
+				Upsert: false,
+				Delete: false,
+			},
+			Proxy:     false,
+			Read:      false,
+			Subscribe: false,
+			Write:     false,
+		},
+	},
+
+	// GoogleContacts Support Configuration
+	GoogleContacts: {
+		AuthType: Oauth2,
+		BaseURL:  "https://people.googleapis.com",
+    OauthOpts: OauthOpts{
+			GrantType:                 AuthorizationCode,
+			AuthURL:                   "https://accounts.google.com/o/oauth2/v2/auth",
+			TokenURL:                  "https://oauth2.googleapis.com/token",
+			ExplicitScopesRequired:    true,
+			ExplicitWorkspaceRequired: false,
+			TokenMetadataFields: TokenMetadataFields{
+				ScopesField: "scope",
+			},
+		},
+		Support: Support{
+			BulkWrite: BulkWriteSupport{
+				Insert: false,
+				Update: false,
+				Upsert: false,
+				Delete: false,
+			},
+			Proxy:     false,
+			Read:      false,
+			Subscribe: false,
+			Write:     false,
+		},
+	},
+
+	// GoogleMail Support Configuration
+	GoogleMail: {
+		AuthType: Oauth2,
+		BaseURL:  "https://gmail.googleapis.com",
+		OauthOpts: OauthOpts{
+			GrantType:                 AuthorizationCode,
+			AuthURL:                   "https://accounts.google.com/o/oauth2/v2/auth",
+			TokenURL:                  "https://oauth2.googleapis.com/token",
 			ExplicitScopesRequired:    true,
 			ExplicitWorkspaceRequired: false,
 			TokenMetadataFields: TokenMetadataFields{


Test patch:
diff --git a/providers/catalog_test.go b/providers/catalog_test.go
index 428f8af7..4c76b343 100644
--- a/providers/catalog_test.go
+++ b/providers/catalog_test.go
@@ -1093,14 +1093,14 @@ var testCases = []struct { // nolint
 	{
 		provider:    Timely,
 		description: "Valid Timely provider config with no substitutions",
-    	expected: &ProviderInfo{
+		expected: &ProviderInfo{
 			AuthType: Oauth2,
 			OauthOpts: OauthOpts{
 				GrantType:                 AuthorizationCode,
-        		AuthURL:                   "https://api.timelyapp.com/1.1/oauth/authorize",
+				AuthURL:                   "https://api.timelyapp.com/1.1/oauth/authorize",
 				TokenURL:                  "https://api.timelyapp.com/1.1/oauth/token",
 				ExplicitScopesRequired:    false,
-        		ExplicitWorkspaceRequired: false,
+				ExplicitWorkspaceRequired: false,
 				TokenMetadataFields: TokenMetadataFields{
 					ScopesField: "scope",
 				},
@@ -1117,22 +1117,22 @@ var testCases = []struct { // nolint
 				Subscribe: false,
 				Proxy:     false,
 			},
-     	 	BaseURL: "https://api.timelyapp.com",
-    	},
+			BaseURL: "https://api.timelyapp.com",
+		},
 		expectedErr: nil,
-  	},
-  	{
+	},
+	{
 		provider:    Atlassian,
 		description: "Valid Atlassian provider config with no substitutions",
-    	expected: &ProviderInfo{
+		expected: &ProviderInfo{
 			AuthType: Oauth2,
 			OauthOpts: OauthOpts{
 				GrantType:                 AuthorizationCode,
-        		AuthURL:                   "https://auth.atlassian.com/authorize",
+				AuthURL:                   "https://auth.atlassian.com/authorize",
 				TokenURL:                  "https://auth.atlassian.com/oauth/token",
 				ExplicitScopesRequired:    true,
 				ExplicitWorkspaceRequired: false,
-      		},
+			},
 			Support: Support{
 				BulkWrite: BulkWriteSupport{
 					Insert: false,
@@ -1145,11 +1145,11 @@ var testCases = []struct { // nolint
 				Subscribe: false,
 				Write:     false,
 			},
-      		BaseURL: "https://api.atlassian.com",
-    	},
+			BaseURL: "https://api.atlassian.com",
+		},
 		expectedErr: nil,
-  	},
-  	{
+	},
+	{
 		provider:    Webflow,
 		description: "Valid Webflow provider config with no substitutions",
 		expected: &ProviderInfo{
@@ -1176,7 +1176,7 @@ var testCases = []struct { // nolint
 				Subscribe: false,
 				Write:     false,
 			},
-      		BaseURL: "https://api.webflow.com",
+			BaseURL: "https://api.webflow.com",
 		},
 		expectedErr: nil,
 	},
@@ -1200,7 +1200,7 @@ var testCases = []struct { // nolint
 			OauthOpts: OauthOpts{
 				GrantType:                 AuthorizationCode,
 				AuthURL:                   "https://stackoverflow.com/oauth",
-				TokenURL:                  "https://stackoverflow.com/oauth/access_token",
+				TokenURL:                  "https://stackoverflow.com/oauth/access_token/json",
 				ExplicitScopesRequired:    true,
 				ExplicitWorkspaceRequired: false,
 				TokenMetadataFields: TokenMetadataFields{
@@ -1211,6 +1211,68 @@ var testCases = []struct { // nolint
 		},
 		expectedErr: nil,
 	},
+	{
+		provider:    GoogleContacts,
+		description: "Valid GoogleContacts provider config with no substitutions",
+    	expected: &ProviderInfo{
+			AuthType: Oauth2,
+			OauthOpts: OauthOpts{
+				GrantType:                 AuthorizationCode,
+				AuthURL:                   "https://accounts.google.com/o/oauth2/v2/auth",
+				TokenURL:                  "https://oauth2.googleapis.com/token",
+				ExplicitScopesRequired:    true,
+				ExplicitWorkspaceRequired: false,
+				TokenMetadataFields: TokenMetadataFields{
+					ScopesField: "scope",
+				},
+			},
+			Support: Support{
+				BulkWrite: BulkWriteSupport{
+					Insert: false,
+					Update: false,
+					Upsert: false,
+					Delete: false,
+				},
+				Proxy:     false,
+				Read:      false,
+				Subscribe: false,
+				Write:     false,
+			},
+      		BaseURL: "https://people.googleapis.com",
+    	},
+		expectedErr: nil,
+	},
+  	{
+		provider:    GoogleMail,
+		description: "Valid GoogleMail provider config with no substitutions",
+		expected: &ProviderInfo{
+			AuthType: Oauth2,
+			OauthOpts: OauthOpts{
+				GrantType:                 AuthorizationCode,
+				AuthURL:                   "https://accounts.google.com/o/oauth2/v2/auth",
+				TokenURL:                  "https://oauth2.googleapis.com/token",
+				ExplicitScopesRequired:    true,
+				ExplicitWorkspaceRequired: false,
+				TokenMetadataFields: TokenMetadataFields{
+					ScopesField: "scope",
+				},
+			},
+			Support: Support{
+				BulkWrite: BulkWriteSupport{
+					Insert: false,
+					Update: false,
+					Upsert: false,
+					Delete: false,
+				},
+				Proxy:     false,
+				Read:      false,
+				Subscribe: false,
+				Write:     false,
+			},
+			BaseURL: "https://gmail.googleapis.com",
+		},
+		expectedErr: nil,
+	},
 }
 
 func TestReadInfo(t *testing.T) { // nolint