diff --git a/examples/with-chi-oso/main.go b/examples/with-chi-oso/main.go index 36509060..a3b06cf3 100644 --- a/examples/with-chi-oso/main.go +++ b/examples/with-chi-oso/main.go @@ -12,9 +12,8 @@ import ( "github.com/supertokens/supertokens-golang/recipe/emailverification" "github.com/supertokens/supertokens-golang/recipe/emailverification/evmodels" "github.com/supertokens/supertokens-golang/recipe/session" + "github.com/supertokens/supertokens-golang/recipe/thirdparty" "github.com/supertokens/supertokens-golang/recipe/thirdparty/tpmodels" - "github.com/supertokens/supertokens-golang/recipe/thirdpartyemailpassword" - "github.com/supertokens/supertokens-golang/recipe/thirdpartyemailpassword/tpepmodels" "github.com/supertokens/supertokens-golang/supertokens" ) @@ -37,111 +36,113 @@ func main() { emailverification.Init(evmodels.TypeInput{ Mode: evmodels.ModeRequired, }), - thirdpartyemailpassword.Init(&tpepmodels.TypeInput{ - Providers: []tpmodels.ProviderInput{ - // We have provided you with development keys which you can use for testsing. - // IMPORTANT: Please replace them with your own OAuth keys for production use. - { - Config: tpmodels.ProviderConfig{ - ThirdPartyId: "google", - Clients: []tpmodels.ProviderClientConfig{ - { - ClientType: "web", - ClientID: "1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com", - ClientSecret: "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", - }, - { - // we use this for mobile apps - ClientType: "mobile", - ClientID: "1060725074195-c7mgk8p0h27c4428prfuo3lg7ould5o7.apps.googleusercontent.com", - ClientSecret: "", // this is empty because we follow Authorization code grant flow via PKCE for mobile apps (Google doesn't issue a client secret for mobile apps). + thirdparty.Init(&tpmodels.TypeInput{ + SignInAndUpFeature: tpmodels.TypeInputSignInAndUp{ + Providers: []tpmodels.ProviderInput{ + // We have provided you with development keys which you can use for testsing. + // IMPORTANT: Please replace them with your own OAuth keys for production use. + { + Config: tpmodels.ProviderConfig{ + ThirdPartyId: "google", + Clients: []tpmodels.ProviderClientConfig{ + { + ClientType: "web", + ClientID: "1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com", + ClientSecret: "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", + }, + { + // we use this for mobile apps + ClientType: "mobile", + ClientID: "1060725074195-c7mgk8p0h27c4428prfuo3lg7ould5o7.apps.googleusercontent.com", + ClientSecret: "", // this is empty because we follow Authorization code grant flow via PKCE for mobile apps (Google doesn't issue a client secret for mobile apps). + }, }, }, }, - }, - { - Config: tpmodels.ProviderConfig{ - ThirdPartyId: "github", - Clients: []tpmodels.ProviderClientConfig{ - { - ClientType: "web", - ClientID: "467101b197249757c71f", - ClientSecret: "e97051221f4b6426e8fe8d51486396703012f5bd", - }, - { - // We use this for mobile apps - ClientType: "mobile", - ClientID: "8a9152860ce869b64c44", - ClientSecret: "00e841f10f288363cd3786b1b1f538f05cfdbda2", + { + Config: tpmodels.ProviderConfig{ + ThirdPartyId: "github", + Clients: []tpmodels.ProviderClientConfig{ + { + ClientType: "web", + ClientID: "467101b197249757c71f", + ClientSecret: "e97051221f4b6426e8fe8d51486396703012f5bd", + }, + { + // We use this for mobile apps + ClientType: "mobile", + ClientID: "8a9152860ce869b64c44", + ClientSecret: "00e841f10f288363cd3786b1b1f538f05cfdbda2", + }, }, }, }, - }, - /* - For Apple signin, iOS apps always use the bundle identifier as the client ID when communicating with Apple. Android, Web and other platforms - need to configure a Service ID on the Apple developer dashboard and use that as client ID. - In the example below 4398792-io.supertokens.example.service is the client ID for Web. Android etc and thus we mark it as default. For iOS - the frontend for the demo app sends the clientId in the request which is then used by the SDK. - */ - { - Config: tpmodels.ProviderConfig{ - ThirdPartyId: "apple", - Clients: []tpmodels.ProviderClientConfig{ - { - // For Android and website apps - ClientType: "web", - ClientID: "4398792-io.supertokens.example.service", - AdditionalConfig: map[string]interface{}{ - "keyId": "7M48Y4RYDL", - "privateKey": "-----BEGIN PRIVATE KEY-----\nMIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgu8gXs+XYkqXD6Ala9Sf/iJXzhbwcoG5dMh1OonpdJUmgCgYIKoZIzj0DAQehRANCAASfrvlFbFCYqn3I2zeknYXLwtH30JuOKestDbSfZYxZNMqhF/OzdZFTV0zc5u5s3eN+oCWbnvl0hM+9IW0UlkdA\n-----END PRIVATE KEY-----", - "teamId": "YWQCXGJRJL", + /* + For Apple signin, iOS apps always use the bundle identifier as the client ID when communicating with Apple. Android, Web and other platforms + need to configure a Service ID on the Apple developer dashboard and use that as client ID. + In the example below 4398792-io.supertokens.example.service is the client ID for Web. Android etc and thus we mark it as default. For iOS + the frontend for the demo app sends the clientId in the request which is then used by the SDK. + */ + { + Config: tpmodels.ProviderConfig{ + ThirdPartyId: "apple", + Clients: []tpmodels.ProviderClientConfig{ + { + // For Android and website apps + ClientType: "web", + ClientID: "4398792-io.supertokens.example.service", + AdditionalConfig: map[string]interface{}{ + "keyId": "7M48Y4RYDL", + "privateKey": "-----BEGIN PRIVATE KEY-----\nMIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgu8gXs+XYkqXD6Ala9Sf/iJXzhbwcoG5dMh1OonpdJUmgCgYIKoZIzj0DAQehRANCAASfrvlFbFCYqn3I2zeknYXLwtH30JuOKestDbSfZYxZNMqhF/OzdZFTV0zc5u5s3eN+oCWbnvl0hM+9IW0UlkdA\n-----END PRIVATE KEY-----", + "teamId": "YWQCXGJRJL", + }, }, - }, - { - // For iOS Apps - ClientType: "ios", - ClientID: "4398792-io.supertokens.example", - AdditionalConfig: map[string]interface{}{ - "keyId": "7M48Y4RYDL", - "privateKey": "-----BEGIN PRIVATE KEY-----\nMIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgu8gXs+XYkqXD6Ala9Sf/iJXzhbwcoG5dMh1OonpdJUmgCgYIKoZIzj0DAQehRANCAASfrvlFbFCYqn3I2zeknYXLwtH30JuOKestDbSfZYxZNMqhF/OzdZFTV0zc5u5s3eN+oCWbnvl0hM+9IW0UlkdA\n-----END PRIVATE KEY-----", - "teamId": "YWQCXGJRJL", + { + // For iOS Apps + ClientType: "ios", + ClientID: "4398792-io.supertokens.example", + AdditionalConfig: map[string]interface{}{ + "keyId": "7M48Y4RYDL", + "privateKey": "-----BEGIN PRIVATE KEY-----\nMIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgu8gXs+XYkqXD6Ala9Sf/iJXzhbwcoG5dMh1OonpdJUmgCgYIKoZIzj0DAQehRANCAASfrvlFbFCYqn3I2zeknYXLwtH30JuOKestDbSfZYxZNMqhF/OzdZFTV0zc5u5s3eN+oCWbnvl0hM+9IW0UlkdA\n-----END PRIVATE KEY-----", + "teamId": "YWQCXGJRJL", + }, }, }, }, }, - }, - { - Config: tpmodels.ProviderConfig{ - ThirdPartyId: "discord", - Clients: []tpmodels.ProviderClientConfig{ - { - ClientType: "web", - ClientID: "4398792-907871294886928395", - ClientSecret: "His4yXGEovVp5TZkZhEAt0ZXGh8uOVDm", - }, - { - // We use this for mobile apps - ClientType: "mobile", - ClientID: "4398792-907871294886928395", - ClientSecret: "His4yXGEovVp5TZkZhEAt0ZXGh8uOVDm", + { + Config: tpmodels.ProviderConfig{ + ThirdPartyId: "discord", + Clients: []tpmodels.ProviderClientConfig{ + { + ClientType: "web", + ClientID: "4398792-907871294886928395", + ClientSecret: "His4yXGEovVp5TZkZhEAt0ZXGh8uOVDm", + }, + { + // We use this for mobile apps + ClientType: "mobile", + ClientID: "4398792-907871294886928395", + ClientSecret: "His4yXGEovVp5TZkZhEAt0ZXGh8uOVDm", + }, }, }, }, - }, - { - Config: tpmodels.ProviderConfig{ - ThirdPartyId: "google-workspaces", - Clients: []tpmodels.ProviderClientConfig{ - { - ClientType: "web", - ClientID: "1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com", - ClientSecret: "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", - }, - { - // We use this for mobile apps - ClientType: "mobile", - ClientID: "1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com", - ClientSecret: "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", + { + Config: tpmodels.ProviderConfig{ + ThirdPartyId: "google-workspaces", + Clients: []tpmodels.ProviderClientConfig{ + { + ClientType: "web", + ClientID: "1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com", + ClientSecret: "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", + }, + { + // We use this for mobile apps + ClientType: "mobile", + ClientID: "1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com", + ClientSecret: "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", + }, }, }, }, diff --git a/examples/with-chi-oso/service/service.go b/examples/with-chi-oso/service/service.go index a8c2e8ec..3f752e8f 100644 --- a/examples/with-chi-oso/service/service.go +++ b/examples/with-chi-oso/service/service.go @@ -9,7 +9,7 @@ import ( "github.com/osohq/go-oso" "github.com/supertokens/supertokens-golang/examples/with-chi-oso/models" "github.com/supertokens/supertokens-golang/recipe/session" - "github.com/supertokens/supertokens-golang/recipe/thirdpartyemailpassword" + "github.com/supertokens/supertokens-golang/recipe/thirdparty" "github.com/supertokens/supertokens-golang/supertokens" ) @@ -92,7 +92,7 @@ func (s *service) Repo(w http.ResponseWriter, r *http.Request) { w.Write([]byte(err.Error())) return } - userByID, err := thirdpartyemailpassword.GetUserById(sessionContainer.GetUserID()) + userByID, err := thirdparty.GetUserByID(sessionContainer.GetUserID()) if err != nil { w.WriteHeader(500) w.Write([]byte(err.Error())) diff --git a/examples/with-chi/main.go b/examples/with-chi/main.go index fd2f1c4b..8065f747 100644 --- a/examples/with-chi/main.go +++ b/examples/with-chi/main.go @@ -7,12 +7,12 @@ import ( "github.com/go-chi/chi/v5" "github.com/go-chi/cors" "github.com/supertokens/supertokens-golang/recipe/dashboard" + "github.com/supertokens/supertokens-golang/recipe/emailpassword" "github.com/supertokens/supertokens-golang/recipe/emailverification" "github.com/supertokens/supertokens-golang/recipe/emailverification/evmodels" "github.com/supertokens/supertokens-golang/recipe/session" + "github.com/supertokens/supertokens-golang/recipe/thirdparty" "github.com/supertokens/supertokens-golang/recipe/thirdparty/tpmodels" - "github.com/supertokens/supertokens-golang/recipe/thirdpartyemailpassword" - "github.com/supertokens/supertokens-golang/recipe/thirdpartyemailpassword/tpepmodels" "github.com/supertokens/supertokens-golang/supertokens" ) @@ -30,7 +30,7 @@ func main() { emailverification.Init(evmodels.TypeInput{ Mode: evmodels.ModeRequired, }), - thirdpartyemailpassword.Init(&tpepmodels.TypeInput{ + thirdparty.Init(&tpmodels.TypeInput{ /* We use different credentials for different platforms when required. For example the redirect URI for Github is different for Web and mobile. In such a case we can provide multiple providers with different client Ids. @@ -39,116 +39,119 @@ func main() { request. In the absence of a clientId in the request the SDK uses the default provider, indicated by `isDefault: true`. When adding multiple providers for the same type (Google, Github etc), make sure to set `isDefault: true`. */ - Providers: []tpmodels.ProviderInput{ - // We have provided you with development keys which you can use for testsing. - // IMPORTANT: Please replace them with your own OAuth keys for production use. - { - Config: tpmodels.ProviderConfig{ - ThirdPartyId: "google", - Clients: []tpmodels.ProviderClientConfig{ - { - ClientType: "web", - ClientID: "1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com", - ClientSecret: "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", - }, - { - // we use this for mobile apps - ClientType: "mobile", - ClientID: "1060725074195-c7mgk8p0h27c4428prfuo3lg7ould5o7.apps.googleusercontent.com", - ClientSecret: "", // this is empty because we follow Authorization code grant flow via PKCE for mobile apps (Google doesn't issue a client secret for mobile apps). + SignInAndUpFeature: tpmodels.TypeInputSignInAndUp{ + Providers: []tpmodels.ProviderInput{ + // We have provided you with development keys which you can use for testsing. + // IMPORTANT: Please replace them with your own OAuth keys for production use. + { + Config: tpmodels.ProviderConfig{ + ThirdPartyId: "google", + Clients: []tpmodels.ProviderClientConfig{ + { + ClientType: "web", + ClientID: "1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com", + ClientSecret: "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", + }, + { + // we use this for mobile apps + ClientType: "mobile", + ClientID: "1060725074195-c7mgk8p0h27c4428prfuo3lg7ould5o7.apps.googleusercontent.com", + ClientSecret: "", // this is empty because we follow Authorization code grant flow via PKCE for mobile apps (Google doesn't issue a client secret for mobile apps). + }, }, }, }, - }, - { - Config: tpmodels.ProviderConfig{ - ThirdPartyId: "github", - Clients: []tpmodels.ProviderClientConfig{ - { - ClientType: "web", - ClientID: "467101b197249757c71f", - ClientSecret: "e97051221f4b6426e8fe8d51486396703012f5bd", - }, - { - // We use this for mobile apps - ClientType: "mobile", - ClientID: "8a9152860ce869b64c44", - ClientSecret: "00e841f10f288363cd3786b1b1f538f05cfdbda2", + { + Config: tpmodels.ProviderConfig{ + ThirdPartyId: "github", + Clients: []tpmodels.ProviderClientConfig{ + { + ClientType: "web", + ClientID: "467101b197249757c71f", + ClientSecret: "e97051221f4b6426e8fe8d51486396703012f5bd", + }, + { + // We use this for mobile apps + ClientType: "mobile", + ClientID: "8a9152860ce869b64c44", + ClientSecret: "00e841f10f288363cd3786b1b1f538f05cfdbda2", + }, }, }, }, - }, - /* - For Apple signin, iOS apps always use the bundle identifier as the client ID when communicating with Apple. Android, Web and other platforms - need to configure a Service ID on the Apple developer dashboard and use that as client ID. - In the example below 4398792-io.supertokens.example.service is the client ID for Web. Android etc and thus we mark it as default. For iOS - the frontend for the demo app sends the clientId in the request which is then used by the SDK. - */ - { - Config: tpmodels.ProviderConfig{ - ThirdPartyId: "apple", - Clients: []tpmodels.ProviderClientConfig{ - { - // For Android and website apps - ClientType: "web", - ClientID: "4398792-io.supertokens.example.service", - AdditionalConfig: map[string]interface{}{ - "keyId": "7M48Y4RYDL", - "privateKey": "-----BEGIN PRIVATE KEY-----\nMIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgu8gXs+XYkqXD6Ala9Sf/iJXzhbwcoG5dMh1OonpdJUmgCgYIKoZIzj0DAQehRANCAASfrvlFbFCYqn3I2zeknYXLwtH30JuOKestDbSfZYxZNMqhF/OzdZFTV0zc5u5s3eN+oCWbnvl0hM+9IW0UlkdA\n-----END PRIVATE KEY-----", - "teamId": "YWQCXGJRJL", + /* + For Apple signin, iOS apps always use the bundle identifier as the client ID when communicating with Apple. Android, Web and other platforms + need to configure a Service ID on the Apple developer dashboard and use that as client ID. + In the example below 4398792-io.supertokens.example.service is the client ID for Web. Android etc and thus we mark it as default. For iOS + the frontend for the demo app sends the clientId in the request which is then used by the SDK. + */ + { + Config: tpmodels.ProviderConfig{ + ThirdPartyId: "apple", + Clients: []tpmodels.ProviderClientConfig{ + { + // For Android and website apps + ClientType: "web", + ClientID: "4398792-io.supertokens.example.service", + AdditionalConfig: map[string]interface{}{ + "keyId": "7M48Y4RYDL", + "privateKey": "-----BEGIN PRIVATE KEY-----\nMIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgu8gXs+XYkqXD6Ala9Sf/iJXzhbwcoG5dMh1OonpdJUmgCgYIKoZIzj0DAQehRANCAASfrvlFbFCYqn3I2zeknYXLwtH30JuOKestDbSfZYxZNMqhF/OzdZFTV0zc5u5s3eN+oCWbnvl0hM+9IW0UlkdA\n-----END PRIVATE KEY-----", + "teamId": "YWQCXGJRJL", + }, }, - }, - { - // For iOS Apps - ClientType: "ios", - ClientID: "4398792-io.supertokens.example", - AdditionalConfig: map[string]interface{}{ - "keyId": "7M48Y4RYDL", - "privateKey": "-----BEGIN PRIVATE KEY-----\nMIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgu8gXs+XYkqXD6Ala9Sf/iJXzhbwcoG5dMh1OonpdJUmgCgYIKoZIzj0DAQehRANCAASfrvlFbFCYqn3I2zeknYXLwtH30JuOKestDbSfZYxZNMqhF/OzdZFTV0zc5u5s3eN+oCWbnvl0hM+9IW0UlkdA\n-----END PRIVATE KEY-----", - "teamId": "YWQCXGJRJL", + { + // For iOS Apps + ClientType: "ios", + ClientID: "4398792-io.supertokens.example", + AdditionalConfig: map[string]interface{}{ + "keyId": "7M48Y4RYDL", + "privateKey": "-----BEGIN PRIVATE KEY-----\nMIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgu8gXs+XYkqXD6Ala9Sf/iJXzhbwcoG5dMh1OonpdJUmgCgYIKoZIzj0DAQehRANCAASfrvlFbFCYqn3I2zeknYXLwtH30JuOKestDbSfZYxZNMqhF/OzdZFTV0zc5u5s3eN+oCWbnvl0hM+9IW0UlkdA\n-----END PRIVATE KEY-----", + "teamId": "YWQCXGJRJL", + }, }, }, }, }, - }, - { - Config: tpmodels.ProviderConfig{ - ThirdPartyId: "discord", - Clients: []tpmodels.ProviderClientConfig{ - { - ClientType: "web", - ClientID: "4398792-907871294886928395", - ClientSecret: "His4yXGEovVp5TZkZhEAt0ZXGh8uOVDm", - }, - { - // We use this for mobile apps - ClientType: "mobile", - ClientID: "4398792-907871294886928395", - ClientSecret: "His4yXGEovVp5TZkZhEAt0ZXGh8uOVDm", + { + Config: tpmodels.ProviderConfig{ + ThirdPartyId: "discord", + Clients: []tpmodels.ProviderClientConfig{ + { + ClientType: "web", + ClientID: "4398792-907871294886928395", + ClientSecret: "His4yXGEovVp5TZkZhEAt0ZXGh8uOVDm", + }, + { + // We use this for mobile apps + ClientType: "mobile", + ClientID: "4398792-907871294886928395", + ClientSecret: "His4yXGEovVp5TZkZhEAt0ZXGh8uOVDm", + }, }, }, }, - }, - { - Config: tpmodels.ProviderConfig{ - ThirdPartyId: "google-workspaces", - Clients: []tpmodels.ProviderClientConfig{ - { - ClientType: "web", - ClientID: "1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com", - ClientSecret: "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", - }, - { - // We use this for mobile apps - ClientType: "mobile", - ClientID: "1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com", - ClientSecret: "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", + { + Config: tpmodels.ProviderConfig{ + ThirdPartyId: "google-workspaces", + Clients: []tpmodels.ProviderClientConfig{ + { + ClientType: "web", + ClientID: "1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com", + ClientSecret: "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", + }, + { + // We use this for mobile apps + ClientType: "mobile", + ClientID: "1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com", + ClientSecret: "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", + }, }, }, }, }, }, }), + emailpassword.Init(nil), session.Init(nil), dashboard.Init(nil), }, diff --git a/examples/with-fiber/main.go b/examples/with-fiber/main.go index 2a2b1f9a..72f6f437 100644 --- a/examples/with-fiber/main.go +++ b/examples/with-fiber/main.go @@ -13,9 +13,8 @@ import ( "github.com/supertokens/supertokens-golang/recipe/emailverification/evmodels" "github.com/supertokens/supertokens-golang/recipe/session" "github.com/supertokens/supertokens-golang/recipe/session/sessmodels" + "github.com/supertokens/supertokens-golang/recipe/thirdparty" "github.com/supertokens/supertokens-golang/recipe/thirdparty/tpmodels" - "github.com/supertokens/supertokens-golang/recipe/thirdpartyemailpassword" - "github.com/supertokens/supertokens-golang/recipe/thirdpartyemailpassword/tpepmodels" "github.com/supertokens/supertokens-golang/supertokens" ) @@ -33,7 +32,7 @@ func main() { emailverification.Init(evmodels.TypeInput{ Mode: evmodels.ModeRequired, }), - thirdpartyemailpassword.Init(&tpepmodels.TypeInput{ + thirdparty.Init(&tpmodels.TypeInput{ /* We use different credentials for different platforms when required. For example the redirect URI for Github is different for Web and mobile. In such a case we can provide multiple providers with different client Ids. @@ -41,110 +40,112 @@ func main() { request. In the absence of a clientId in the request the SDK uses the default provider, indicated by `isDefault: true`. When adding multiple providers for the same type (Google, Github etc), make sure to set `isDefault: true`. */ - Providers: []tpmodels.ProviderInput{ - // We have provided you with development keys which you can use for testsing. - // IMPORTANT: Please replace them with your own OAuth keys for production use. - { - Config: tpmodels.ProviderConfig{ - ThirdPartyId: "google", - Clients: []tpmodels.ProviderClientConfig{ - { - ClientType: "web", - ClientID: "1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com", - ClientSecret: "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", - }, - { - // we use this for mobile apps - ClientType: "mobile", - ClientID: "1060725074195-c7mgk8p0h27c4428prfuo3lg7ould5o7.apps.googleusercontent.com", - ClientSecret: "", // this is empty because we follow Authorization code grant flow via PKCE for mobile apps (Google doesn't issue a client secret for mobile apps). + SignInAndUpFeature: tpmodels.TypeInputSignInAndUp{ + Providers: []tpmodels.ProviderInput{ + // We have provided you with development keys which you can use for testsing. + // IMPORTANT: Please replace them with your own OAuth keys for production use. + { + Config: tpmodels.ProviderConfig{ + ThirdPartyId: "google", + Clients: []tpmodels.ProviderClientConfig{ + { + ClientType: "web", + ClientID: "1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com", + ClientSecret: "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", + }, + { + // we use this for mobile apps + ClientType: "mobile", + ClientID: "1060725074195-c7mgk8p0h27c4428prfuo3lg7ould5o7.apps.googleusercontent.com", + ClientSecret: "", // this is empty because we follow Authorization code grant flow via PKCE for mobile apps (Google doesn't issue a client secret for mobile apps). + }, }, }, }, - }, - { - Config: tpmodels.ProviderConfig{ - ThirdPartyId: "github", - Clients: []tpmodels.ProviderClientConfig{ - { - ClientType: "web", - ClientID: "467101b197249757c71f", - ClientSecret: "e97051221f4b6426e8fe8d51486396703012f5bd", - }, - { - // We use this for mobile apps - ClientType: "mobile", - ClientID: "8a9152860ce869b64c44", - ClientSecret: "00e841f10f288363cd3786b1b1f538f05cfdbda2", + { + Config: tpmodels.ProviderConfig{ + ThirdPartyId: "github", + Clients: []tpmodels.ProviderClientConfig{ + { + ClientType: "web", + ClientID: "467101b197249757c71f", + ClientSecret: "e97051221f4b6426e8fe8d51486396703012f5bd", + }, + { + // We use this for mobile apps + ClientType: "mobile", + ClientID: "8a9152860ce869b64c44", + ClientSecret: "00e841f10f288363cd3786b1b1f538f05cfdbda2", + }, }, }, }, - }, - /* - For Apple signin, iOS apps always use the bundle identifier as the client ID when communicating with Apple. Android, Web and other platforms - need to configure a Service ID on the Apple developer dashboard and use that as client ID. - In the example below 4398792-io.supertokens.example.service is the client ID for Web. Android etc and thus we mark it as default. For iOS - the frontend for the demo app sends the clientId in the request which is then used by the SDK. - */ - { - Config: tpmodels.ProviderConfig{ - ThirdPartyId: "apple", - Clients: []tpmodels.ProviderClientConfig{ - { - // For Android and website apps - ClientType: "web", - ClientID: "4398792-io.supertokens.example.service", - AdditionalConfig: map[string]interface{}{ - "keyId": "7M48Y4RYDL", - "privateKey": "-----BEGIN PRIVATE KEY-----\nMIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgu8gXs+XYkqXD6Ala9Sf/iJXzhbwcoG5dMh1OonpdJUmgCgYIKoZIzj0DAQehRANCAASfrvlFbFCYqn3I2zeknYXLwtH30JuOKestDbSfZYxZNMqhF/OzdZFTV0zc5u5s3eN+oCWbnvl0hM+9IW0UlkdA\n-----END PRIVATE KEY-----", - "teamId": "YWQCXGJRJL", + /* + For Apple signin, iOS apps always use the bundle identifier as the client ID when communicating with Apple. Android, Web and other platforms + need to configure a Service ID on the Apple developer dashboard and use that as client ID. + In the example below 4398792-io.supertokens.example.service is the client ID for Web. Android etc and thus we mark it as default. For iOS + the frontend for the demo app sends the clientId in the request which is then used by the SDK. + */ + { + Config: tpmodels.ProviderConfig{ + ThirdPartyId: "apple", + Clients: []tpmodels.ProviderClientConfig{ + { + // For Android and website apps + ClientType: "web", + ClientID: "4398792-io.supertokens.example.service", + AdditionalConfig: map[string]interface{}{ + "keyId": "7M48Y4RYDL", + "privateKey": "-----BEGIN PRIVATE KEY-----\nMIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgu8gXs+XYkqXD6Ala9Sf/iJXzhbwcoG5dMh1OonpdJUmgCgYIKoZIzj0DAQehRANCAASfrvlFbFCYqn3I2zeknYXLwtH30JuOKestDbSfZYxZNMqhF/OzdZFTV0zc5u5s3eN+oCWbnvl0hM+9IW0UlkdA\n-----END PRIVATE KEY-----", + "teamId": "YWQCXGJRJL", + }, }, - }, - { - // For iOS Apps - ClientType: "ios", - ClientID: "4398792-io.supertokens.example", - AdditionalConfig: map[string]interface{}{ - "keyId": "7M48Y4RYDL", - "privateKey": "-----BEGIN PRIVATE KEY-----\nMIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgu8gXs+XYkqXD6Ala9Sf/iJXzhbwcoG5dMh1OonpdJUmgCgYIKoZIzj0DAQehRANCAASfrvlFbFCYqn3I2zeknYXLwtH30JuOKestDbSfZYxZNMqhF/OzdZFTV0zc5u5s3eN+oCWbnvl0hM+9IW0UlkdA\n-----END PRIVATE KEY-----", - "teamId": "YWQCXGJRJL", + { + // For iOS Apps + ClientType: "ios", + ClientID: "4398792-io.supertokens.example", + AdditionalConfig: map[string]interface{}{ + "keyId": "7M48Y4RYDL", + "privateKey": "-----BEGIN PRIVATE KEY-----\nMIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgu8gXs+XYkqXD6Ala9Sf/iJXzhbwcoG5dMh1OonpdJUmgCgYIKoZIzj0DAQehRANCAASfrvlFbFCYqn3I2zeknYXLwtH30JuOKestDbSfZYxZNMqhF/OzdZFTV0zc5u5s3eN+oCWbnvl0hM+9IW0UlkdA\n-----END PRIVATE KEY-----", + "teamId": "YWQCXGJRJL", + }, }, }, }, }, - }, - { - Config: tpmodels.ProviderConfig{ - ThirdPartyId: "discord", - Clients: []tpmodels.ProviderClientConfig{ - { - ClientType: "web", - ClientID: "4398792-907871294886928395", - ClientSecret: "His4yXGEovVp5TZkZhEAt0ZXGh8uOVDm", - }, - { - // We use this for mobile apps - ClientType: "mobile", - ClientID: "4398792-907871294886928395", - ClientSecret: "His4yXGEovVp5TZkZhEAt0ZXGh8uOVDm", + { + Config: tpmodels.ProviderConfig{ + ThirdPartyId: "discord", + Clients: []tpmodels.ProviderClientConfig{ + { + ClientType: "web", + ClientID: "4398792-907871294886928395", + ClientSecret: "His4yXGEovVp5TZkZhEAt0ZXGh8uOVDm", + }, + { + // We use this for mobile apps + ClientType: "mobile", + ClientID: "4398792-907871294886928395", + ClientSecret: "His4yXGEovVp5TZkZhEAt0ZXGh8uOVDm", + }, }, }, }, - }, - { - Config: tpmodels.ProviderConfig{ - ThirdPartyId: "google-workspaces", - Clients: []tpmodels.ProviderClientConfig{ - { - ClientType: "web", - ClientID: "1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com", - ClientSecret: "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", - }, - { - // We use this for mobile apps - ClientType: "mobile", - ClientID: "1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com", - ClientSecret: "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", + { + Config: tpmodels.ProviderConfig{ + ThirdPartyId: "google-workspaces", + Clients: []tpmodels.ProviderClientConfig{ + { + ClientType: "web", + ClientID: "1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com", + ClientSecret: "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", + }, + { + // We use this for mobile apps + ClientType: "mobile", + ClientID: "1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com", + ClientSecret: "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", + }, }, }, }, diff --git a/examples/with-gin/config/config.go b/examples/with-gin/config/config.go index 8722e0c9..59af48b3 100644 --- a/examples/with-gin/config/config.go +++ b/examples/with-gin/config/config.go @@ -1,16 +1,16 @@ package config import ( - "github.com/supertokens/supertokens-golang/recipe/dashboard" "log" + "github.com/supertokens/supertokens-golang/recipe/dashboard" + "github.com/spf13/viper" "github.com/supertokens/supertokens-golang/recipe/emailverification" "github.com/supertokens/supertokens-golang/recipe/emailverification/evmodels" "github.com/supertokens/supertokens-golang/recipe/session" + "github.com/supertokens/supertokens-golang/recipe/thirdparty" "github.com/supertokens/supertokens-golang/recipe/thirdparty/tpmodels" - "github.com/supertokens/supertokens-golang/recipe/thirdpartyemailpassword" - "github.com/supertokens/supertokens-golang/recipe/thirdpartyemailpassword/tpepmodels" "github.com/supertokens/supertokens-golang/supertokens" ) @@ -49,8 +49,10 @@ func Init() { emailverification.Init(evmodels.TypeInput{ Mode: evmodels.ModeRequired, }), - thirdpartyemailpassword.Init(&tpepmodels.TypeInput{ - Providers: providers, + thirdparty.Init(&tpmodels.TypeInput{ + SignInAndUpFeature: tpmodels.TypeInputSignInAndUp{ + Providers: providers, + }, }), session.Init(nil), dashboard.Init(nil), diff --git a/examples/with-go-zero/main.go b/examples/with-go-zero/main.go index 0d0b4113..8f8c0aee 100644 --- a/examples/with-go-zero/main.go +++ b/examples/with-go-zero/main.go @@ -2,17 +2,17 @@ package main import ( "encoding/json" - "github.com/supertokens/supertokens-golang/recipe/dashboard" "log" "net/http" "strings" + "github.com/supertokens/supertokens-golang/recipe/dashboard" + "github.com/supertokens/supertokens-golang/recipe/emailverification" "github.com/supertokens/supertokens-golang/recipe/emailverification/evmodels" "github.com/supertokens/supertokens-golang/recipe/session" + "github.com/supertokens/supertokens-golang/recipe/thirdparty" "github.com/supertokens/supertokens-golang/recipe/thirdparty/tpmodels" - "github.com/supertokens/supertokens-golang/recipe/thirdpartyemailpassword" - "github.com/supertokens/supertokens-golang/recipe/thirdpartyemailpassword/tpepmodels" "github.com/supertokens/supertokens-golang/supertokens" "github.com/zeromicro/go-zero/rest" ) @@ -31,7 +31,7 @@ func main() { emailverification.Init(evmodels.TypeInput{ Mode: evmodels.ModeRequired, }), - thirdpartyemailpassword.Init(&tpepmodels.TypeInput{ + thirdparty.Init(&tpmodels.TypeInput{ /* We use different credentials for different platforms when required. For example the redirect URI for Github is different for Web and mobile. In such a case we can provide multiple providers with different client Ids. @@ -39,110 +39,112 @@ func main() { request. In the absence of a clientId in the request the SDK uses the default provider, indicated by `isDefault: true`. When adding multiple providers for the same type (Google, Github etc), make sure to set `isDefault: true`. */ - Providers: []tpmodels.ProviderInput{ - // We have provided you with development keys which you can use for testsing. - // IMPORTANT: Please replace them with your own OAuth keys for production use. - { - Config: tpmodels.ProviderConfig{ - ThirdPartyId: "google", - Clients: []tpmodels.ProviderClientConfig{ - { - ClientType: "web", - ClientID: "1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com", - ClientSecret: "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", - }, - { - // we use this for mobile apps - ClientType: "mobile", - ClientID: "1060725074195-c7mgk8p0h27c4428prfuo3lg7ould5o7.apps.googleusercontent.com", - ClientSecret: "", // this is empty because we follow Authorization code grant flow via PKCE for mobile apps (Google doesn't issue a client secret for mobile apps). + SignInAndUpFeature: tpmodels.TypeInputSignInAndUp{ + Providers: []tpmodels.ProviderInput{ + // We have provided you with development keys which you can use for testsing. + // IMPORTANT: Please replace them with your own OAuth keys for production use. + { + Config: tpmodels.ProviderConfig{ + ThirdPartyId: "google", + Clients: []tpmodels.ProviderClientConfig{ + { + ClientType: "web", + ClientID: "1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com", + ClientSecret: "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", + }, + { + // we use this for mobile apps + ClientType: "mobile", + ClientID: "1060725074195-c7mgk8p0h27c4428prfuo3lg7ould5o7.apps.googleusercontent.com", + ClientSecret: "", // this is empty because we follow Authorization code grant flow via PKCE for mobile apps (Google doesn't issue a client secret for mobile apps). + }, }, }, }, - }, - { - Config: tpmodels.ProviderConfig{ - ThirdPartyId: "github", - Clients: []tpmodels.ProviderClientConfig{ - { - ClientType: "web", - ClientID: "467101b197249757c71f", - ClientSecret: "e97051221f4b6426e8fe8d51486396703012f5bd", - }, - { - // We use this for mobile apps - ClientType: "mobile", - ClientID: "8a9152860ce869b64c44", - ClientSecret: "00e841f10f288363cd3786b1b1f538f05cfdbda2", + { + Config: tpmodels.ProviderConfig{ + ThirdPartyId: "github", + Clients: []tpmodels.ProviderClientConfig{ + { + ClientType: "web", + ClientID: "467101b197249757c71f", + ClientSecret: "e97051221f4b6426e8fe8d51486396703012f5bd", + }, + { + // We use this for mobile apps + ClientType: "mobile", + ClientID: "8a9152860ce869b64c44", + ClientSecret: "00e841f10f288363cd3786b1b1f538f05cfdbda2", + }, }, }, }, - }, - /* - For Apple signin, iOS apps always use the bundle identifier as the client ID when communicating with Apple. Android, Web and other platforms - need to configure a Service ID on the Apple developer dashboard and use that as client ID. - In the example below 4398792-io.supertokens.example.service is the client ID for Web. Android etc and thus we mark it as default. For iOS - the frontend for the demo app sends the clientId in the request which is then used by the SDK. - */ - { - Config: tpmodels.ProviderConfig{ - ThirdPartyId: "apple", - Clients: []tpmodels.ProviderClientConfig{ - { - // For Android and website apps - ClientType: "web", - ClientID: "4398792-io.supertokens.example.service", - AdditionalConfig: map[string]interface{}{ - "keyId": "7M48Y4RYDL", - "privateKey": "-----BEGIN PRIVATE KEY-----\nMIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgu8gXs+XYkqXD6Ala9Sf/iJXzhbwcoG5dMh1OonpdJUmgCgYIKoZIzj0DAQehRANCAASfrvlFbFCYqn3I2zeknYXLwtH30JuOKestDbSfZYxZNMqhF/OzdZFTV0zc5u5s3eN+oCWbnvl0hM+9IW0UlkdA\n-----END PRIVATE KEY-----", - "teamId": "YWQCXGJRJL", + /* + For Apple signin, iOS apps always use the bundle identifier as the client ID when communicating with Apple. Android, Web and other platforms + need to configure a Service ID on the Apple developer dashboard and use that as client ID. + In the example below 4398792-io.supertokens.example.service is the client ID for Web. Android etc and thus we mark it as default. For iOS + the frontend for the demo app sends the clientId in the request which is then used by the SDK. + */ + { + Config: tpmodels.ProviderConfig{ + ThirdPartyId: "apple", + Clients: []tpmodels.ProviderClientConfig{ + { + // For Android and website apps + ClientType: "web", + ClientID: "4398792-io.supertokens.example.service", + AdditionalConfig: map[string]interface{}{ + "keyId": "7M48Y4RYDL", + "privateKey": "-----BEGIN PRIVATE KEY-----\nMIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgu8gXs+XYkqXD6Ala9Sf/iJXzhbwcoG5dMh1OonpdJUmgCgYIKoZIzj0DAQehRANCAASfrvlFbFCYqn3I2zeknYXLwtH30JuOKestDbSfZYxZNMqhF/OzdZFTV0zc5u5s3eN+oCWbnvl0hM+9IW0UlkdA\n-----END PRIVATE KEY-----", + "teamId": "YWQCXGJRJL", + }, }, - }, - { - // For iOS Apps - ClientType: "ios", - ClientID: "4398792-io.supertokens.example", - AdditionalConfig: map[string]interface{}{ - "keyId": "7M48Y4RYDL", - "privateKey": "-----BEGIN PRIVATE KEY-----\nMIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgu8gXs+XYkqXD6Ala9Sf/iJXzhbwcoG5dMh1OonpdJUmgCgYIKoZIzj0DAQehRANCAASfrvlFbFCYqn3I2zeknYXLwtH30JuOKestDbSfZYxZNMqhF/OzdZFTV0zc5u5s3eN+oCWbnvl0hM+9IW0UlkdA\n-----END PRIVATE KEY-----", - "teamId": "YWQCXGJRJL", + { + // For iOS Apps + ClientType: "ios", + ClientID: "4398792-io.supertokens.example", + AdditionalConfig: map[string]interface{}{ + "keyId": "7M48Y4RYDL", + "privateKey": "-----BEGIN PRIVATE KEY-----\nMIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgu8gXs+XYkqXD6Ala9Sf/iJXzhbwcoG5dMh1OonpdJUmgCgYIKoZIzj0DAQehRANCAASfrvlFbFCYqn3I2zeknYXLwtH30JuOKestDbSfZYxZNMqhF/OzdZFTV0zc5u5s3eN+oCWbnvl0hM+9IW0UlkdA\n-----END PRIVATE KEY-----", + "teamId": "YWQCXGJRJL", + }, }, }, }, }, - }, - { - Config: tpmodels.ProviderConfig{ - ThirdPartyId: "discord", - Clients: []tpmodels.ProviderClientConfig{ - { - ClientType: "web", - ClientID: "4398792-907871294886928395", - ClientSecret: "His4yXGEovVp5TZkZhEAt0ZXGh8uOVDm", - }, - { - // We use this for mobile apps - ClientType: "mobile", - ClientID: "4398792-907871294886928395", - ClientSecret: "His4yXGEovVp5TZkZhEAt0ZXGh8uOVDm", + { + Config: tpmodels.ProviderConfig{ + ThirdPartyId: "discord", + Clients: []tpmodels.ProviderClientConfig{ + { + ClientType: "web", + ClientID: "4398792-907871294886928395", + ClientSecret: "His4yXGEovVp5TZkZhEAt0ZXGh8uOVDm", + }, + { + // We use this for mobile apps + ClientType: "mobile", + ClientID: "4398792-907871294886928395", + ClientSecret: "His4yXGEovVp5TZkZhEAt0ZXGh8uOVDm", + }, }, }, }, - }, - { - Config: tpmodels.ProviderConfig{ - ThirdPartyId: "google-workspaces", - Clients: []tpmodels.ProviderClientConfig{ - { - ClientType: "web", - ClientID: "1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com", - ClientSecret: "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", - }, - { - // We use this for mobile apps - ClientType: "mobile", - ClientID: "1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com", - ClientSecret: "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", + { + Config: tpmodels.ProviderConfig{ + ThirdPartyId: "google-workspaces", + Clients: []tpmodels.ProviderClientConfig{ + { + ClientType: "web", + ClientID: "1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com", + ClientSecret: "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", + }, + { + // We use this for mobile apps + ClientType: "mobile", + ClientID: "1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com", + ClientSecret: "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", + }, }, }, }, diff --git a/examples/with-http/main.go b/examples/with-http/main.go index 6a5e40d1..7b513221 100644 --- a/examples/with-http/main.go +++ b/examples/with-http/main.go @@ -2,16 +2,16 @@ package main import ( "encoding/json" - "github.com/supertokens/supertokens-golang/recipe/dashboard" "net/http" "strings" + "github.com/supertokens/supertokens-golang/recipe/dashboard" + "github.com/supertokens/supertokens-golang/recipe/emailverification" "github.com/supertokens/supertokens-golang/recipe/emailverification/evmodels" "github.com/supertokens/supertokens-golang/recipe/session" + "github.com/supertokens/supertokens-golang/recipe/thirdparty" "github.com/supertokens/supertokens-golang/recipe/thirdparty/tpmodels" - "github.com/supertokens/supertokens-golang/recipe/thirdpartyemailpassword" - "github.com/supertokens/supertokens-golang/recipe/thirdpartyemailpassword/tpepmodels" "github.com/supertokens/supertokens-golang/supertokens" ) @@ -29,7 +29,7 @@ func main() { emailverification.Init(evmodels.TypeInput{ Mode: evmodels.ModeRequired, }), - thirdpartyemailpassword.Init(&tpepmodels.TypeInput{ + thirdparty.Init(&tpmodels.TypeInput{ /* We use different credentials for different platforms when required. For example the redirect URI for Github is different for Web and mobile. In such a case we can provide multiple providers with different client Ids. @@ -38,110 +38,112 @@ func main() { request. In the absence of a clientId in the request the SDK uses the default provider, indicated by `isDefault: true`. When adding multiple providers for the same type (Google, Github etc), make sure to set `isDefault: true`. */ - Providers: []tpmodels.ProviderInput{ - // We have provided you with development keys which you can use for testsing. - // IMPORTANT: Please replace them with your own OAuth keys for production use. - { - Config: tpmodels.ProviderConfig{ - ThirdPartyId: "google", - Clients: []tpmodels.ProviderClientConfig{ - { - ClientType: "web", - ClientID: "1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com", - ClientSecret: "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", - }, - { - // we use this for mobile apps - ClientType: "mobile", - ClientID: "1060725074195-c7mgk8p0h27c4428prfuo3lg7ould5o7.apps.googleusercontent.com", - ClientSecret: "", // this is empty because we follow Authorization code grant flow via PKCE for mobile apps (Google doesn't issue a client secret for mobile apps). + SignInAndUpFeature: tpmodels.TypeInputSignInAndUp{ + Providers: []tpmodels.ProviderInput{ + // We have provided you with development keys which you can use for testsing. + // IMPORTANT: Please replace them with your own OAuth keys for production use. + { + Config: tpmodels.ProviderConfig{ + ThirdPartyId: "google", + Clients: []tpmodels.ProviderClientConfig{ + { + ClientType: "web", + ClientID: "1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com", + ClientSecret: "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", + }, + { + // we use this for mobile apps + ClientType: "mobile", + ClientID: "1060725074195-c7mgk8p0h27c4428prfuo3lg7ould5o7.apps.googleusercontent.com", + ClientSecret: "", // this is empty because we follow Authorization code grant flow via PKCE for mobile apps (Google doesn't issue a client secret for mobile apps). + }, }, }, }, - }, - { - Config: tpmodels.ProviderConfig{ - ThirdPartyId: "github", - Clients: []tpmodels.ProviderClientConfig{ - { - ClientType: "web", - ClientID: "467101b197249757c71f", - ClientSecret: "e97051221f4b6426e8fe8d51486396703012f5bd", - }, - { - // We use this for mobile apps - ClientType: "mobile", - ClientID: "8a9152860ce869b64c44", - ClientSecret: "00e841f10f288363cd3786b1b1f538f05cfdbda2", + { + Config: tpmodels.ProviderConfig{ + ThirdPartyId: "github", + Clients: []tpmodels.ProviderClientConfig{ + { + ClientType: "web", + ClientID: "467101b197249757c71f", + ClientSecret: "e97051221f4b6426e8fe8d51486396703012f5bd", + }, + { + // We use this for mobile apps + ClientType: "mobile", + ClientID: "8a9152860ce869b64c44", + ClientSecret: "00e841f10f288363cd3786b1b1f538f05cfdbda2", + }, }, }, }, - }, - /* - For Apple signin, iOS apps always use the bundle identifier as the client ID when communicating with Apple. Android, Web and other platforms - need to configure a Service ID on the Apple developer dashboard and use that as client ID. - In the example below 4398792-io.supertokens.example.service is the client ID for Web. Android etc and thus we mark it as default. For iOS - the frontend for the demo app sends the clientId in the request which is then used by the SDK. - */ - { - Config: tpmodels.ProviderConfig{ - ThirdPartyId: "apple", - Clients: []tpmodels.ProviderClientConfig{ - { - // For Android and website apps - ClientType: "web", - ClientID: "4398792-io.supertokens.example.service", - AdditionalConfig: map[string]interface{}{ - "keyId": "7M48Y4RYDL", - "privateKey": "-----BEGIN PRIVATE KEY-----\nMIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgu8gXs+XYkqXD6Ala9Sf/iJXzhbwcoG5dMh1OonpdJUmgCgYIKoZIzj0DAQehRANCAASfrvlFbFCYqn3I2zeknYXLwtH30JuOKestDbSfZYxZNMqhF/OzdZFTV0zc5u5s3eN+oCWbnvl0hM+9IW0UlkdA\n-----END PRIVATE KEY-----", - "teamId": "YWQCXGJRJL", + /* + For Apple signin, iOS apps always use the bundle identifier as the client ID when communicating with Apple. Android, Web and other platforms + need to configure a Service ID on the Apple developer dashboard and use that as client ID. + In the example below 4398792-io.supertokens.example.service is the client ID for Web. Android etc and thus we mark it as default. For iOS + the frontend for the demo app sends the clientId in the request which is then used by the SDK. + */ + { + Config: tpmodels.ProviderConfig{ + ThirdPartyId: "apple", + Clients: []tpmodels.ProviderClientConfig{ + { + // For Android and website apps + ClientType: "web", + ClientID: "4398792-io.supertokens.example.service", + AdditionalConfig: map[string]interface{}{ + "keyId": "7M48Y4RYDL", + "privateKey": "-----BEGIN PRIVATE KEY-----\nMIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgu8gXs+XYkqXD6Ala9Sf/iJXzhbwcoG5dMh1OonpdJUmgCgYIKoZIzj0DAQehRANCAASfrvlFbFCYqn3I2zeknYXLwtH30JuOKestDbSfZYxZNMqhF/OzdZFTV0zc5u5s3eN+oCWbnvl0hM+9IW0UlkdA\n-----END PRIVATE KEY-----", + "teamId": "YWQCXGJRJL", + }, }, - }, - { - // For iOS Apps - ClientType: "ios", - ClientID: "4398792-io.supertokens.example", - AdditionalConfig: map[string]interface{}{ - "keyId": "7M48Y4RYDL", - "privateKey": "-----BEGIN PRIVATE KEY-----\nMIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgu8gXs+XYkqXD6Ala9Sf/iJXzhbwcoG5dMh1OonpdJUmgCgYIKoZIzj0DAQehRANCAASfrvlFbFCYqn3I2zeknYXLwtH30JuOKestDbSfZYxZNMqhF/OzdZFTV0zc5u5s3eN+oCWbnvl0hM+9IW0UlkdA\n-----END PRIVATE KEY-----", - "teamId": "YWQCXGJRJL", + { + // For iOS Apps + ClientType: "ios", + ClientID: "4398792-io.supertokens.example", + AdditionalConfig: map[string]interface{}{ + "keyId": "7M48Y4RYDL", + "privateKey": "-----BEGIN PRIVATE KEY-----\nMIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgu8gXs+XYkqXD6Ala9Sf/iJXzhbwcoG5dMh1OonpdJUmgCgYIKoZIzj0DAQehRANCAASfrvlFbFCYqn3I2zeknYXLwtH30JuOKestDbSfZYxZNMqhF/OzdZFTV0zc5u5s3eN+oCWbnvl0hM+9IW0UlkdA\n-----END PRIVATE KEY-----", + "teamId": "YWQCXGJRJL", + }, }, }, }, }, - }, - { - Config: tpmodels.ProviderConfig{ - ThirdPartyId: "discord", - Clients: []tpmodels.ProviderClientConfig{ - { - ClientType: "web", - ClientID: "4398792-907871294886928395", - ClientSecret: "His4yXGEovVp5TZkZhEAt0ZXGh8uOVDm", - }, - { - // We use this for mobile apps - ClientType: "mobile", - ClientID: "4398792-907871294886928395", - ClientSecret: "His4yXGEovVp5TZkZhEAt0ZXGh8uOVDm", + { + Config: tpmodels.ProviderConfig{ + ThirdPartyId: "discord", + Clients: []tpmodels.ProviderClientConfig{ + { + ClientType: "web", + ClientID: "4398792-907871294886928395", + ClientSecret: "His4yXGEovVp5TZkZhEAt0ZXGh8uOVDm", + }, + { + // We use this for mobile apps + ClientType: "mobile", + ClientID: "4398792-907871294886928395", + ClientSecret: "His4yXGEovVp5TZkZhEAt0ZXGh8uOVDm", + }, }, }, }, - }, - { - Config: tpmodels.ProviderConfig{ - ThirdPartyId: "google-workspaces", - Clients: []tpmodels.ProviderClientConfig{ - { - ClientType: "web", - ClientID: "1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com", - ClientSecret: "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", - }, - { - // We use this for mobile apps - ClientType: "mobile", - ClientID: "1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com", - ClientSecret: "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", + { + Config: tpmodels.ProviderConfig{ + ThirdPartyId: "google-workspaces", + Clients: []tpmodels.ProviderClientConfig{ + { + ClientType: "web", + ClientID: "1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com", + ClientSecret: "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", + }, + { + // We use this for mobile apps + ClientType: "mobile", + ClientID: "1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com", + ClientSecret: "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", + }, }, }, }, diff --git a/examples/with-labstack-echo/main.go b/examples/with-labstack-echo/main.go index a080f934..a8f1e9f3 100644 --- a/examples/with-labstack-echo/main.go +++ b/examples/with-labstack-echo/main.go @@ -3,18 +3,18 @@ package main import ( "encoding/json" "errors" - "github.com/supertokens/supertokens-golang/recipe/dashboard" "net/http" "strings" + "github.com/supertokens/supertokens-golang/recipe/dashboard" + "github.com/labstack/echo/v4" "github.com/supertokens/supertokens-golang/recipe/emailverification" "github.com/supertokens/supertokens-golang/recipe/emailverification/evmodels" "github.com/supertokens/supertokens-golang/recipe/session" "github.com/supertokens/supertokens-golang/recipe/session/sessmodels" + "github.com/supertokens/supertokens-golang/recipe/thirdparty" "github.com/supertokens/supertokens-golang/recipe/thirdparty/tpmodels" - "github.com/supertokens/supertokens-golang/recipe/thirdpartyemailpassword" - "github.com/supertokens/supertokens-golang/recipe/thirdpartyemailpassword/tpepmodels" "github.com/supertokens/supertokens-golang/supertokens" ) @@ -32,7 +32,7 @@ func main() { emailverification.Init(evmodels.TypeInput{ Mode: evmodels.ModeRequired, }), - thirdpartyemailpassword.Init(&tpepmodels.TypeInput{ + thirdparty.Init(&tpmodels.TypeInput{ /* We use different credentials for different platforms when required. For example the redirect URI for Github is different for Web and mobile. In such a case we can provide multiple providers with different client Ids. @@ -41,110 +41,112 @@ func main() { request. In the absence of a clientId in the request the SDK uses the default provider, indicated by `isDefault: true`. When adding multiple providers for the same type (Google, Github etc), make sure to set `isDefault: true`. */ - Providers: []tpmodels.ProviderInput{ - // We have provided you with development keys which you can use for testsing. - // IMPORTANT: Please replace them with your own OAuth keys for production use. - { - Config: tpmodels.ProviderConfig{ - ThirdPartyId: "google", - Clients: []tpmodels.ProviderClientConfig{ - { - ClientType: "web", - ClientID: "1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com", - ClientSecret: "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", - }, - { - // we use this for mobile apps - ClientType: "mobile", - ClientID: "1060725074195-c7mgk8p0h27c4428prfuo3lg7ould5o7.apps.googleusercontent.com", - ClientSecret: "", // this is empty because we follow Authorization code grant flow via PKCE for mobile apps (Google doesn't issue a client secret for mobile apps). + SignInAndUpFeature: tpmodels.TypeInputSignInAndUp{ + Providers: []tpmodels.ProviderInput{ + // We have provided you with development keys which you can use for testsing. + // IMPORTANT: Please replace them with your own OAuth keys for production use. + { + Config: tpmodels.ProviderConfig{ + ThirdPartyId: "google", + Clients: []tpmodels.ProviderClientConfig{ + { + ClientType: "web", + ClientID: "1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com", + ClientSecret: "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", + }, + { + // we use this for mobile apps + ClientType: "mobile", + ClientID: "1060725074195-c7mgk8p0h27c4428prfuo3lg7ould5o7.apps.googleusercontent.com", + ClientSecret: "", // this is empty because we follow Authorization code grant flow via PKCE for mobile apps (Google doesn't issue a client secret for mobile apps). + }, }, }, }, - }, - { - Config: tpmodels.ProviderConfig{ - ThirdPartyId: "github", - Clients: []tpmodels.ProviderClientConfig{ - { - ClientType: "web", - ClientID: "467101b197249757c71f", - ClientSecret: "e97051221f4b6426e8fe8d51486396703012f5bd", - }, - { - // We use this for mobile apps - ClientType: "mobile", - ClientID: "8a9152860ce869b64c44", - ClientSecret: "00e841f10f288363cd3786b1b1f538f05cfdbda2", + { + Config: tpmodels.ProviderConfig{ + ThirdPartyId: "github", + Clients: []tpmodels.ProviderClientConfig{ + { + ClientType: "web", + ClientID: "467101b197249757c71f", + ClientSecret: "e97051221f4b6426e8fe8d51486396703012f5bd", + }, + { + // We use this for mobile apps + ClientType: "mobile", + ClientID: "8a9152860ce869b64c44", + ClientSecret: "00e841f10f288363cd3786b1b1f538f05cfdbda2", + }, }, }, }, - }, - /* - For Apple signin, iOS apps always use the bundle identifier as the client ID when communicating with Apple. Android, Web and other platforms - need to configure a Service ID on the Apple developer dashboard and use that as client ID. - In the example below 4398792-io.supertokens.example.service is the client ID for Web. Android etc and thus we mark it as default. For iOS - the frontend for the demo app sends the clientId in the request which is then used by the SDK. - */ - { - Config: tpmodels.ProviderConfig{ - ThirdPartyId: "apple", - Clients: []tpmodels.ProviderClientConfig{ - { - // For Android and website apps - ClientType: "web", - ClientID: "4398792-io.supertokens.example.service", - AdditionalConfig: map[string]interface{}{ - "keyId": "7M48Y4RYDL", - "privateKey": "-----BEGIN PRIVATE KEY-----\nMIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgu8gXs+XYkqXD6Ala9Sf/iJXzhbwcoG5dMh1OonpdJUmgCgYIKoZIzj0DAQehRANCAASfrvlFbFCYqn3I2zeknYXLwtH30JuOKestDbSfZYxZNMqhF/OzdZFTV0zc5u5s3eN+oCWbnvl0hM+9IW0UlkdA\n-----END PRIVATE KEY-----", - "teamId": "YWQCXGJRJL", + /* + For Apple signin, iOS apps always use the bundle identifier as the client ID when communicating with Apple. Android, Web and other platforms + need to configure a Service ID on the Apple developer dashboard and use that as client ID. + In the example below 4398792-io.supertokens.example.service is the client ID for Web. Android etc and thus we mark it as default. For iOS + the frontend for the demo app sends the clientId in the request which is then used by the SDK. + */ + { + Config: tpmodels.ProviderConfig{ + ThirdPartyId: "apple", + Clients: []tpmodels.ProviderClientConfig{ + { + // For Android and website apps + ClientType: "web", + ClientID: "4398792-io.supertokens.example.service", + AdditionalConfig: map[string]interface{}{ + "keyId": "7M48Y4RYDL", + "privateKey": "-----BEGIN PRIVATE KEY-----\nMIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgu8gXs+XYkqXD6Ala9Sf/iJXzhbwcoG5dMh1OonpdJUmgCgYIKoZIzj0DAQehRANCAASfrvlFbFCYqn3I2zeknYXLwtH30JuOKestDbSfZYxZNMqhF/OzdZFTV0zc5u5s3eN+oCWbnvl0hM+9IW0UlkdA\n-----END PRIVATE KEY-----", + "teamId": "YWQCXGJRJL", + }, }, - }, - { - // For iOS Apps - ClientType: "ios", - ClientID: "4398792-io.supertokens.example", - AdditionalConfig: map[string]interface{}{ - "keyId": "7M48Y4RYDL", - "privateKey": "-----BEGIN PRIVATE KEY-----\nMIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgu8gXs+XYkqXD6Ala9Sf/iJXzhbwcoG5dMh1OonpdJUmgCgYIKoZIzj0DAQehRANCAASfrvlFbFCYqn3I2zeknYXLwtH30JuOKestDbSfZYxZNMqhF/OzdZFTV0zc5u5s3eN+oCWbnvl0hM+9IW0UlkdA\n-----END PRIVATE KEY-----", - "teamId": "YWQCXGJRJL", + { + // For iOS Apps + ClientType: "ios", + ClientID: "4398792-io.supertokens.example", + AdditionalConfig: map[string]interface{}{ + "keyId": "7M48Y4RYDL", + "privateKey": "-----BEGIN PRIVATE KEY-----\nMIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgu8gXs+XYkqXD6Ala9Sf/iJXzhbwcoG5dMh1OonpdJUmgCgYIKoZIzj0DAQehRANCAASfrvlFbFCYqn3I2zeknYXLwtH30JuOKestDbSfZYxZNMqhF/OzdZFTV0zc5u5s3eN+oCWbnvl0hM+9IW0UlkdA\n-----END PRIVATE KEY-----", + "teamId": "YWQCXGJRJL", + }, }, }, }, }, - }, - { - Config: tpmodels.ProviderConfig{ - ThirdPartyId: "discord", - Clients: []tpmodels.ProviderClientConfig{ - { - ClientType: "web", - ClientID: "4398792-907871294886928395", - ClientSecret: "His4yXGEovVp5TZkZhEAt0ZXGh8uOVDm", - }, - { - // We use this for mobile apps - ClientType: "mobile", - ClientID: "4398792-907871294886928395", - ClientSecret: "His4yXGEovVp5TZkZhEAt0ZXGh8uOVDm", + { + Config: tpmodels.ProviderConfig{ + ThirdPartyId: "discord", + Clients: []tpmodels.ProviderClientConfig{ + { + ClientType: "web", + ClientID: "4398792-907871294886928395", + ClientSecret: "His4yXGEovVp5TZkZhEAt0ZXGh8uOVDm", + }, + { + // We use this for mobile apps + ClientType: "mobile", + ClientID: "4398792-907871294886928395", + ClientSecret: "His4yXGEovVp5TZkZhEAt0ZXGh8uOVDm", + }, }, }, }, - }, - { - Config: tpmodels.ProviderConfig{ - ThirdPartyId: "google-workspaces", - Clients: []tpmodels.ProviderClientConfig{ - { - ClientType: "web", - ClientID: "1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com", - ClientSecret: "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", - }, - { - // We use this for mobile apps - ClientType: "mobile", - ClientID: "1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com", - ClientSecret: "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", + { + Config: tpmodels.ProviderConfig{ + ThirdPartyId: "google-workspaces", + Clients: []tpmodels.ProviderClientConfig{ + { + ClientType: "web", + ClientID: "1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com", + ClientSecret: "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", + }, + { + // We use this for mobile apps + ClientType: "mobile", + ClientID: "1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com", + ClientSecret: "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", + }, }, }, }, diff --git a/examples/with-mux/main.go b/examples/with-mux/main.go index c388e022..b79fee89 100644 --- a/examples/with-mux/main.go +++ b/examples/with-mux/main.go @@ -2,17 +2,17 @@ package main import ( "encoding/json" - "github.com/supertokens/supertokens-golang/recipe/dashboard" "net/http" + "github.com/supertokens/supertokens-golang/recipe/dashboard" + "github.com/gorilla/handlers" "github.com/gorilla/mux" "github.com/supertokens/supertokens-golang/recipe/emailverification" "github.com/supertokens/supertokens-golang/recipe/emailverification/evmodels" "github.com/supertokens/supertokens-golang/recipe/session" + "github.com/supertokens/supertokens-golang/recipe/thirdparty" "github.com/supertokens/supertokens-golang/recipe/thirdparty/tpmodels" - "github.com/supertokens/supertokens-golang/recipe/thirdpartyemailpassword" - "github.com/supertokens/supertokens-golang/recipe/thirdpartyemailpassword/tpepmodels" "github.com/supertokens/supertokens-golang/supertokens" ) @@ -30,7 +30,7 @@ func main() { emailverification.Init(evmodels.TypeInput{ Mode: evmodels.ModeRequired, }), - thirdpartyemailpassword.Init(&tpepmodels.TypeInput{ + thirdparty.Init(&tpmodels.TypeInput{ /* We use different credentials for different platforms when required. For example the redirect URI for Github is different for Web and mobile. In such a case we can provide multiple providers with different client Ids. @@ -39,110 +39,112 @@ func main() { request. In the absence of a clientId in the request the SDK uses the default provider, indicated by `isDefault: true`. When adding multiple providers for the same type (Google, Github etc), make sure to set `isDefault: true`. */ - Providers: []tpmodels.ProviderInput{ - // We have provided you with development keys which you can use for testsing. - // IMPORTANT: Please replace them with your own OAuth keys for production use. - { - Config: tpmodels.ProviderConfig{ - ThirdPartyId: "google", - Clients: []tpmodels.ProviderClientConfig{ - { - ClientType: "web", - ClientID: "1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com", - ClientSecret: "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", - }, - { - // we use this for mobile apps - ClientType: "mobile", - ClientID: "1060725074195-c7mgk8p0h27c4428prfuo3lg7ould5o7.apps.googleusercontent.com", - ClientSecret: "", // this is empty because we follow Authorization code grant flow via PKCE for mobile apps (Google doesn't issue a client secret for mobile apps). + SignInAndUpFeature: tpmodels.TypeInputSignInAndUp{ + Providers: []tpmodels.ProviderInput{ + // We have provided you with development keys which you can use for testsing. + // IMPORTANT: Please replace them with your own OAuth keys for production use. + { + Config: tpmodels.ProviderConfig{ + ThirdPartyId: "google", + Clients: []tpmodels.ProviderClientConfig{ + { + ClientType: "web", + ClientID: "1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com", + ClientSecret: "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", + }, + { + // we use this for mobile apps + ClientType: "mobile", + ClientID: "1060725074195-c7mgk8p0h27c4428prfuo3lg7ould5o7.apps.googleusercontent.com", + ClientSecret: "", // this is empty because we follow Authorization code grant flow via PKCE for mobile apps (Google doesn't issue a client secret for mobile apps). + }, }, }, }, - }, - { - Config: tpmodels.ProviderConfig{ - ThirdPartyId: "github", - Clients: []tpmodels.ProviderClientConfig{ - { - ClientType: "web", - ClientID: "467101b197249757c71f", - ClientSecret: "e97051221f4b6426e8fe8d51486396703012f5bd", - }, - { - // We use this for mobile apps - ClientType: "mobile", - ClientID: "8a9152860ce869b64c44", - ClientSecret: "00e841f10f288363cd3786b1b1f538f05cfdbda2", + { + Config: tpmodels.ProviderConfig{ + ThirdPartyId: "github", + Clients: []tpmodels.ProviderClientConfig{ + { + ClientType: "web", + ClientID: "467101b197249757c71f", + ClientSecret: "e97051221f4b6426e8fe8d51486396703012f5bd", + }, + { + // We use this for mobile apps + ClientType: "mobile", + ClientID: "8a9152860ce869b64c44", + ClientSecret: "00e841f10f288363cd3786b1b1f538f05cfdbda2", + }, }, }, }, - }, - /* - For Apple signin, iOS apps always use the bundle identifier as the client ID when communicating with Apple. Android, Web and other platforms - need to configure a Service ID on the Apple developer dashboard and use that as client ID. - In the example below 4398792-io.supertokens.example.service is the client ID for Web. Android etc and thus we mark it as default. For iOS - the frontend for the demo app sends the clientId in the request which is then used by the SDK. - */ - { - Config: tpmodels.ProviderConfig{ - ThirdPartyId: "apple", - Clients: []tpmodels.ProviderClientConfig{ - { - // For Android and website apps - ClientType: "web", - ClientID: "4398792-io.supertokens.example.service", - AdditionalConfig: map[string]interface{}{ - "keyId": "7M48Y4RYDL", - "privateKey": "-----BEGIN PRIVATE KEY-----\nMIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgu8gXs+XYkqXD6Ala9Sf/iJXzhbwcoG5dMh1OonpdJUmgCgYIKoZIzj0DAQehRANCAASfrvlFbFCYqn3I2zeknYXLwtH30JuOKestDbSfZYxZNMqhF/OzdZFTV0zc5u5s3eN+oCWbnvl0hM+9IW0UlkdA\n-----END PRIVATE KEY-----", - "teamId": "YWQCXGJRJL", + /* + For Apple signin, iOS apps always use the bundle identifier as the client ID when communicating with Apple. Android, Web and other platforms + need to configure a Service ID on the Apple developer dashboard and use that as client ID. + In the example below 4398792-io.supertokens.example.service is the client ID for Web. Android etc and thus we mark it as default. For iOS + the frontend for the demo app sends the clientId in the request which is then used by the SDK. + */ + { + Config: tpmodels.ProviderConfig{ + ThirdPartyId: "apple", + Clients: []tpmodels.ProviderClientConfig{ + { + // For Android and website apps + ClientType: "web", + ClientID: "4398792-io.supertokens.example.service", + AdditionalConfig: map[string]interface{}{ + "keyId": "7M48Y4RYDL", + "privateKey": "-----BEGIN PRIVATE KEY-----\nMIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgu8gXs+XYkqXD6Ala9Sf/iJXzhbwcoG5dMh1OonpdJUmgCgYIKoZIzj0DAQehRANCAASfrvlFbFCYqn3I2zeknYXLwtH30JuOKestDbSfZYxZNMqhF/OzdZFTV0zc5u5s3eN+oCWbnvl0hM+9IW0UlkdA\n-----END PRIVATE KEY-----", + "teamId": "YWQCXGJRJL", + }, }, - }, - { - // For iOS Apps - ClientType: "ios", - ClientID: "4398792-io.supertokens.example", - AdditionalConfig: map[string]interface{}{ - "keyId": "7M48Y4RYDL", - "privateKey": "-----BEGIN PRIVATE KEY-----\nMIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgu8gXs+XYkqXD6Ala9Sf/iJXzhbwcoG5dMh1OonpdJUmgCgYIKoZIzj0DAQehRANCAASfrvlFbFCYqn3I2zeknYXLwtH30JuOKestDbSfZYxZNMqhF/OzdZFTV0zc5u5s3eN+oCWbnvl0hM+9IW0UlkdA\n-----END PRIVATE KEY-----", - "teamId": "YWQCXGJRJL", + { + // For iOS Apps + ClientType: "ios", + ClientID: "4398792-io.supertokens.example", + AdditionalConfig: map[string]interface{}{ + "keyId": "7M48Y4RYDL", + "privateKey": "-----BEGIN PRIVATE KEY-----\nMIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgu8gXs+XYkqXD6Ala9Sf/iJXzhbwcoG5dMh1OonpdJUmgCgYIKoZIzj0DAQehRANCAASfrvlFbFCYqn3I2zeknYXLwtH30JuOKestDbSfZYxZNMqhF/OzdZFTV0zc5u5s3eN+oCWbnvl0hM+9IW0UlkdA\n-----END PRIVATE KEY-----", + "teamId": "YWQCXGJRJL", + }, }, }, }, }, - }, - { - Config: tpmodels.ProviderConfig{ - ThirdPartyId: "discord", - Clients: []tpmodels.ProviderClientConfig{ - { - ClientType: "web", - ClientID: "4398792-907871294886928395", - ClientSecret: "His4yXGEovVp5TZkZhEAt0ZXGh8uOVDm", - }, - { - // We use this for mobile apps - ClientType: "mobile", - ClientID: "4398792-907871294886928395", - ClientSecret: "His4yXGEovVp5TZkZhEAt0ZXGh8uOVDm", + { + Config: tpmodels.ProviderConfig{ + ThirdPartyId: "discord", + Clients: []tpmodels.ProviderClientConfig{ + { + ClientType: "web", + ClientID: "4398792-907871294886928395", + ClientSecret: "His4yXGEovVp5TZkZhEAt0ZXGh8uOVDm", + }, + { + // We use this for mobile apps + ClientType: "mobile", + ClientID: "4398792-907871294886928395", + ClientSecret: "His4yXGEovVp5TZkZhEAt0ZXGh8uOVDm", + }, }, }, }, - }, - { - Config: tpmodels.ProviderConfig{ - ThirdPartyId: "google-workspaces", - Clients: []tpmodels.ProviderClientConfig{ - { - ClientType: "web", - ClientID: "1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com", - ClientSecret: "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", - }, - { - // We use this for mobile apps - ClientType: "mobile", - ClientID: "1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com", - ClientSecret: "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", + { + Config: tpmodels.ProviderConfig{ + ThirdPartyId: "google-workspaces", + Clients: []tpmodels.ProviderClientConfig{ + { + ClientType: "web", + ClientID: "1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com", + ClientSecret: "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", + }, + { + // We use this for mobile apps + ClientType: "mobile", + ClientID: "1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com", + ClientSecret: "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", + }, }, }, }, diff --git a/examples/with-twirp/cmd/server/main.go b/examples/with-twirp/cmd/server/main.go index 0c27b65a..8f59037a 100644 --- a/examples/with-twirp/cmd/server/main.go +++ b/examples/with-twirp/cmd/server/main.go @@ -14,11 +14,12 @@ package main import ( - "github.com/supertokens/supertokens-golang/recipe/dashboard" "log" "net/http" "os" + "github.com/supertokens/supertokens-golang/recipe/dashboard" + "github.com/gorilla/handlers" "github.com/supertokens/supertokens-golang/examples/with-twirp/haberdasher" "github.com/supertokens/supertokens-golang/examples/with-twirp/internal/haberdasherserver" @@ -28,9 +29,8 @@ import ( "github.com/supertokens/supertokens-golang/recipe/emailverification/evmodels" "github.com/supertokens/supertokens-golang/recipe/session" "github.com/supertokens/supertokens-golang/recipe/session/sessmodels" + "github.com/supertokens/supertokens-golang/recipe/thirdparty" "github.com/supertokens/supertokens-golang/recipe/thirdparty/tpmodels" - "github.com/supertokens/supertokens-golang/recipe/thirdpartyemailpassword" - "github.com/supertokens/supertokens-golang/recipe/thirdpartyemailpassword/tpepmodels" "github.com/supertokens/supertokens-golang/supertokens" "github.com/twitchtv/twirp" ) @@ -49,7 +49,7 @@ func main() { emailverification.Init(evmodels.TypeInput{ Mode: evmodels.ModeRequired, }), - thirdpartyemailpassword.Init(&tpepmodels.TypeInput{ + thirdparty.Init(&tpmodels.TypeInput{ /* We use different credentials for different platforms when required. For example the redirect URI for Github is different for Web and mobile. In such a case we can provide multiple providers with different client Ids. @@ -58,110 +58,112 @@ func main() { request. In the absence of a clientId in the request the SDK uses the default provider, indicated by `isDefault: true`. When adding multiple providers for the same type (Google, Github etc), make sure to set `isDefault: true`. */ - Providers: []tpmodels.ProviderInput{ - // We have provided you with development keys which you can use for testsing. - // IMPORTANT: Please replace them with your own OAuth keys for production use. - { - Config: tpmodels.ProviderConfig{ - ThirdPartyId: "google", - Clients: []tpmodels.ProviderClientConfig{ - { - ClientType: "web", - ClientID: "1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com", - ClientSecret: "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", - }, - { - // we use this for mobile apps - ClientType: "mobile", - ClientID: "1060725074195-c7mgk8p0h27c4428prfuo3lg7ould5o7.apps.googleusercontent.com", - ClientSecret: "", // this is empty because we follow Authorization code grant flow via PKCE for mobile apps (Google doesn't issue a client secret for mobile apps). + SignInAndUpFeature: tpmodels.TypeInputSignInAndUp{ + Providers: []tpmodels.ProviderInput{ + // We have provided you with development keys which you can use for testsing. + // IMPORTANT: Please replace them with your own OAuth keys for production use. + { + Config: tpmodels.ProviderConfig{ + ThirdPartyId: "google", + Clients: []tpmodels.ProviderClientConfig{ + { + ClientType: "web", + ClientID: "1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com", + ClientSecret: "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", + }, + { + // we use this for mobile apps + ClientType: "mobile", + ClientID: "1060725074195-c7mgk8p0h27c4428prfuo3lg7ould5o7.apps.googleusercontent.com", + ClientSecret: "", // this is empty because we follow Authorization code grant flow via PKCE for mobile apps (Google doesn't issue a client secret for mobile apps). + }, }, }, }, - }, - { - Config: tpmodels.ProviderConfig{ - ThirdPartyId: "github", - Clients: []tpmodels.ProviderClientConfig{ - { - ClientType: "web", - ClientID: "467101b197249757c71f", - ClientSecret: "e97051221f4b6426e8fe8d51486396703012f5bd", - }, - { - // We use this for mobile apps - ClientType: "mobile", - ClientID: "8a9152860ce869b64c44", - ClientSecret: "00e841f10f288363cd3786b1b1f538f05cfdbda2", + { + Config: tpmodels.ProviderConfig{ + ThirdPartyId: "github", + Clients: []tpmodels.ProviderClientConfig{ + { + ClientType: "web", + ClientID: "467101b197249757c71f", + ClientSecret: "e97051221f4b6426e8fe8d51486396703012f5bd", + }, + { + // We use this for mobile apps + ClientType: "mobile", + ClientID: "8a9152860ce869b64c44", + ClientSecret: "00e841f10f288363cd3786b1b1f538f05cfdbda2", + }, }, }, }, - }, - /* - For Apple signin, iOS apps always use the bundle identifier as the client ID when communicating with Apple. Android, Web and other platforms - need to configure a Service ID on the Apple developer dashboard and use that as client ID. - In the example below 4398792-io.supertokens.example.service is the client ID for Web. Android etc and thus we mark it as default. For iOS - the frontend for the demo app sends the clientId in the request which is then used by the SDK. - */ - { - Config: tpmodels.ProviderConfig{ - ThirdPartyId: "apple", - Clients: []tpmodels.ProviderClientConfig{ - { - // For Android and website apps - ClientType: "web", - ClientID: "4398792-io.supertokens.example.service", - AdditionalConfig: map[string]interface{}{ - "keyId": "7M48Y4RYDL", - "privateKey": "-----BEGIN PRIVATE KEY-----\nMIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgu8gXs+XYkqXD6Ala9Sf/iJXzhbwcoG5dMh1OonpdJUmgCgYIKoZIzj0DAQehRANCAASfrvlFbFCYqn3I2zeknYXLwtH30JuOKestDbSfZYxZNMqhF/OzdZFTV0zc5u5s3eN+oCWbnvl0hM+9IW0UlkdA\n-----END PRIVATE KEY-----", - "teamId": "YWQCXGJRJL", + /* + For Apple signin, iOS apps always use the bundle identifier as the client ID when communicating with Apple. Android, Web and other platforms + need to configure a Service ID on the Apple developer dashboard and use that as client ID. + In the example below 4398792-io.supertokens.example.service is the client ID for Web. Android etc and thus we mark it as default. For iOS + the frontend for the demo app sends the clientId in the request which is then used by the SDK. + */ + { + Config: tpmodels.ProviderConfig{ + ThirdPartyId: "apple", + Clients: []tpmodels.ProviderClientConfig{ + { + // For Android and website apps + ClientType: "web", + ClientID: "4398792-io.supertokens.example.service", + AdditionalConfig: map[string]interface{}{ + "keyId": "7M48Y4RYDL", + "privateKey": "-----BEGIN PRIVATE KEY-----\nMIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgu8gXs+XYkqXD6Ala9Sf/iJXzhbwcoG5dMh1OonpdJUmgCgYIKoZIzj0DAQehRANCAASfrvlFbFCYqn3I2zeknYXLwtH30JuOKestDbSfZYxZNMqhF/OzdZFTV0zc5u5s3eN+oCWbnvl0hM+9IW0UlkdA\n-----END PRIVATE KEY-----", + "teamId": "YWQCXGJRJL", + }, }, - }, - { - // For iOS Apps - ClientType: "ios", - ClientID: "4398792-io.supertokens.example", - AdditionalConfig: map[string]interface{}{ - "keyId": "7M48Y4RYDL", - "privateKey": "-----BEGIN PRIVATE KEY-----\nMIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgu8gXs+XYkqXD6Ala9Sf/iJXzhbwcoG5dMh1OonpdJUmgCgYIKoZIzj0DAQehRANCAASfrvlFbFCYqn3I2zeknYXLwtH30JuOKestDbSfZYxZNMqhF/OzdZFTV0zc5u5s3eN+oCWbnvl0hM+9IW0UlkdA\n-----END PRIVATE KEY-----", - "teamId": "YWQCXGJRJL", + { + // For iOS Apps + ClientType: "ios", + ClientID: "4398792-io.supertokens.example", + AdditionalConfig: map[string]interface{}{ + "keyId": "7M48Y4RYDL", + "privateKey": "-----BEGIN PRIVATE KEY-----\nMIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgu8gXs+XYkqXD6Ala9Sf/iJXzhbwcoG5dMh1OonpdJUmgCgYIKoZIzj0DAQehRANCAASfrvlFbFCYqn3I2zeknYXLwtH30JuOKestDbSfZYxZNMqhF/OzdZFTV0zc5u5s3eN+oCWbnvl0hM+9IW0UlkdA\n-----END PRIVATE KEY-----", + "teamId": "YWQCXGJRJL", + }, }, }, }, }, - }, - { - Config: tpmodels.ProviderConfig{ - ThirdPartyId: "discord", - Clients: []tpmodels.ProviderClientConfig{ - { - ClientType: "web", - ClientID: "4398792-907871294886928395", - ClientSecret: "His4yXGEovVp5TZkZhEAt0ZXGh8uOVDm", - }, - { - // We use this for mobile apps - ClientType: "mobile", - ClientID: "4398792-907871294886928395", - ClientSecret: "His4yXGEovVp5TZkZhEAt0ZXGh8uOVDm", + { + Config: tpmodels.ProviderConfig{ + ThirdPartyId: "discord", + Clients: []tpmodels.ProviderClientConfig{ + { + ClientType: "web", + ClientID: "4398792-907871294886928395", + ClientSecret: "His4yXGEovVp5TZkZhEAt0ZXGh8uOVDm", + }, + { + // We use this for mobile apps + ClientType: "mobile", + ClientID: "4398792-907871294886928395", + ClientSecret: "His4yXGEovVp5TZkZhEAt0ZXGh8uOVDm", + }, }, }, }, - }, - { - Config: tpmodels.ProviderConfig{ - ThirdPartyId: "google-workspaces", - Clients: []tpmodels.ProviderClientConfig{ - { - ClientType: "web", - ClientID: "1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com", - ClientSecret: "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", - }, - { - // We use this for mobile apps - ClientType: "mobile", - ClientID: "1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com", - ClientSecret: "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", + { + Config: tpmodels.ProviderConfig{ + ThirdPartyId: "google-workspaces", + Clients: []tpmodels.ProviderClientConfig{ + { + ClientType: "web", + ClientID: "1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com", + ClientSecret: "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", + }, + { + // We use this for mobile apps + ClientType: "mobile", + ClientID: "1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com", + ClientSecret: "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", + }, }, }, },