From 957f7eb941666f334863d6017bc9d775626420fb Mon Sep 17 00:00:00 2001 From: rishabhpoddar Date: Wed, 10 Apr 2024 17:34:23 +0530 Subject: [PATCH] removes tpep recipe entirely --- recipe/dashboard/api/userdetails/userPut.go | 115 ----- recipe/dashboard/api/utils.go | 66 --- recipe/dashboard/userGet_test.go | 43 +- .../api/implementation.go | 168 ------- .../api/passwordlessAPIImplementation.go | 78 ---- .../api/thirdPartyAPIImplementation.go | 78 ---- .../backwardCompatibilityService/main.go | 42 -- .../emaildelivery/smtpService/main.go | 51 --- .../smtpService/plessServiceImplementation.go | 39 -- .../smtpService/serviceImplementation.go | 47 -- recipe/thirdpartypasswordless/main.go | 415 ----------------- recipe/thirdpartypasswordless/recipe.go | 223 ---------- .../recipeimplementation/main.go | 420 ------------------ .../passwordlessRecipeImplementation.go | 191 -------- .../thirdPartyRecipeImplementation.go | 140 ------ .../backwardCompatibilityService/main.go | 42 -- .../smsdelivery/supertokensService/main.go | 35 -- .../smsdelivery/twilioService/main.go | 39 -- recipe/thirdpartypasswordless/testingUtils.go | 295 ------------ .../tplmodels/apiInterface.go | 65 --- .../tplmodels/models.go | 70 --- .../tplmodels/recipeInterface.go | 92 ---- recipe/thirdpartypasswordless/utils.go | 93 ---- test/auth-react-server/main.go | 203 +++++---- 24 files changed, 137 insertions(+), 2913 deletions(-) delete mode 100644 recipe/thirdpartypasswordless/api/implementation.go delete mode 100644 recipe/thirdpartypasswordless/api/passwordlessAPIImplementation.go delete mode 100644 recipe/thirdpartypasswordless/api/thirdPartyAPIImplementation.go delete mode 100644 recipe/thirdpartypasswordless/emaildelivery/backwardCompatibilityService/main.go delete mode 100644 recipe/thirdpartypasswordless/emaildelivery/smtpService/main.go delete mode 100644 recipe/thirdpartypasswordless/emaildelivery/smtpService/plessServiceImplementation.go delete mode 100644 recipe/thirdpartypasswordless/emaildelivery/smtpService/serviceImplementation.go delete mode 100644 recipe/thirdpartypasswordless/main.go delete mode 100644 recipe/thirdpartypasswordless/recipe.go delete mode 100644 recipe/thirdpartypasswordless/recipeimplementation/main.go delete mode 100644 recipe/thirdpartypasswordless/recipeimplementation/passwordlessRecipeImplementation.go delete mode 100644 recipe/thirdpartypasswordless/recipeimplementation/thirdPartyRecipeImplementation.go delete mode 100644 recipe/thirdpartypasswordless/smsdelivery/backwardCompatibilityService/main.go delete mode 100644 recipe/thirdpartypasswordless/smsdelivery/supertokensService/main.go delete mode 100644 recipe/thirdpartypasswordless/smsdelivery/twilioService/main.go delete mode 100644 recipe/thirdpartypasswordless/testingUtils.go delete mode 100644 recipe/thirdpartypasswordless/tplmodels/apiInterface.go delete mode 100644 recipe/thirdpartypasswordless/tplmodels/models.go delete mode 100644 recipe/thirdpartypasswordless/tplmodels/recipeInterface.go delete mode 100644 recipe/thirdpartypasswordless/utils.go diff --git a/recipe/dashboard/api/userdetails/userPut.go b/recipe/dashboard/api/userdetails/userPut.go index 4320f06c..431461bc 100644 --- a/recipe/dashboard/api/userdetails/userPut.go +++ b/recipe/dashboard/api/userdetails/userPut.go @@ -25,7 +25,6 @@ import ( "github.com/supertokens/supertokens-golang/recipe/emailpassword" "github.com/supertokens/supertokens-golang/recipe/emailpassword/epmodels" "github.com/supertokens/supertokens-golang/recipe/passwordless" - "github.com/supertokens/supertokens-golang/recipe/thirdpartypasswordless" "github.com/supertokens/supertokens-golang/recipe/usermetadata" "github.com/supertokens/supertokens-golang/supertokens" ) @@ -151,63 +150,6 @@ func updateEmailForRecipeId(recipeId string, userId string, email string, tenant }, nil } - if recipeId == "thirdpartypasswordless" { - isValidEmail := true - validationError := "" - - passwordlessConfig := thirdpartypasswordless.GetRecipeInstance().Config - - if passwordlessConfig.ContactMethodPhone.Enabled { - validationResult := passwordless.DefaultValidateEmailAddress(email, tenantId) - - if validationResult != nil { - isValidEmail = false - validationError = *validationResult - } - } else if passwordlessConfig.ContactMethodEmail.Enabled { - validationResult := passwordlessConfig.ContactMethodEmail.ValidateEmailAddress(email, tenantId) - - if validationResult != nil { - isValidEmail = false - validationError = *validationResult - } - } else { - validationResult := passwordlessConfig.ContactMethodEmailOrPhone.ValidateEmailAddress(email, tenantId) - - if validationResult != nil { - isValidEmail = false - validationError = *validationResult - } - } - - if !isValidEmail { - return updateEmailResponse{ - Status: "INVALID_EMAIL_ERROR", - Error: validationError, - }, nil - } - - updateResponse, updateErr := thirdpartypasswordless.UpdatePasswordlessUser(userId, &email, nil, userContext) - - if updateErr != nil { - return updateEmailResponse{}, updateErr - } - - if updateResponse.UnknownUserIdError != nil { - return updateEmailResponse{}, errors.New("Should never come here") - } - - if updateResponse.EmailAlreadyExistsError != nil { - return updateEmailResponse{ - Status: "EMAIL_ALREADY_EXISTS_ERROR", - }, nil - } - - return updateEmailResponse{ - Status: "OK", - }, nil - } - return updateEmailResponse{}, errors.New("Should never come here") } @@ -269,63 +211,6 @@ func updatePhoneForRecipeId(recipeId string, userId string, phone string, tenant }, nil } - if recipeId == "thirdpartypasswordless" { - isValidPhone := true - validationError := "" - - passwordlessConfig := thirdpartypasswordless.GetRecipeInstance().Config - - if passwordlessConfig.ContactMethodEmail.Enabled { - validationResult := passwordless.DefaultValidatePhoneNumber(phone, tenantId) - - if validationResult != nil { - isValidPhone = false - validationError = *validationResult - } - } else if passwordlessConfig.ContactMethodPhone.Enabled { - validationResult := passwordlessConfig.ContactMethodPhone.ValidatePhoneNumber(phone, tenantId) - - if validationResult != nil { - isValidPhone = false - validationError = *validationResult - } - } else { - validationResult := passwordlessConfig.ContactMethodEmailOrPhone.ValidatePhoneNumber(phone, tenantId) - - if validationResult != nil { - isValidPhone = false - validationError = *validationResult - } - } - - if !isValidPhone { - return updatePhoneResponse{ - Status: "INVALID_PHONE_ERROR", - Error: validationError, - }, nil - } - - updateResponse, updateErr := thirdpartypasswordless.UpdatePasswordlessUser(userId, nil, &phone, userContext) - - if updateErr != nil { - return updatePhoneResponse{}, updateErr - } - - if updateResponse.UnknownUserIdError != nil { - return updatePhoneResponse{}, errors.New("Should never come here") - } - - if updateResponse.EmailAlreadyExistsError != nil { - return updatePhoneResponse{ - Status: "PHONE_ALREADY_EXISTS_ERROR", - }, nil - } - - return updatePhoneResponse{ - Status: "OK", - }, nil - } - /** * If it comes here then the user is a not a passwordless user in which case the UI should not have allowed this */ diff --git a/recipe/dashboard/api/utils.go b/recipe/dashboard/api/utils.go index 5490a2bc..d20846ca 100644 --- a/recipe/dashboard/api/utils.go +++ b/recipe/dashboard/api/utils.go @@ -1,13 +1,10 @@ package api import ( - "reflect" - "github.com/supertokens/supertokens-golang/recipe/dashboard/dashboardmodels" "github.com/supertokens/supertokens-golang/recipe/emailpassword" "github.com/supertokens/supertokens-golang/recipe/passwordless" "github.com/supertokens/supertokens-golang/recipe/thirdparty" - "github.com/supertokens/supertokens-golang/recipe/thirdpartypasswordless" "github.com/supertokens/supertokens-golang/supertokens" ) @@ -44,7 +41,6 @@ func GetUserForRecipeId(userId string, recipeId string, userContext supertokens. } } else if recipeId == thirdparty.RECIPE_ID { response, error := thirdparty.GetUserByID(userId, userContext) - if error == nil && response != nil { userToReturn.Id = response.ID userToReturn.TimeJoined = response.TimeJoined @@ -57,31 +53,6 @@ func GetUserForRecipeId(userId string, recipeId string, userContext supertokens. } userToReturn.TenantIds = response.TenantIds } - - if reflect.DeepEqual(userToReturn, dashboardmodels.UserType{}) { - tpplessResponse, tpplessError := thirdpartypasswordless.GetUserById(userId, userContext) - - if tpplessError == nil && tpplessResponse != nil { - userToReturn.Id = tpplessResponse.ID - userToReturn.TimeJoined = tpplessResponse.TimeJoined - userToReturn.FirstName = "" - userToReturn.LastName = "" - - if tpplessResponse.Email != nil { - userToReturn.Email = *tpplessResponse.Email - } - - if tpplessResponse.PhoneNumber != nil { - userToReturn.Phone = *tpplessResponse.PhoneNumber - } - - userToReturn.ThirdParty = &dashboardmodels.ThirdParty{ - Id: tpplessResponse.ThirdParty.ID, - UserId: tpplessResponse.ThirdParty.UserID, - } - userToReturn.TenantIds = tpplessResponse.TenantIds - } - } } else if recipeId == passwordless.RECIPE_ID { response, error := passwordless.GetUserByID(userId, userContext) @@ -101,27 +72,6 @@ func GetUserForRecipeId(userId string, recipeId string, userContext supertokens. userToReturn.TenantIds = response.TenantIds } - - if reflect.DeepEqual(userToReturn, dashboardmodels.UserType{}) { - tppResponse, tppError := thirdpartypasswordless.GetUserByID(userId, userContext) - - if tppError == nil && tppResponse != nil { - userToReturn.Id = tppResponse.ID - userToReturn.TimeJoined = tppResponse.TimeJoined - userToReturn.FirstName = "" - userToReturn.LastName = "" - - if tppResponse.Email != nil { - userToReturn.Email = *tppResponse.Email - } - - if tppResponse.PhoneNumber != nil { - userToReturn.Phone = *tppResponse.PhoneNumber - } - - userToReturn.TenantIds = tppResponse.TenantIds - } - } } return userToReturn, recipeToReturn @@ -142,28 +92,12 @@ func IsRecipeInitialised(recipeId string) bool { if err == nil { isRecipeInitialised = true } - - if !isRecipeInitialised { - _, err := thirdpartypasswordless.GetRecipeInstanceOrThrowError() - - if err == nil { - isRecipeInitialised = true - } - } } else if recipeId == thirdparty.RECIPE_ID { _, err := thirdparty.GetRecipeInstanceOrThrowError() if err == nil { isRecipeInitialised = true } - - if !isRecipeInitialised { - _, err := thirdpartypasswordless.GetRecipeInstanceOrThrowError() - - if err == nil { - isRecipeInitialised = true - } - } } return isRecipeInitialised diff --git a/recipe/dashboard/userGet_test.go b/recipe/dashboard/userGet_test.go index 7f6b8b5c..c50dc010 100644 --- a/recipe/dashboard/userGet_test.go +++ b/recipe/dashboard/userGet_test.go @@ -11,11 +11,11 @@ import ( "github.com/supertokens/supertokens-golang/recipe/dashboard/api" "github.com/supertokens/supertokens-golang/recipe/dashboard/api/userdetails" "github.com/supertokens/supertokens-golang/recipe/emailpassword" + "github.com/supertokens/supertokens-golang/recipe/passwordless" "github.com/supertokens/supertokens-golang/recipe/passwordless/plessmodels" "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/thirdpartypasswordless" - "github.com/supertokens/supertokens-golang/recipe/thirdpartypasswordless/tplmodels" "github.com/stretchr/testify/assert" "github.com/supertokens/supertokens-golang/recipe/dashboard/dashboardmodels" @@ -85,6 +85,33 @@ func TestThatUserGetReturnsTenantIDsCorrectly(t *testing.T) { assert.Equal(t, response.User.TenantIds[0], "public") } +var customProvider1 = tpmodels.ProviderInput{ + Config: tpmodels.ProviderConfig{ + ThirdPartyId: "custom", + AuthorizationEndpoint: "https://test.com/oauth/auth", + TokenEndpoint: "https://test.com/oauth/token", + + Clients: []tpmodels.ProviderClientConfig{ + { + ClientID: "supertokens", + }, + }, + }, + + Override: func(originalImplementation *tpmodels.TypeProvider) *tpmodels.TypeProvider { + originalImplementation.GetUserInfo = func(oAuthTokens tpmodels.TypeOAuthTokens, userContext supertokens.UserContext) (tpmodels.TypeUserInfo, error) { + return tpmodels.TypeUserInfo{ + ThirdPartyUserId: "user", + Email: &tpmodels.EmailStruct{ + ID: "email@test.com", + IsVerified: true, + }, + }, nil + } + return originalImplementation + }, +} + func TestThatUserGetReturnsValidUserForThirdPartyUserWhenUsingThirdPartyPasswordless(t *testing.T) { config := supertokens.TypeInput{ Supertokens: &supertokens.ConnectionInfo{ @@ -96,14 +123,18 @@ func TestThatUserGetReturnsValidUserForThirdPartyUserWhenUsingThirdPartyPassword WebsiteDomain: "supertokens.io", }, RecipeList: []supertokens.Recipe{ - thirdpartypasswordless.Init(tplmodels.TypeInput{ + thirdparty.Init(&tpmodels.TypeInput{ + SignInAndUpFeature: tpmodels.TypeInputSignInAndUp{ + Providers: []tpmodels.ProviderInput{ + customProvider1, + }, + }, + }), + passwordless.Init(plessmodels.TypeInput{ FlowType: "USER_INPUT_CODE_AND_MAGIC_LINK", ContactMethodEmailOrPhone: plessmodels.ContactMethodEmailOrPhoneConfig{ Enabled: true, }, - Providers: []tpmodels.ProviderInput{ - thirdpartypasswordless.SigninupCustomProvider1, - }, }), Init(&dashboardmodels.TypeInput{ ApiKey: "testapikey", diff --git a/recipe/thirdpartypasswordless/api/implementation.go b/recipe/thirdpartypasswordless/api/implementation.go deleted file mode 100644 index 2d7f7c13..00000000 --- a/recipe/thirdpartypasswordless/api/implementation.go +++ /dev/null @@ -1,168 +0,0 @@ -/* Copyright (c) 2021, VRAI Labs and/or its affiliates. All rights reserved. - * - * This software is licensed under the Apache License, Version 2.0 (the - * "License") as published by the Apache Software Foundation. - * - * You may not use this file except in compliance with the License. You may - * obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -package api - -import ( - plessapi "github.com/supertokens/supertokens-golang/recipe/passwordless/api" - "github.com/supertokens/supertokens-golang/recipe/passwordless/plessmodels" - "github.com/supertokens/supertokens-golang/recipe/session/sessmodels" - tpapi "github.com/supertokens/supertokens-golang/recipe/thirdparty/api" - "github.com/supertokens/supertokens-golang/recipe/thirdparty/tpmodels" - "github.com/supertokens/supertokens-golang/recipe/thirdpartypasswordless/tplmodels" - "github.com/supertokens/supertokens-golang/supertokens" -) - -func MakeAPIImplementation() tplmodels.APIInterface { - passwordlessImplementation := plessapi.MakeAPIImplementation() - thirdPartyImplementation := tpapi.MakeAPIImplementation() - - ogSignInUpPOST := *thirdPartyImplementation.SignInUpPOST - thirdPartySignInUpPOST := func(provider *tpmodels.TypeProvider, input tpmodels.TypeSignInUpInput, tenantId string, options tpmodels.APIOptions, userContext supertokens.UserContext) (tplmodels.ThirdPartySignInUpPOSTResponse, error) { - response, err := ogSignInUpPOST(provider, input, tenantId, options, userContext) - if err != nil { - return tplmodels.ThirdPartySignInUpPOSTResponse{}, err - } - if response.GeneralError != nil { - return tplmodels.ThirdPartySignInUpPOSTResponse{ - GeneralError: response.GeneralError, - }, nil - } else if response.NoEmailGivenByProviderError != nil { - return tplmodels.ThirdPartySignInUpPOSTResponse{ - NoEmailGivenByProviderError: &struct{}{}, - }, nil - } else { - return tplmodels.ThirdPartySignInUpPOSTResponse{ - OK: &struct { - CreatedNewUser bool - User tplmodels.User - Session *sessmodels.TypeSessionContainer - OAuthTokens map[string]interface{} - RawUserInfoFromProvider tpmodels.TypeRawUserInfoFromProvider - }{ - CreatedNewUser: response.OK.CreatedNewUser, - User: tplmodels.User{ - ID: response.OK.User.ID, - TimeJoined: response.OK.User.TimeJoined, - Email: &response.OK.User.Email, - ThirdParty: &response.OK.User.ThirdParty, - }, - Session: response.OK.Session, - OAuthTokens: response.OK.OAuthTokens, - RawUserInfoFromProvider: response.OK.RawUserInfoFromProvider, - }, - }, nil - } - } - - ogAuthorisationUrlGET := *thirdPartyImplementation.AuthorisationUrlGET - authorisationUrlGET := func(provider *tpmodels.TypeProvider, redirectURIOnProviderDashboard string, tenantId string, options tpmodels.APIOptions, userContext supertokens.UserContext) (tpmodels.AuthorisationUrlGETResponse, error) { - return ogAuthorisationUrlGET(provider, redirectURIOnProviderDashboard, tenantId, options, userContext) - } - - ogAppleRedirectHandlerPOST := *thirdPartyImplementation.AppleRedirectHandlerPOST - appleRedirectHandlerPOST := func(formPostInfoFromProvider map[string]interface{}, options tpmodels.APIOptions, userContext supertokens.UserContext) error { - return ogAppleRedirectHandlerPOST(formPostInfoFromProvider, options, userContext) - } - - ogConsumeCodePOST := *passwordlessImplementation.ConsumeCodePOST - consumeCodePOST := func(userInput *plessmodels.UserInputCodeWithDeviceID, linkCode *string, preAuthSessionID string, tenantId string, options plessmodels.APIOptions, userContext supertokens.UserContext) (tplmodels.ConsumeCodePOSTResponse, error) { - resp, err := ogConsumeCodePOST(userInput, linkCode, preAuthSessionID, tenantId, options, userContext) - if err != nil { - return tplmodels.ConsumeCodePOSTResponse{}, err - } - if resp.OK != nil { - return tplmodels.ConsumeCodePOSTResponse{ - OK: &struct { - CreatedNewUser bool - User tplmodels.User - Session sessmodels.SessionContainer - }{ - CreatedNewUser: resp.OK.CreatedNewUser, - Session: resp.OK.Session, - User: tplmodels.User{ - ID: resp.OK.User.ID, - TimeJoined: resp.OK.User.TimeJoined, - Email: resp.OK.User.Email, - PhoneNumber: resp.OK.User.PhoneNumber, - ThirdParty: nil, - }, - }, - }, nil - } else if resp.ExpiredUserInputCodeError != nil { - return tplmodels.ConsumeCodePOSTResponse{ - ExpiredUserInputCodeError: resp.ExpiredUserInputCodeError, - }, nil - } else if resp.IncorrectUserInputCodeError != nil { - return tplmodels.ConsumeCodePOSTResponse{ - IncorrectUserInputCodeError: resp.IncorrectUserInputCodeError, - }, nil - } else if resp.RestartFlowError != nil { - return tplmodels.ConsumeCodePOSTResponse{ - RestartFlowError: &struct{}{}, - }, nil - } else { - return tplmodels.ConsumeCodePOSTResponse{ - GeneralError: resp.GeneralError, - }, nil - } - } - - ogCreateCodePOST := *passwordlessImplementation.CreateCodePOST - createCodePOST := func(email *string, phoneNumber *string, tenantId string, options plessmodels.APIOptions, userContext supertokens.UserContext) (plessmodels.CreateCodePOSTResponse, error) { - return ogCreateCodePOST(email, phoneNumber, tenantId, options, userContext) - } - - ogEmailExistGET := *passwordlessImplementation.EmailExistsGET - passwordlessEmailExistsGET := func(email string, tenantId string, options plessmodels.APIOptions, userContext supertokens.UserContext) (plessmodels.EmailExistsGETResponse, error) { - return ogEmailExistGET(email, tenantId, options, userContext) - } - - ogPhoneNumberExistsGET := *passwordlessImplementation.PhoneNumberExistsGET - passwordlessPhoneNumberExistsGET := func(phoneNumber string, tenantId string, options plessmodels.APIOptions, userContext supertokens.UserContext) (plessmodels.PhoneNumberExistsGETResponse, error) { - return ogPhoneNumberExistsGET(phoneNumber, tenantId, options, userContext) - } - - ogResendCodePOST := *passwordlessImplementation.ResendCodePOST - resendCodePOST := func(deviceID string, preAuthSessionID string, tenantId string, options plessmodels.APIOptions, userContext supertokens.UserContext) (plessmodels.ResendCodePOSTResponse, error) { - return ogResendCodePOST(deviceID, preAuthSessionID, tenantId, options, userContext) - } - - result := tplmodels.APIInterface{ - AuthorisationUrlGET: &authorisationUrlGET, - ThirdPartySignInUpPOST: &thirdPartySignInUpPOST, - AppleRedirectHandlerPOST: &appleRedirectHandlerPOST, - - CreateCodePOST: &createCodePOST, - ResendCodePOST: &resendCodePOST, - ConsumeCodePOST: &consumeCodePOST, - PasswordlessEmailExistsGET: &passwordlessEmailExistsGET, - PasswordlessPhoneNumberExistsGET: &passwordlessPhoneNumberExistsGET, - } - - modifiedPwdless := GetPasswordlessIterfaceImpl(result) - (*passwordlessImplementation.ConsumeCodePOST) = *modifiedPwdless.ConsumeCodePOST - (*passwordlessImplementation.CreateCodePOST) = *modifiedPwdless.CreateCodePOST - (*passwordlessImplementation.EmailExistsGET) = *modifiedPwdless.EmailExistsGET - (*passwordlessImplementation.PhoneNumberExistsGET) = *modifiedPwdless.PhoneNumberExistsGET - (*passwordlessImplementation.ResendCodePOST) = *modifiedPwdless.ResendCodePOST - - modifiedTP := GetThirdPartyIterfaceImpl(result) - (*thirdPartyImplementation.AuthorisationUrlGET) = *modifiedTP.AuthorisationUrlGET - (*thirdPartyImplementation.SignInUpPOST) = *modifiedTP.SignInUpPOST - (*thirdPartyImplementation.AppleRedirectHandlerPOST) = *modifiedTP.AppleRedirectHandlerPOST - - return result -} diff --git a/recipe/thirdpartypasswordless/api/passwordlessAPIImplementation.go b/recipe/thirdpartypasswordless/api/passwordlessAPIImplementation.go deleted file mode 100644 index 0cbecc9d..00000000 --- a/recipe/thirdpartypasswordless/api/passwordlessAPIImplementation.go +++ /dev/null @@ -1,78 +0,0 @@ -/* Copyright (c) 2021, VRAI Labs and/or its affiliates. All rights reserved. - * - * This software is licensed under the Apache License, Version 2.0 (the - * "License") as published by the Apache Software Foundation. - * - * You may not use this file except in compliance with the License. You may - * obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -package api - -import ( - "github.com/supertokens/supertokens-golang/recipe/passwordless/plessmodels" - "github.com/supertokens/supertokens-golang/recipe/session/sessmodels" - "github.com/supertokens/supertokens-golang/recipe/thirdpartypasswordless/tplmodels" - "github.com/supertokens/supertokens-golang/supertokens" -) - -func GetPasswordlessIterfaceImpl(apiImplmentation tplmodels.APIInterface) plessmodels.APIInterface { - - result := plessmodels.APIInterface{ - CreateCodePOST: apiImplmentation.CreateCodePOST, - ResendCodePOST: apiImplmentation.ResendCodePOST, - EmailExistsGET: apiImplmentation.PasswordlessEmailExistsGET, - PhoneNumberExistsGET: apiImplmentation.PasswordlessPhoneNumberExistsGET, - ConsumeCodePOST: nil, - } - - if apiImplmentation.ConsumeCodePOST != nil && (*apiImplmentation.ConsumeCodePOST) != nil { - consumeCodePOST := func(userInput *plessmodels.UserInputCodeWithDeviceID, linkCode *string, preAuthSessionID string, tenantId string, options plessmodels.APIOptions, userContext supertokens.UserContext) (plessmodels.ConsumeCodePOSTResponse, error) { - result, err := (*apiImplmentation.ConsumeCodePOST)(userInput, linkCode, preAuthSessionID, tenantId, options, userContext) - if err != nil { - return plessmodels.ConsumeCodePOSTResponse{}, err - } - if result.OK != nil { - return plessmodels.ConsumeCodePOSTResponse{OK: &struct { - CreatedNewUser bool - User plessmodels.User - Session sessmodels.SessionContainer - }{ - CreatedNewUser: result.OK.CreatedNewUser, - User: plessmodels.User{ - ID: result.OK.User.ID, - Email: result.OK.User.Email, - PhoneNumber: result.OK.User.PhoneNumber, - TimeJoined: result.OK.User.TimeJoined, - }, - Session: result.OK.Session, - }}, nil - } else if result.ExpiredUserInputCodeError != nil { - return plessmodels.ConsumeCodePOSTResponse{ - ExpiredUserInputCodeError: result.ExpiredUserInputCodeError, - }, nil - } else if result.IncorrectUserInputCodeError != nil { - return plessmodels.ConsumeCodePOSTResponse{ - IncorrectUserInputCodeError: result.IncorrectUserInputCodeError, - }, nil - } else if result.RestartFlowError != nil { - return plessmodels.ConsumeCodePOSTResponse{ - RestartFlowError: &struct{}{}, - }, nil - } else { - return plessmodels.ConsumeCodePOSTResponse{ - GeneralError: result.GeneralError, - }, nil - } - } - result.ConsumeCodePOST = &consumeCodePOST - } - - return result -} diff --git a/recipe/thirdpartypasswordless/api/thirdPartyAPIImplementation.go b/recipe/thirdpartypasswordless/api/thirdPartyAPIImplementation.go deleted file mode 100644 index b5bf0341..00000000 --- a/recipe/thirdpartypasswordless/api/thirdPartyAPIImplementation.go +++ /dev/null @@ -1,78 +0,0 @@ -/* Copyright (c) 2021, VRAI Labs and/or its affiliates. All rights reserved. - * - * This software is licensed under the Apache License, Version 2.0 (the - * "License") as published by the Apache Software Foundation. - * - * You may not use this file except in compliance with the License. You may - * obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -package api - -import ( - "github.com/supertokens/supertokens-golang/recipe/session/sessmodels" - "github.com/supertokens/supertokens-golang/recipe/thirdparty/tpmodels" - "github.com/supertokens/supertokens-golang/recipe/thirdpartypasswordless/tplmodels" - "github.com/supertokens/supertokens-golang/supertokens" -) - -func GetThirdPartyIterfaceImpl(apiImplmentation tplmodels.APIInterface) tpmodels.APIInterface { - if apiImplmentation.ThirdPartySignInUpPOST == nil || (*apiImplmentation.ThirdPartySignInUpPOST) == nil { - return tpmodels.APIInterface{ - AuthorisationUrlGET: apiImplmentation.AuthorisationUrlGET, - AppleRedirectHandlerPOST: apiImplmentation.AppleRedirectHandlerPOST, - SignInUpPOST: nil, - } - } - - signInUpPOST := func(provider *tpmodels.TypeProvider, input tpmodels.TypeSignInUpInput, tenantId string, options tpmodels.APIOptions, userContext supertokens.UserContext) (tpmodels.SignInUpPOSTResponse, error) { - result, err := (*apiImplmentation.ThirdPartySignInUpPOST)(provider, input, tenantId, options, userContext) - if err != nil { - return tpmodels.SignInUpPOSTResponse{}, err - } - - if result.OK != nil { - return tpmodels.SignInUpPOSTResponse{ - OK: &struct { - CreatedNewUser bool - User tpmodels.User - Session *sessmodels.TypeSessionContainer - OAuthTokens map[string]interface{} - RawUserInfoFromProvider tpmodels.TypeRawUserInfoFromProvider - }{ - CreatedNewUser: result.OK.CreatedNewUser, - User: tpmodels.User{ - ID: result.OK.User.ID, - TimeJoined: result.OK.User.TimeJoined, - Email: *result.OK.User.Email, - TenantIds: result.OK.User.TenantIds, - ThirdParty: *result.OK.User.ThirdParty, - }, - Session: result.OK.Session, - OAuthTokens: result.OK.OAuthTokens, - RawUserInfoFromProvider: result.OK.RawUserInfoFromProvider, - }, - }, nil - } else if result.NoEmailGivenByProviderError != nil { - return tpmodels.SignInUpPOSTResponse{ - NoEmailGivenByProviderError: &struct{}{}, - }, nil - } else { - return tpmodels.SignInUpPOSTResponse{ - GeneralError: result.GeneralError, - }, nil - } - } - - return tpmodels.APIInterface{ - AuthorisationUrlGET: apiImplmentation.AuthorisationUrlGET, - AppleRedirectHandlerPOST: apiImplmentation.AppleRedirectHandlerPOST, - SignInUpPOST: &signInUpPOST, - } -} diff --git a/recipe/thirdpartypasswordless/emaildelivery/backwardCompatibilityService/main.go b/recipe/thirdpartypasswordless/emaildelivery/backwardCompatibilityService/main.go deleted file mode 100644 index 196904c5..00000000 --- a/recipe/thirdpartypasswordless/emaildelivery/backwardCompatibilityService/main.go +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2022, VRAI Labs and/or its affiliates. All rights reserved. - * - * This software is licensed under the Apache License, Version 2.0 (the - * "License") as published by the Apache Software Foundation. - * - * You may not use this file except in compliance with the License. You may - * obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -package backwardCompatibilityService - -import ( - "errors" - - "github.com/supertokens/supertokens-golang/ingredients/emaildelivery" - passwordlessBackwardsCompatibilityService "github.com/supertokens/supertokens-golang/recipe/passwordless/emaildelivery/backwardCompatibilityService" - "github.com/supertokens/supertokens-golang/supertokens" -) - -func MakeBackwardCompatibilityService(appInfo supertokens.NormalisedAppinfo, sendPasswordlessLoginEmail func(email string, userInputCode *string, urlWithLinkCode *string, codeLifetime uint64, preAuthSessionId string, userContext supertokens.UserContext) error) emaildelivery.EmailDeliveryInterface { - passwordlessService := passwordlessBackwardsCompatibilityService.MakeBackwardCompatibilityService(appInfo, sendPasswordlessLoginEmail) - - sendEmail := func(input emaildelivery.EmailType, userContext supertokens.UserContext) error { - if input.PasswordlessLogin != nil { - return (*passwordlessService.SendEmail)(input, userContext) - - } else { - return errors.New("should never come here") - } - } - - return emaildelivery.EmailDeliveryInterface{ - SendEmail: &sendEmail, - } -} diff --git a/recipe/thirdpartypasswordless/emaildelivery/smtpService/main.go b/recipe/thirdpartypasswordless/emaildelivery/smtpService/main.go deleted file mode 100644 index 88eee5d6..00000000 --- a/recipe/thirdpartypasswordless/emaildelivery/smtpService/main.go +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2022, VRAI Labs and/or its affiliates. All rights reserved. - * - * This software is licensed under the Apache License, Version 2.0 (the - * "License") as published by the Apache Software Foundation. - * - * You may not use this file except in compliance with the License. You may - * obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -package smtpService - -import ( - "errors" - - "github.com/supertokens/supertokens-golang/ingredients/emaildelivery" - plesssmtpService "github.com/supertokens/supertokens-golang/recipe/passwordless/emaildelivery/smtpService" - "github.com/supertokens/supertokens-golang/supertokens" -) - -func MakeSMTPService(config emaildelivery.SMTPServiceConfig) *emaildelivery.EmailDeliveryInterface { - serviceImpl := makeServiceImplementation(config.Settings) - - if config.Override != nil { - serviceImpl = config.Override(serviceImpl) - } - - passwordlessServiceImpl := plesssmtpService.MakeSMTPService(emaildelivery.SMTPServiceConfig{ - Settings: config.Settings, - Override: makePasswordlessServiceImplementation(serviceImpl), - }) - - sendEmail := func(input emaildelivery.EmailType, userContext supertokens.UserContext) error { - if input.PasswordlessLogin != nil { - return (*passwordlessServiceImpl.SendEmail)(input, userContext) - - } else { - return errors.New("should never come here") - } - } - - return &emaildelivery.EmailDeliveryInterface{ - SendEmail: &sendEmail, - } -} diff --git a/recipe/thirdpartypasswordless/emaildelivery/smtpService/plessServiceImplementation.go b/recipe/thirdpartypasswordless/emaildelivery/smtpService/plessServiceImplementation.go deleted file mode 100644 index c11b4b65..00000000 --- a/recipe/thirdpartypasswordless/emaildelivery/smtpService/plessServiceImplementation.go +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2022, VRAI Labs and/or its affiliates. All rights reserved. - * - * This software is licensed under the Apache License, Version 2.0 (the - * "License") as published by the Apache Software Foundation. - * - * You may not use this file except in compliance with the License. You may - * obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -package smtpService - -import ( - "github.com/supertokens/supertokens-golang/ingredients/emaildelivery" - "github.com/supertokens/supertokens-golang/supertokens" -) - -func makePasswordlessServiceImplementation(serviceImpl emaildelivery.SMTPInterface) func(originalImplementation emaildelivery.SMTPInterface) emaildelivery.SMTPInterface { - return func(originalImplementation emaildelivery.SMTPInterface) emaildelivery.SMTPInterface { - sendRawEmail := func(input emaildelivery.EmailContent, userContext supertokens.UserContext) error { - return (*serviceImpl.SendRawEmail)(input, userContext) - } - - getContent := func(input emaildelivery.EmailType, userContext supertokens.UserContext) (emaildelivery.EmailContent, error) { - return (*serviceImpl.GetContent)(input, userContext) - } - - return emaildelivery.SMTPInterface{ - SendRawEmail: &sendRawEmail, - GetContent: &getContent, - } - } -} diff --git a/recipe/thirdpartypasswordless/emaildelivery/smtpService/serviceImplementation.go b/recipe/thirdpartypasswordless/emaildelivery/smtpService/serviceImplementation.go deleted file mode 100644 index 90191e25..00000000 --- a/recipe/thirdpartypasswordless/emaildelivery/smtpService/serviceImplementation.go +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2022, VRAI Labs and/or its affiliates. All rights reserved. - * - * This software is licensed under the Apache License, Version 2.0 (the - * "License") as published by the Apache Software Foundation. - * - * You may not use this file except in compliance with the License. You may - * obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -package smtpService - -import ( - "errors" - - "github.com/supertokens/supertokens-golang/ingredients/emaildelivery" - plesssmtpService "github.com/supertokens/supertokens-golang/recipe/passwordless/emaildelivery/smtpService" - "github.com/supertokens/supertokens-golang/supertokens" -) - -func makeServiceImplementation(settings emaildelivery.SMTPSettings) emaildelivery.SMTPInterface { - sendRawEmail := func(input emaildelivery.EmailContent, userContext supertokens.UserContext) error { - return emaildelivery.SendSMTPEmail(settings, input) - } - - plessServiceImpl := plesssmtpService.MakeServiceImplementation(settings) - - getContent := func(input emaildelivery.EmailType, userContext supertokens.UserContext) (emaildelivery.EmailContent, error) { - if input.PasswordlessLogin != nil { - return (*plessServiceImpl.GetContent)(input, userContext) - - } else { - return emaildelivery.EmailContent{}, errors.New("should never come here") - } - } - - return emaildelivery.SMTPInterface{ - SendRawEmail: &sendRawEmail, - GetContent: &getContent, - } -} diff --git a/recipe/thirdpartypasswordless/main.go b/recipe/thirdpartypasswordless/main.go deleted file mode 100644 index ed7c6710..00000000 --- a/recipe/thirdpartypasswordless/main.go +++ /dev/null @@ -1,415 +0,0 @@ -/* Copyright (c) 2021, VRAI Labs and/or its affiliates. All rights reserved. - * - * This software is licensed under the Apache License, Version 2.0 (the - * "License") as published by the Apache Software Foundation. - * - * You may not use this file except in compliance with the License. You may - * obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -package thirdpartypasswordless - -import ( - "github.com/supertokens/supertokens-golang/ingredients/emaildelivery" - "github.com/supertokens/supertokens-golang/ingredients/smsdelivery" - "github.com/supertokens/supertokens-golang/recipe/passwordless/plessmodels" - "github.com/supertokens/supertokens-golang/recipe/thirdparty/tpmodels" - "github.com/supertokens/supertokens-golang/recipe/thirdpartypasswordless/emaildelivery/smtpService" - "github.com/supertokens/supertokens-golang/recipe/thirdpartypasswordless/smsdelivery/supertokensService" - "github.com/supertokens/supertokens-golang/recipe/thirdpartypasswordless/smsdelivery/twilioService" - "github.com/supertokens/supertokens-golang/recipe/thirdpartypasswordless/tplmodels" - "github.com/supertokens/supertokens-golang/supertokens" -) - -func Init(config tplmodels.TypeInput) supertokens.Recipe { - return recipeInit(config) -} - -func ThirdPartyManuallyCreateOrUpdateUser(tenantId string, thirdPartyID string, thirdPartyUserID string, email string, userContext ...supertokens.UserContext) (tplmodels.ManuallyCreateOrUpdateUserResponse, error) { - instance, err := GetRecipeInstanceOrThrowError() - if err != nil { - return tplmodels.ManuallyCreateOrUpdateUserResponse{}, err - } - if len(userContext) == 0 { - userContext = append(userContext, &map[string]interface{}{}) - } - return (*instance.RecipeImpl.ThirdPartyManuallyCreateOrUpdateUser)(thirdPartyID, thirdPartyUserID, email, tenantId, userContext[0]) -} - -func ThirdPartyGetProvider(tenantId string, thirdPartyID string, clientType *string, userContext ...supertokens.UserContext) (*tpmodels.TypeProvider, error) { - instance, err := GetRecipeInstanceOrThrowError() - if err != nil { - return nil, err - } - if len(userContext) == 0 { - userContext = append(userContext, &map[string]interface{}{}) - } - return (*instance.RecipeImpl.ThirdPartyGetProvider)(thirdPartyID, clientType, tenantId, userContext[0]) -} - -func GetUserByThirdPartyInfo(tenantId string, thirdPartyID string, thirdPartyUserID string, userContext ...supertokens.UserContext) (*tplmodels.User, error) { - instance, err := GetRecipeInstanceOrThrowError() - if err != nil { - return nil, err - } - if len(userContext) == 0 { - userContext = append(userContext, &map[string]interface{}{}) - } - return (*instance.RecipeImpl.GetUserByThirdPartyInfo)(thirdPartyID, thirdPartyUserID, tenantId, userContext[0]) -} - -func GetUserById(userID string, userContext ...supertokens.UserContext) (*tplmodels.User, error) { - instance, err := GetRecipeInstanceOrThrowError() - if err != nil { - return nil, err - } - if len(userContext) == 0 { - userContext = append(userContext, &map[string]interface{}{}) - } - return (*instance.RecipeImpl.GetUserByID)(userID, userContext[0]) -} - -func GetUsersByEmail(tenantId string, email string, userContext ...supertokens.UserContext) ([]tplmodels.User, error) { - instance, err := GetRecipeInstanceOrThrowError() - if err != nil { - return nil, err - } - if len(userContext) == 0 { - userContext = append(userContext, &map[string]interface{}{}) - } - return (*instance.RecipeImpl.GetUsersByEmail)(email, tenantId, userContext[0]) -} - -func CreateCodeWithEmail(tenantId string, email string, userInputCode *string, userContext ...supertokens.UserContext) (plessmodels.CreateCodeResponse, error) { - instance, err := GetRecipeInstanceOrThrowError() - if err != nil { - return plessmodels.CreateCodeResponse{}, err - } - if len(userContext) == 0 { - userContext = append(userContext, &map[string]interface{}{}) - } - return (*instance.RecipeImpl.CreateCode)(&email, nil, userInputCode, tenantId, userContext[0]) -} - -func CreateCodeWithPhoneNumber(tenantId string, phoneNumber string, userInputCode *string, userContext ...supertokens.UserContext) (plessmodels.CreateCodeResponse, error) { - instance, err := GetRecipeInstanceOrThrowError() - if err != nil { - return plessmodels.CreateCodeResponse{}, err - } - if len(userContext) == 0 { - userContext = append(userContext, &map[string]interface{}{}) - } - return (*instance.RecipeImpl.CreateCode)(nil, &phoneNumber, userInputCode, tenantId, userContext[0]) -} - -func CreateNewCodeForDevice(tenantId string, deviceID string, userInputCode *string, userContext ...supertokens.UserContext) (plessmodels.ResendCodeResponse, error) { - instance, err := GetRecipeInstanceOrThrowError() - if err != nil { - return plessmodels.ResendCodeResponse{}, err - } - if len(userContext) == 0 { - userContext = append(userContext, &map[string]interface{}{}) - } - return (*instance.RecipeImpl.CreateNewCodeForDevice)(deviceID, userInputCode, tenantId, userContext[0]) -} - -func ConsumeCodeWithUserInputCode(tenantId string, deviceID string, userInputCode string, preAuthSessionID string, userContext ...supertokens.UserContext) (tplmodels.ConsumeCodeResponse, error) { - instance, err := GetRecipeInstanceOrThrowError() - if err != nil { - return tplmodels.ConsumeCodeResponse{}, err - } - if len(userContext) == 0 { - userContext = append(userContext, &map[string]interface{}{}) - } - return (*instance.RecipeImpl.ConsumeCode)(&plessmodels.UserInputCodeWithDeviceID{ - Code: userInputCode, - DeviceID: deviceID, - }, nil, preAuthSessionID, tenantId, userContext[0]) -} - -func ConsumeCodeWithLinkCode(tenantId string, linkCode string, preAuthSessionID string, userContext ...supertokens.UserContext) (tplmodels.ConsumeCodeResponse, error) { - instance, err := GetRecipeInstanceOrThrowError() - if err != nil { - return tplmodels.ConsumeCodeResponse{}, err - } - if len(userContext) == 0 { - userContext = append(userContext, &map[string]interface{}{}) - } - return (*instance.RecipeImpl.ConsumeCode)(nil, &linkCode, preAuthSessionID, tenantId, userContext[0]) -} - -func GetUserByID(userID string, userContext ...supertokens.UserContext) (*tplmodels.User, error) { - instance, err := GetRecipeInstanceOrThrowError() - if err != nil { - return nil, err - } - if len(userContext) == 0 { - userContext = append(userContext, &map[string]interface{}{}) - } - return (*instance.RecipeImpl.GetUserByID)(userID, userContext[0]) -} - -func GetUserByPhoneNumber(tenantId string, phoneNumber string, userContext ...supertokens.UserContext) (*tplmodels.User, error) { - instance, err := GetRecipeInstanceOrThrowError() - if err != nil { - return nil, err - } - if len(userContext) == 0 { - userContext = append(userContext, &map[string]interface{}{}) - } - return (*instance.RecipeImpl.GetUserByPhoneNumber)(phoneNumber, tenantId, userContext[0]) -} - -func UpdatePasswordlessUser(userID string, email *string, phoneNumber *string, userContext ...supertokens.UserContext) (plessmodels.UpdateUserResponse, error) { - instance, err := GetRecipeInstanceOrThrowError() - if err != nil { - return plessmodels.UpdateUserResponse{}, err - } - if len(userContext) == 0 { - userContext = append(userContext, &map[string]interface{}{}) - } - return (*instance.RecipeImpl.UpdatePasswordlessUser)(userID, email, phoneNumber, userContext[0]) -} - -func DeleteEmailForPasswordlessUser(userID string, userContext ...supertokens.UserContext) (plessmodels.DeleteUserResponse, error) { - instance, err := GetRecipeInstanceOrThrowError() - if err != nil { - return plessmodels.DeleteUserResponse{}, err - } - if len(userContext) == 0 { - userContext = append(userContext, &map[string]interface{}{}) - } - return (*instance.RecipeImpl.DeleteEmailForPasswordlessUser)(userID, userContext[0]) -} - -func DeletePhoneNumberForUser(userID string, userContext ...supertokens.UserContext) (plessmodels.DeleteUserResponse, error) { - instance, err := GetRecipeInstanceOrThrowError() - if err != nil { - return plessmodels.DeleteUserResponse{}, err - } - if len(userContext) == 0 { - userContext = append(userContext, &map[string]interface{}{}) - } - return (*instance.RecipeImpl.DeletePhoneNumberForUser)(userID, userContext[0]) -} - -func RevokeAllCodesByEmail(tenantId string, email string, userContext ...supertokens.UserContext) error { - instance, err := GetRecipeInstanceOrThrowError() - if err != nil { - return err - } - if len(userContext) == 0 { - userContext = append(userContext, &map[string]interface{}{}) - } - return (*instance.RecipeImpl.RevokeAllCodes)(&email, nil, tenantId, userContext[0]) -} - -func RevokeAllCodesByPhoneNumber(tenantId string, phoneNumber string, userContext ...supertokens.UserContext) error { - instance, err := GetRecipeInstanceOrThrowError() - if err != nil { - return err - } - if len(userContext) == 0 { - userContext = append(userContext, &map[string]interface{}{}) - } - return (*instance.RecipeImpl.RevokeAllCodes)(nil, &phoneNumber, tenantId, userContext[0]) -} - -func RevokeCode(tenantId string, codeID string, userContext ...supertokens.UserContext) error { - instance, err := GetRecipeInstanceOrThrowError() - if err != nil { - return err - } - if len(userContext) == 0 { - userContext = append(userContext, &map[string]interface{}{}) - } - return (*instance.RecipeImpl.RevokeCode)(codeID, tenantId, userContext[0]) -} - -func ListCodesByEmail(tenantId string, email string, userContext ...supertokens.UserContext) ([]plessmodels.DeviceType, error) { - instance, err := GetRecipeInstanceOrThrowError() - if err != nil { - return []plessmodels.DeviceType{}, err - } - if len(userContext) == 0 { - userContext = append(userContext, &map[string]interface{}{}) - } - return (*instance.RecipeImpl.ListCodesByEmail)(email, tenantId, userContext[0]) -} - -func ListCodesByPhoneNumber(tenantId string, phoneNumber string, userContext ...supertokens.UserContext) ([]plessmodels.DeviceType, error) { - instance, err := GetRecipeInstanceOrThrowError() - if err != nil { - return []plessmodels.DeviceType{}, err - } - if len(userContext) == 0 { - userContext = append(userContext, &map[string]interface{}{}) - } - return (*instance.RecipeImpl.ListCodesByPhoneNumber)(phoneNumber, tenantId, userContext[0]) -} - -func ListCodesByDeviceID(tenantId string, deviceID string, userContext ...supertokens.UserContext) (*plessmodels.DeviceType, error) { - instance, err := GetRecipeInstanceOrThrowError() - if err != nil { - return nil, err - } - if len(userContext) == 0 { - userContext = append(userContext, &map[string]interface{}{}) - } - return (*instance.RecipeImpl.ListCodesByDeviceID)(deviceID, tenantId, userContext[0]) -} - -func ListCodesByPreAuthSessionID(tenantId string, preAuthSessionID string, userContext ...supertokens.UserContext) (*plessmodels.DeviceType, error) { - instance, err := GetRecipeInstanceOrThrowError() - if err != nil { - return nil, err - } - if len(userContext) == 0 { - userContext = append(userContext, &map[string]interface{}{}) - } - return (*instance.RecipeImpl.ListCodesByPreAuthSessionID)(preAuthSessionID, tenantId, userContext[0]) -} - -func CreateMagicLinkByEmail(tenantId string, email string, userContext ...supertokens.UserContext) (string, error) { - instance, err := GetRecipeInstanceOrThrowError() - if err != nil { - return "", err - } - if len(userContext) == 0 { - userContext = append(userContext, &map[string]interface{}{}) - } - return instance.passwordlessRecipe.CreateMagicLink(&email, nil, tenantId, userContext[0]) -} - -func CreateMagicLinkByPhoneNumber(tenantId string, phoneNumber string, userContext ...supertokens.UserContext) (string, error) { - instance, err := GetRecipeInstanceOrThrowError() - if err != nil { - return "", err - } - if len(userContext) == 0 { - userContext = append(userContext, &map[string]interface{}{}) - } - return instance.passwordlessRecipe.CreateMagicLink(nil, &phoneNumber, tenantId, userContext[0]) -} - -func PasswordlessSignInUpByEmail(tenantId string, email string, userContext ...supertokens.UserContext) (struct { - PreAuthSessionID string - CreatedNewUser bool - User tplmodels.User -}, error) { - instance, err := GetRecipeInstanceOrThrowError() - if err != nil { - return struct { - PreAuthSessionID string - CreatedNewUser bool - User tplmodels.User - }{}, err - } - if len(userContext) == 0 { - userContext = append(userContext, &map[string]interface{}{}) - } - resp, err := instance.passwordlessRecipe.SignInUp(&email, nil, tenantId, userContext[0]) - if err != nil { - return struct { - PreAuthSessionID string - CreatedNewUser bool - User tplmodels.User - }{}, err - } - return struct { - PreAuthSessionID string - CreatedNewUser bool - User tplmodels.User - }{ - PreAuthSessionID: resp.PreAuthSessionID, - CreatedNewUser: resp.CreatedNewUser, - User: tplmodels.User{ - ID: resp.User.ID, - TimeJoined: resp.User.TimeJoined, - Email: resp.User.Email, - PhoneNumber: resp.User.PhoneNumber, - ThirdParty: nil, - }, - }, nil -} - -func PasswordlessSignInUpByPhoneNumber(tenantId string, phoneNumber string, userContext ...supertokens.UserContext) (struct { - PreAuthSessionID string - CreatedNewUser bool - User tplmodels.User -}, error) { - instance, err := GetRecipeInstanceOrThrowError() - if err != nil { - return struct { - PreAuthSessionID string - CreatedNewUser bool - User tplmodels.User - }{}, err - } - if len(userContext) == 0 { - userContext = append(userContext, &map[string]interface{}{}) - } - resp, err := instance.passwordlessRecipe.SignInUp(nil, &phoneNumber, tenantId, userContext[0]) - if err != nil { - return struct { - PreAuthSessionID string - CreatedNewUser bool - User tplmodels.User - }{}, err - } - return struct { - PreAuthSessionID string - CreatedNewUser bool - User tplmodels.User - }{ - PreAuthSessionID: resp.PreAuthSessionID, - CreatedNewUser: resp.CreatedNewUser, - User: tplmodels.User{ - ID: resp.User.ID, - TimeJoined: resp.User.TimeJoined, - Email: resp.User.Email, - PhoneNumber: resp.User.PhoneNumber, - ThirdParty: nil, - }, - }, nil -} - -func SendEmail(input emaildelivery.EmailType, userContext ...supertokens.UserContext) error { - instance, err := GetRecipeInstanceOrThrowError() - if err != nil { - return err - } - if len(userContext) == 0 { - userContext = append(userContext, &map[string]interface{}{}) - } - return (*instance.EmailDelivery.IngredientInterfaceImpl.SendEmail)(input, userContext[0]) -} - -func SendSms(input smsdelivery.SmsType, userContext ...supertokens.UserContext) error { - instance, err := GetRecipeInstanceOrThrowError() - if err != nil { - return err - } - if len(userContext) == 0 { - userContext = append(userContext, &map[string]interface{}{}) - } - return (*instance.SmsDelivery.IngredientInterfaceImpl.SendSms)(input, userContext[0]) -} - -func MakeSMTPService(config emaildelivery.SMTPServiceConfig) *emaildelivery.EmailDeliveryInterface { - return smtpService.MakeSMTPService(config) -} - -func MakeTwilioService(config smsdelivery.TwilioServiceConfig) (*smsdelivery.SmsDeliveryInterface, error) { - return twilioService.MakeTwilioService(config) -} - -func MakeSupertokensSMSService(apiKey string) *smsdelivery.SmsDeliveryInterface { - return supertokensService.MakeSupertokensSMSService(apiKey) -} diff --git a/recipe/thirdpartypasswordless/recipe.go b/recipe/thirdpartypasswordless/recipe.go deleted file mode 100644 index e4566516..00000000 --- a/recipe/thirdpartypasswordless/recipe.go +++ /dev/null @@ -1,223 +0,0 @@ -/* Copyright (c) 2021, VRAI Labs and/or its affiliates. All rights reserved. - * - * This software is licensed under the Apache License, Version 2.0 (the - * "License") as published by the Apache Software Foundation. - * - * You may not use this file except in compliance with the License. You may - * obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -package thirdpartypasswordless - -import ( - "errors" - "net/http" - - "github.com/supertokens/supertokens-golang/ingredients/emaildelivery" - "github.com/supertokens/supertokens-golang/ingredients/smsdelivery" - "github.com/supertokens/supertokens-golang/recipe/passwordless" - "github.com/supertokens/supertokens-golang/recipe/passwordless/plessmodels" - "github.com/supertokens/supertokens-golang/recipe/thirdparty" - "github.com/supertokens/supertokens-golang/recipe/thirdparty/tpmodels" - "github.com/supertokens/supertokens-golang/recipe/thirdpartypasswordless/api" - "github.com/supertokens/supertokens-golang/recipe/thirdpartypasswordless/recipeimplementation" - "github.com/supertokens/supertokens-golang/recipe/thirdpartypasswordless/tplmodels" - "github.com/supertokens/supertokens-golang/supertokens" -) - -const RECIPE_ID = "thirdpartypasswordless" - -type Recipe struct { - RecipeModule supertokens.RecipeModule - Config tplmodels.TypeNormalisedInput - passwordlessRecipe *passwordless.Recipe - thirdPartyRecipe *thirdparty.Recipe - RecipeImpl tplmodels.RecipeInterface - APIImpl tplmodels.APIInterface - EmailDelivery emaildelivery.Ingredient - SmsDelivery smsdelivery.Ingredient -} - -var singletonInstance *Recipe - -func MakeRecipe(recipeId string, appInfo supertokens.NormalisedAppinfo, config tplmodels.TypeInput, thirdPartyInstance *thirdparty.Recipe, passwordlessInstance *passwordless.Recipe, emailDeliveryIngredient *emaildelivery.Ingredient, smsDeliveryIngredient *smsdelivery.Ingredient, onSuperTokensAPIError func(err error, req *http.Request, res http.ResponseWriter)) (Recipe, error) { - r := &Recipe{} - r.RecipeModule = supertokens.MakeRecipeModule(recipeId, appInfo, r.handleAPIRequest, r.getAllCORSHeaders, r.getAPIsHandled, nil, r.handleError, onSuperTokensAPIError) - - verifiedConfig, err := validateAndNormaliseUserInput(r, appInfo, config) - if err != nil { - return Recipe{}, err - } - r.Config = verifiedConfig - { - passwordlessquerierInstance, err := supertokens.GetNewQuerierInstanceOrThrowError(passwordless.RECIPE_ID) - if err != nil { - return Recipe{}, err - } - thirdpartyquerierInstance, err := supertokens.GetNewQuerierInstanceOrThrowError(thirdparty.RECIPE_ID) - if err != nil { - return Recipe{}, err - } - - r.RecipeImpl = verifiedConfig.Override.Functions(recipeimplementation.MakeRecipeImplementation(*passwordlessquerierInstance, thirdpartyquerierInstance, verifiedConfig.Providers)) - } - r.APIImpl = verifiedConfig.Override.APIs(api.MakeAPIImplementation()) - - if emailDeliveryIngredient != nil { - r.EmailDelivery = *emailDeliveryIngredient - } else { - r.EmailDelivery = emaildelivery.MakeIngredient(verifiedConfig.GetEmailDeliveryConfig()) - } - - if smsDeliveryIngredient != nil { - r.SmsDelivery = *smsDeliveryIngredient - } else { - r.SmsDelivery = smsdelivery.MakeIngredient(verifiedConfig.GetSmsDeliveryConfig()) - } - - var passwordlessRecipe passwordless.Recipe - if passwordlessInstance == nil { - passwordlessConfig := plessmodels.TypeInput{ - ContactMethodPhone: verifiedConfig.ContactMethodPhone, - ContactMethodEmail: verifiedConfig.ContactMethodEmail, - ContactMethodEmailOrPhone: verifiedConfig.ContactMethodEmailOrPhone, - FlowType: verifiedConfig.FlowType, - GetCustomUserInputCode: verifiedConfig.GetCustomUserInputCode, - Override: &plessmodels.OverrideStruct{ - Functions: func(originalImplementation plessmodels.RecipeInterface) plessmodels.RecipeInterface { - return recipeimplementation.MakePasswordlessRecipeImplementation(r.RecipeImpl) - }, - APIs: func(originalImplementation plessmodels.APIInterface) plessmodels.APIInterface { - return api.GetPasswordlessIterfaceImpl(r.APIImpl) - }, - }, - } - passwordlessRecipe, err = passwordless.MakeRecipe(recipeId, appInfo, passwordlessConfig, &r.EmailDelivery, &r.SmsDelivery, onSuperTokensAPIError) - if err != nil { - return Recipe{}, err - } - r.passwordlessRecipe = &passwordlessRecipe - } else { - r.passwordlessRecipe = passwordlessInstance - } - - if thirdPartyInstance == nil { - thirdPartyConfig := &tpmodels.TypeInput{ - SignInAndUpFeature: tpmodels.TypeInputSignInAndUp{ - Providers: verifiedConfig.Providers, - }, - Override: &tpmodels.OverrideStruct{ - Functions: func(_ tpmodels.RecipeInterface) tpmodels.RecipeInterface { - return recipeimplementation.MakeThirdPartyRecipeImplementation(r.RecipeImpl) - }, - APIs: func(_ tpmodels.APIInterface) tpmodels.APIInterface { - return api.GetThirdPartyIterfaceImpl(r.APIImpl) - }, - }, - } - thirdPartyRecipeinstance, err := thirdparty.MakeRecipe(recipeId, appInfo, thirdPartyConfig, &r.EmailDelivery, onSuperTokensAPIError) - if err != nil { - return Recipe{}, err - } - r.thirdPartyRecipe = &thirdPartyRecipeinstance - } else { - r.thirdPartyRecipe = thirdPartyInstance - } - - return *r, nil -} - -func recipeInit(config tplmodels.TypeInput) supertokens.Recipe { - return func(appInfo supertokens.NormalisedAppinfo, onSuperTokensAPIError func(err error, req *http.Request, res http.ResponseWriter)) (*supertokens.RecipeModule, error) { - if singletonInstance == nil { - recipe, err := MakeRecipe(RECIPE_ID, appInfo, config, nil, nil, nil, nil, onSuperTokensAPIError) - if err != nil { - return nil, err - } - singletonInstance = &recipe - return &singletonInstance.RecipeModule, nil - } - return nil, errors.New("ThirdPartyPasswordless recipe has already been initialised. Please check your code for bugs.") - } -} - -func GetRecipeInstanceOrThrowError() (*Recipe, error) { - if singletonInstance != nil { - return singletonInstance, nil - } - return nil, errors.New("Initialisation not done. Did you forget to call the init function?") -} - -func GetRecipeInstance() *Recipe { - return singletonInstance -} - -// implement RecipeModule - -func (r *Recipe) getAPIsHandled() ([]supertokens.APIHandled, error) { - passwordlessAPIhandled, err := r.passwordlessRecipe.RecipeModule.GetAPIsHandled() - if err != nil { - return nil, err - } - apisHandled := passwordlessAPIhandled - if r.thirdPartyRecipe != nil { - thirdpartyAPIhandled, err := r.thirdPartyRecipe.RecipeModule.GetAPIsHandled() - if err != nil { - return nil, err - } - apisHandled = append(apisHandled, thirdpartyAPIhandled...) - } - return apisHandled, nil -} - -func (r *Recipe) handleAPIRequest(id string, tenantId string, req *http.Request, res http.ResponseWriter, theirHandler http.HandlerFunc, path supertokens.NormalisedURLPath, method string, userContext supertokens.UserContext) error { - ok, _, err := r.passwordlessRecipe.RecipeModule.ReturnAPIIdIfCanHandleRequest(path, method, userContext) - if err != nil { - return err - } - if ok != nil { - return r.passwordlessRecipe.RecipeModule.HandleAPIRequest(id, tenantId, req, res, theirHandler, path, method, userContext) - } - if r.thirdPartyRecipe != nil { - ok, _, err := r.thirdPartyRecipe.RecipeModule.ReturnAPIIdIfCanHandleRequest(path, method, userContext) - if err != nil { - return err - } - if ok != nil { - return r.thirdPartyRecipe.RecipeModule.HandleAPIRequest(id, tenantId, req, res, theirHandler, path, method, userContext) - } - } - return errors.New("should not come here") -} - -func (r *Recipe) getAllCORSHeaders() []string { - corsHeaders := r.passwordlessRecipe.RecipeModule.GetAllCORSHeaders() - if r.thirdPartyRecipe != nil { - corsHeaders = append(corsHeaders, r.thirdPartyRecipe.RecipeModule.GetAllCORSHeaders()...) - } - return corsHeaders -} - -func (r *Recipe) handleError(err error, req *http.Request, res http.ResponseWriter, userContext supertokens.UserContext) (bool, error) { - handleError, err := r.passwordlessRecipe.RecipeModule.HandleError(err, req, res, userContext) - if err != nil || handleError { - return handleError, err - } - if r.thirdPartyRecipe != nil { - handleError, err = r.thirdPartyRecipe.RecipeModule.HandleError(err, req, res, userContext) - if err != nil || handleError { - return handleError, err - } - } - return false, nil -} - -func ResetForTest() { - singletonInstance = nil -} diff --git a/recipe/thirdpartypasswordless/recipeimplementation/main.go b/recipe/thirdpartypasswordless/recipeimplementation/main.go deleted file mode 100644 index b1cb8f0e..00000000 --- a/recipe/thirdpartypasswordless/recipeimplementation/main.go +++ /dev/null @@ -1,420 +0,0 @@ -/* Copyright (c) 2021, VRAI Labs and/or its affiliates. All rights reserved. - * - * This software is licensed under the Apache License, Version 2.0 (the - * "License") as published by the Apache Software Foundation. - * - * You may not use this file except in compliance with the License. You may - * obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -package recipeimplementation - -import ( - "errors" - - "github.com/supertokens/supertokens-golang/recipe/passwordless" - "github.com/supertokens/supertokens-golang/recipe/passwordless/plessmodels" - "github.com/supertokens/supertokens-golang/recipe/thirdparty" - "github.com/supertokens/supertokens-golang/recipe/thirdparty/tpmodels" - "github.com/supertokens/supertokens-golang/recipe/thirdpartypasswordless/tplmodels" - "github.com/supertokens/supertokens-golang/supertokens" -) - -func MakeRecipeImplementation(passwordlessQuerier supertokens.Querier, thirdPartyQuerier *supertokens.Querier, providers []tpmodels.ProviderInput) tplmodels.RecipeInterface { - result := tplmodels.RecipeInterface{} - - passwordlessImplementation := passwordless.MakeRecipeImplementation(passwordlessQuerier) - var thirdPartyImplementation *tpmodels.RecipeInterface - if thirdPartyQuerier != nil { - thirdPartyImplementationTemp := thirdparty.MakeRecipeImplementation(*thirdPartyQuerier, providers) - thirdPartyImplementation = &thirdPartyImplementationTemp - } - - var ogSignInUp func(thirdPartyID string, thirdPartyUserID string, email string, oAuthTokens tpmodels.TypeOAuthTokens, rawUserInfoFromProvider tpmodels.TypeRawUserInfoFromProvider, tenantId string, userContext supertokens.UserContext) (tpmodels.SignInUpResponse, error) = nil - if thirdPartyImplementation != nil { - ogSignInUp = *thirdPartyImplementation.SignInUp - } - thirPartySignInUp := func(thirdPartyID string, thirdPartyUserID string, email string, oAuthTokens tpmodels.TypeOAuthTokens, rawUserInfoFromProvider tpmodels.TypeRawUserInfoFromProvider, tenantId string, userContext supertokens.UserContext) (tplmodels.ThirdPartySignInUp, error) { - if ogSignInUp == nil { - return tplmodels.ThirdPartySignInUp{}, errors.New("no thirdparty provider configured") - } - result, err := ogSignInUp(thirdPartyID, thirdPartyUserID, email, oAuthTokens, rawUserInfoFromProvider, tenantId, userContext) - if err != nil { - return tplmodels.ThirdPartySignInUp{}, err - } - return tplmodels.ThirdPartySignInUp{ - OK: &struct { - CreatedNewUser bool - User tplmodels.User - OAuthTokens map[string]interface{} - RawUserInfoFromProvider tpmodels.TypeRawUserInfoFromProvider - }{ - CreatedNewUser: result.OK.CreatedNewUser, - User: tplmodels.User{ - ID: result.OK.User.ID, - TimeJoined: result.OK.User.TimeJoined, - Email: &result.OK.User.Email, - ThirdParty: &result.OK.User.ThirdParty, - }, - }, - }, nil - } - - var ogManuallyCreateOrUpdateUser func(thirdPartyID string, thirdPartyUserID string, email string, tenantId string, userContext supertokens.UserContext) (tpmodels.ManuallyCreateOrUpdateUserResponse, error) = nil - if thirdPartyImplementation != nil { - ogManuallyCreateOrUpdateUser = *thirdPartyImplementation.ManuallyCreateOrUpdateUser - } - - thirdPartyManuallyCreateOrUpdateUser := func(thirdPartyID string, thirdPartyUserID string, email string, tenantId string, userContext supertokens.UserContext) (tplmodels.ManuallyCreateOrUpdateUserResponse, error) { - if ogManuallyCreateOrUpdateUser == nil { - return tplmodels.ManuallyCreateOrUpdateUserResponse{}, errors.New("no thirdparty provider configured") - } - result, err := ogManuallyCreateOrUpdateUser(thirdPartyID, thirdPartyUserID, email, tenantId, userContext) - if err != nil { - return tplmodels.ManuallyCreateOrUpdateUserResponse{}, err - } - return tplmodels.ManuallyCreateOrUpdateUserResponse{ - OK: &struct { - CreatedNewUser bool - User tplmodels.User - }{ - CreatedNewUser: result.OK.CreatedNewUser, - User: tplmodels.User{ - ID: result.OK.User.ID, - TimeJoined: result.OK.User.TimeJoined, - Email: &result.OK.User.Email, - ThirdParty: &result.OK.User.ThirdParty, - }, - }, - }, nil - } - - var ogGetProvider func(thirdPartyID string, clientType *string, tenantId string, userContext supertokens.UserContext) (*tpmodels.TypeProvider, error) = nil - if thirdPartyImplementation != nil { - ogGetProvider = *thirdPartyImplementation.GetProvider - } - - thirdPartyGetProvider := func(thirdPartyID string, clientType *string, tenantId string, userContext supertokens.UserContext) (*tpmodels.TypeProvider, error) { - if ogGetProvider == nil { - return nil, errors.New("no thirdparty provider configured") - } - return ogGetProvider(thirdPartyID, clientType, tenantId, userContext) - } - - ogPlessGetUserByID := *passwordlessImplementation.GetUserByID - var ogTPGetUserById func(userID string, userContext supertokens.UserContext) (*tpmodels.User, error) = nil - if thirdPartyImplementation != nil { - ogTPGetUserById = *thirdPartyImplementation.GetUserByID - } - getUserByID := func(userID string, userContext supertokens.UserContext) (*tplmodels.User, error) { - user, err := ogPlessGetUserByID(userID, userContext) - if err != nil { - return nil, err - } - if user != nil { - return &tplmodels.User{ - ID: user.ID, - Email: user.Email, - PhoneNumber: user.PhoneNumber, - TimeJoined: user.TimeJoined, - TenantIds: user.TenantIds, - ThirdParty: nil, - }, nil - } - if ogTPGetUserById == nil { - return nil, nil - } - - userinfo, err := ogTPGetUserById(userID, userContext) - if err != nil { - return nil, err - } - - if userinfo != nil { - return &tplmodels.User{ - ID: userinfo.ID, - Email: &userinfo.Email, - PhoneNumber: nil, - TimeJoined: userinfo.TimeJoined, - TenantIds: userinfo.TenantIds, - ThirdParty: &userinfo.ThirdParty, - }, nil - } - return nil, nil - } - - ogPlessGetUserByEmail := *passwordlessImplementation.GetUserByEmail - var ogTPGetUsersByEmail func(email string, tenantId string, userContext supertokens.UserContext) ([]tpmodels.User, error) = nil - if thirdPartyImplementation != nil { - ogTPGetUsersByEmail = *thirdPartyImplementation.GetUsersByEmail - } - getUsersByEmail := func(email string, tenantId string, userContext supertokens.UserContext) ([]tplmodels.User, error) { - fromPless, err := ogPlessGetUserByEmail(email, tenantId, userContext) - if err != nil { - return []tplmodels.User{}, err - } - - fromTP := []tpmodels.User{} - if ogTPGetUsersByEmail != nil { - fromTP, err = ogTPGetUsersByEmail(email, tenantId, userContext) - if err != nil { - return []tplmodels.User{}, err - } - } - finalResult := []tplmodels.User{} - - if fromPless != nil { - finalResult = append(finalResult, tplmodels.User{ - ID: fromPless.ID, - TimeJoined: fromPless.TimeJoined, - Email: fromPless.Email, - PhoneNumber: fromPless.PhoneNumber, - ThirdParty: nil, - }) - } - - for _, tpUser := range fromTP { - finalResult = append(finalResult, tplmodels.User{ - ID: tpUser.ID, - TimeJoined: tpUser.TimeJoined, - Email: &tpUser.Email, - PhoneNumber: nil, - ThirdParty: &tpUser.ThirdParty, - }) - } - - return finalResult, nil - } - - var ogGetUserByThirdPartyInfo func(thirdPartyID string, thirdPartyUserID string, tenantId string, userContext supertokens.UserContext) (*tpmodels.User, error) = nil - if thirdPartyImplementation != nil { - ogGetUserByThirdPartyInfo = *thirdPartyImplementation.GetUserByThirdPartyInfo - } - getUserByThirdPartyInfo := func(thirdPartyID string, thirdPartyUserID string, tenantId string, userContext supertokens.UserContext) (*tplmodels.User, error) { - if ogGetUserByThirdPartyInfo == nil { - return nil, nil - } - - userinfo, err := ogGetUserByThirdPartyInfo(thirdPartyID, thirdPartyUserID, tenantId, userContext) - if err != nil { - return nil, err - } - - if userinfo != nil { - return &tplmodels.User{ - ID: userinfo.ID, - Email: &userinfo.Email, - PhoneNumber: nil, - TimeJoined: userinfo.TimeJoined, - TenantIds: userinfo.TenantIds, - ThirdParty: &userinfo.ThirdParty, - }, nil - } - return nil, nil - } - - ogCreateCode := *passwordlessImplementation.CreateCode - createCode := func(email *string, phoneNumber *string, userInputCode *string, tenantId string, userContext supertokens.UserContext) (plessmodels.CreateCodeResponse, error) { - return ogCreateCode(email, phoneNumber, userInputCode, tenantId, userContext) - } - - ogConsumeCode := *passwordlessImplementation.ConsumeCode - consumeCode := func(userInput *plessmodels.UserInputCodeWithDeviceID, linkCode *string, preAuthSessionID string, tenantId string, userContext supertokens.UserContext) (tplmodels.ConsumeCodeResponse, error) { - response, err := ogConsumeCode(userInput, linkCode, preAuthSessionID, tenantId, userContext) - if err != nil { - return tplmodels.ConsumeCodeResponse{}, err - } - - if response.ExpiredUserInputCodeError != nil { - return tplmodels.ConsumeCodeResponse{ - ExpiredUserInputCodeError: response.ExpiredUserInputCodeError, - }, nil - } else if response.IncorrectUserInputCodeError != nil { - return tplmodels.ConsumeCodeResponse{ - IncorrectUserInputCodeError: response.IncorrectUserInputCodeError, - }, nil - } else if response.RestartFlowError != nil { - return tplmodels.ConsumeCodeResponse{ - RestartFlowError: &struct{}{}, - }, nil - } - - return tplmodels.ConsumeCodeResponse{ - OK: &struct { - CreatedNewUser bool - User tplmodels.User - }{ - CreatedNewUser: response.OK.CreatedNewUser, - User: tplmodels.User{ - ID: response.OK.User.ID, - TimeJoined: response.OK.User.TimeJoined, - Email: response.OK.User.Email, - PhoneNumber: response.OK.User.PhoneNumber, - ThirdParty: nil, - }, - }, - }, nil - } - - ogCreateNewCodeForDevice := *passwordlessImplementation.CreateNewCodeForDevice - createNewCodeForDevice := func(deviceID string, userInputCode *string, tenantId string, userContext supertokens.UserContext) (plessmodels.ResendCodeResponse, error) { - return ogCreateNewCodeForDevice(deviceID, userInputCode, tenantId, userContext) - } - - ogGetUserByPhoneNumber := *passwordlessImplementation.GetUserByPhoneNumber - getUserByPhoneNumber := func(phoneNumber string, tenantId string, userContext supertokens.UserContext) (*tplmodels.User, error) { - resp, err := ogGetUserByPhoneNumber(phoneNumber, tenantId, userContext) - if err != nil { - return &tplmodels.User{}, err - } - - if resp == nil { - return nil, nil - } - - return &tplmodels.User{ - ID: resp.ID, - TimeJoined: resp.TimeJoined, - Email: resp.Email, - PhoneNumber: resp.PhoneNumber, - ThirdParty: nil, - }, nil - } - - ogListCodesByDeviceID := *passwordlessImplementation.ListCodesByDeviceID - listCodesByDeviceID := func(deviceID string, tenantId string, userContext supertokens.UserContext) (*plessmodels.DeviceType, error) { - return ogListCodesByDeviceID(deviceID, tenantId, userContext) - } - - ogListCodesByEmail := *passwordlessImplementation.ListCodesByEmail - listCodesByEmail := func(email string, tenantId string, userContext supertokens.UserContext) ([]plessmodels.DeviceType, error) { - return ogListCodesByEmail(email, tenantId, userContext) - } - - ogListCodesByPhoneNumber := *passwordlessImplementation.ListCodesByPhoneNumber - listCodesByPhoneNumber := func(phoneNumber string, tenantId string, userContext supertokens.UserContext) ([]plessmodels.DeviceType, error) { - return ogListCodesByPhoneNumber(phoneNumber, tenantId, userContext) - } - - ogListCodesByPreAuthSessionID := *passwordlessImplementation.ListCodesByPreAuthSessionID - listCodesByPreAuthSessionID := func(preAuthSessionID string, tenantId string, userContext supertokens.UserContext) (*plessmodels.DeviceType, error) { - return ogListCodesByPreAuthSessionID(preAuthSessionID, tenantId, userContext) - } - - ogRevokeAllCodes := *passwordlessImplementation.RevokeAllCodes - revokeAllCodes := func(email *string, phoneNumber *string, tenantId string, userContext supertokens.UserContext) error { - return ogRevokeAllCodes(email, phoneNumber, tenantId, userContext) - } - - ogRevokeCode := *passwordlessImplementation.RevokeCode - revokeCode := func(codeID string, tenantId string, userContext supertokens.UserContext) error { - return ogRevokeCode(codeID, tenantId, userContext) - } - - ogUpdateUser := *passwordlessImplementation.UpdateUser - updatePasswordlessUser := func(userID string, email *string, phoneNumber *string, userContext supertokens.UserContext) (plessmodels.UpdateUserResponse, error) { - user, err := (*result.GetUserByID)(userID, userContext) - if err != nil { - return plessmodels.UpdateUserResponse{}, err - } - - if user == nil { - return plessmodels.UpdateUserResponse{ - UnknownUserIdError: &struct{}{}, - }, nil - } else if user.ThirdParty != nil { - return plessmodels.UpdateUserResponse{}, errors.New("cannot update passwordless user info for those who signed up using third party login") - } - return ogUpdateUser(userID, email, phoneNumber, userContext) - } - - ogDeleteEmailForUser := *passwordlessImplementation.DeleteEmailForUser - deleteEmailForPasswordlessUser := func(userID string, userContext supertokens.UserContext) (plessmodels.DeleteUserResponse, error) { - user, err := (*result.GetUserByID)(userID, userContext) - if err != nil { - return plessmodels.DeleteUserResponse{}, err - } - - if user == nil { - return plessmodels.DeleteUserResponse{ - UnknownUserIdError: &struct{}{}, - }, nil - } else if user.ThirdParty != nil { - return plessmodels.DeleteUserResponse{}, errors.New("cannot update passwordless user info for those who signed up using third party login") - } - return ogDeleteEmailForUser(userID, userContext) - } - - ogDeletePhoneNumberForUser := *passwordlessImplementation.DeletePhoneNumberForUser - deletePhoneNumberForPasswordlessUser := func(userID string, userContext supertokens.UserContext) (plessmodels.DeleteUserResponse, error) { - user, err := (*result.GetUserByID)(userID, userContext) - if err != nil { - return plessmodels.DeleteUserResponse{}, err - } - - if user == nil { - return plessmodels.DeleteUserResponse{ - UnknownUserIdError: &struct{}{}, - }, nil - } else if user.ThirdParty != nil { - return plessmodels.DeleteUserResponse{}, errors.New("cannot update passwordless user info for those who signed up using third party login") - } - return ogDeletePhoneNumberForUser(userID, userContext) - } - - result.GetUserByID = &getUserByID - result.GetUsersByEmail = &getUsersByEmail - result.GetUserByThirdPartyInfo = &getUserByThirdPartyInfo - result.ThirdPartySignInUp = &thirPartySignInUp - result.ThirdPartyManuallyCreateOrUpdateUser = &thirdPartyManuallyCreateOrUpdateUser - result.ThirdPartyGetProvider = &thirdPartyGetProvider - result.ConsumeCode = &consumeCode - result.CreateCode = &createCode - result.CreateNewCodeForDevice = &createNewCodeForDevice - result.GetUserByPhoneNumber = &getUserByPhoneNumber - result.ListCodesByDeviceID = &listCodesByDeviceID - result.ListCodesByEmail = &listCodesByEmail - result.ListCodesByPhoneNumber = &listCodesByPhoneNumber - result.ListCodesByPreAuthSessionID = &listCodesByPreAuthSessionID - result.RevokeAllCodes = &revokeAllCodes - result.RevokeCode = &revokeCode - result.UpdatePasswordlessUser = &updatePasswordlessUser - result.DeleteEmailForPasswordlessUser = &deleteEmailForPasswordlessUser - result.DeletePhoneNumberForUser = &deletePhoneNumberForPasswordlessUser - - modifiedPwdless := MakePasswordlessRecipeImplementation(result) - (*passwordlessImplementation.ConsumeCode) = *modifiedPwdless.ConsumeCode - (*passwordlessImplementation.CreateCode) = *modifiedPwdless.CreateCode - (*passwordlessImplementation.CreateNewCodeForDevice) = *modifiedPwdless.CreateNewCodeForDevice - (*passwordlessImplementation.GetUserByEmail) = *modifiedPwdless.GetUserByEmail - (*passwordlessImplementation.GetUserByID) = *modifiedPwdless.GetUserByID - (*passwordlessImplementation.GetUserByPhoneNumber) = *modifiedPwdless.GetUserByPhoneNumber - (*passwordlessImplementation.ListCodesByDeviceID) = *modifiedPwdless.ListCodesByDeviceID - (*passwordlessImplementation.ListCodesByEmail) = *modifiedPwdless.ListCodesByEmail - (*passwordlessImplementation.ListCodesByPhoneNumber) = *modifiedPwdless.ListCodesByPhoneNumber - (*passwordlessImplementation.ListCodesByPreAuthSessionID) = *modifiedPwdless.ListCodesByPreAuthSessionID - (*passwordlessImplementation.RevokeAllCodes) = *modifiedPwdless.RevokeAllCodes - (*passwordlessImplementation.RevokeCode) = *modifiedPwdless.RevokeCode - (*passwordlessImplementation.UpdateUser) = *modifiedPwdless.UpdateUser - (*passwordlessImplementation.DeleteEmailForUser) = *modifiedPwdless.DeleteEmailForUser - (*passwordlessImplementation.DeletePhoneNumberForUser) = *modifiedPwdless.DeletePhoneNumberForUser - - if thirdPartyImplementation != nil { - modifiedTp := MakeThirdPartyRecipeImplementation(result) - (*thirdPartyImplementation.GetUserByID) = *modifiedTp.GetUserByID - (*thirdPartyImplementation.GetUserByThirdPartyInfo) = *modifiedTp.GetUserByThirdPartyInfo - (*thirdPartyImplementation.GetUsersByEmail) = *modifiedTp.GetUsersByEmail - (*thirdPartyImplementation.GetProvider) = *modifiedTp.GetProvider - (*thirdPartyImplementation.SignInUp) = *modifiedTp.SignInUp - (*thirdPartyImplementation.ManuallyCreateOrUpdateUser) = *modifiedTp.ManuallyCreateOrUpdateUser - (*thirdPartyImplementation.GetProvider) = *modifiedTp.GetProvider - } - - return result -} diff --git a/recipe/thirdpartypasswordless/recipeimplementation/passwordlessRecipeImplementation.go b/recipe/thirdpartypasswordless/recipeimplementation/passwordlessRecipeImplementation.go deleted file mode 100644 index 0fa14bd0..00000000 --- a/recipe/thirdpartypasswordless/recipeimplementation/passwordlessRecipeImplementation.go +++ /dev/null @@ -1,191 +0,0 @@ -/* Copyright (c) 2021, VRAI Labs and/or its affiliates. All rights reserved. - * - * This software is licensed under the Apache License, Version 2.0 (the - * "License") as published by the Apache Software Foundation. - * - * You may not use this file except in compliance with the License. You may - * obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -package recipeimplementation - -import ( - "github.com/supertokens/supertokens-golang/recipe/passwordless/plessmodels" - "github.com/supertokens/supertokens-golang/recipe/thirdpartypasswordless/tplmodels" - "github.com/supertokens/supertokens-golang/supertokens" -) - -func MakePasswordlessRecipeImplementation(recipeImplementation tplmodels.RecipeInterface) plessmodels.RecipeInterface { - createCode := func(email *string, phoneNumber *string, userInputCode *string, tenantId string, userContext supertokens.UserContext) (plessmodels.CreateCodeResponse, error) { - return (*recipeImplementation.CreateCode)(email, phoneNumber, userInputCode, tenantId, userContext) - } - - consumeCode := func(userInput *plessmodels.UserInputCodeWithDeviceID, linkCode *string, preAuthSessionID string, tenantId string, userContext supertokens.UserContext) (plessmodels.ConsumeCodeResponse, error) { - resp, err := (*recipeImplementation.ConsumeCode)(userInput, linkCode, preAuthSessionID, tenantId, userContext) - - if err != nil { - return plessmodels.ConsumeCodeResponse{}, err - } - - if resp.ExpiredUserInputCodeError != nil { - return plessmodels.ConsumeCodeResponse{ - ExpiredUserInputCodeError: resp.ExpiredUserInputCodeError, - }, nil - } else if resp.IncorrectUserInputCodeError != nil { - return plessmodels.ConsumeCodeResponse{ - IncorrectUserInputCodeError: resp.IncorrectUserInputCodeError, - }, nil - } else if resp.RestartFlowError != nil { - return plessmodels.ConsumeCodeResponse{ - RestartFlowError: &struct{}{}, - }, nil - } else { - return plessmodels.ConsumeCodeResponse{ - OK: &struct { - CreatedNewUser bool - User plessmodels.User - }{ - CreatedNewUser: resp.OK.CreatedNewUser, - User: plessmodels.User{ - ID: resp.OK.User.ID, - Email: resp.OK.User.Email, - PhoneNumber: resp.OK.User.PhoneNumber, - TimeJoined: resp.OK.User.TimeJoined, - }, - }, - }, nil - } - } - - createNewCodeForDevice := func(deviceID string, userInputCode *string, tenantId string, userContext supertokens.UserContext) (plessmodels.ResendCodeResponse, error) { - return (*recipeImplementation.CreateNewCodeForDevice)(deviceID, userInputCode, tenantId, userContext) - } - - getUserByEmail := func(email string, tenantId string, userContext supertokens.UserContext) (*plessmodels.User, error) { - resp, err := (*recipeImplementation.GetUsersByEmail)(email, tenantId, userContext) - if err != nil { - return nil, err - } - - for _, user := range resp { - if user.ThirdParty == nil { - return &plessmodels.User{ - ID: user.ID, - Email: user.Email, - PhoneNumber: user.PhoneNumber, - TimeJoined: user.TimeJoined, - }, nil - } - } - - return nil, nil - } - - getUserByID := func(userID string, userContext supertokens.UserContext) (*plessmodels.User, error) { - resp, err := (*recipeImplementation.GetUserByID)(userID, userContext) - - if err != nil { - return nil, err - } - - if resp == nil { - return nil, nil - } - - if resp.ThirdParty != nil { - // this is a thirdparty user - return nil, nil - } - - return &plessmodels.User{ - ID: resp.ID, - Email: resp.Email, - PhoneNumber: resp.PhoneNumber, - TimeJoined: resp.TimeJoined, - }, nil - } - - getUserByPhoneNumber := func(phoneNumber string, tenantId string, userContext supertokens.UserContext) (*plessmodels.User, error) { - resp, err := (*recipeImplementation.GetUserByPhoneNumber)(phoneNumber, tenantId, userContext) - - if err != nil { - return nil, err - } - - if resp == nil { - return nil, nil - } - - if resp.ThirdParty != nil { - // this is a thirdparty user - return nil, nil - } - - return &plessmodels.User{ - ID: resp.ID, - Email: resp.Email, - PhoneNumber: resp.PhoneNumber, - TimeJoined: resp.TimeJoined, - }, nil - } - - listCodesByDeviceID := func(deviceID string, tenantId string, userContext supertokens.UserContext) (*plessmodels.DeviceType, error) { - return (*recipeImplementation.ListCodesByDeviceID)(deviceID, tenantId, userContext) - } - - listCodesByEmail := func(email string, tenantId string, userContext supertokens.UserContext) ([]plessmodels.DeviceType, error) { - return (*recipeImplementation.ListCodesByEmail)(email, tenantId, userContext) - } - - listCodesByPhoneNumber := func(phoneNumber string, tenantId string, userContext supertokens.UserContext) ([]plessmodels.DeviceType, error) { - return (*recipeImplementation.ListCodesByPhoneNumber)(phoneNumber, tenantId, userContext) - } - - listCodesByPreAuthSessionID := func(preAuthSessionID string, tenantId string, userContext supertokens.UserContext) (*plessmodels.DeviceType, error) { - return (*recipeImplementation.ListCodesByPreAuthSessionID)(preAuthSessionID, tenantId, userContext) - } - - revokeAllCodes := func(email *string, phoneNumber *string, tenantId string, userContext supertokens.UserContext) error { - return (*recipeImplementation.RevokeAllCodes)(email, phoneNumber, tenantId, userContext) - } - - revokeCode := func(codeID string, tenantId string, userContext supertokens.UserContext) error { - return (*recipeImplementation.RevokeCode)(codeID, tenantId, userContext) - } - - updateUser := func(userID string, email *string, phoneNumber *string, userContext supertokens.UserContext) (plessmodels.UpdateUserResponse, error) { - return (*recipeImplementation.UpdatePasswordlessUser)(userID, email, phoneNumber, userContext) - } - - deleteEmailForUser := func(userID string, userContext supertokens.UserContext) (plessmodels.DeleteUserResponse, error) { - return (*recipeImplementation.DeleteEmailForPasswordlessUser)(userID, userContext) - } - - deletePhoneNumberForUser := func(userID string, userContext supertokens.UserContext) (plessmodels.DeleteUserResponse, error) { - return (*recipeImplementation.DeletePhoneNumberForUser)(userID, userContext) - } - - return plessmodels.RecipeInterface{ - CreateCode: &createCode, - ConsumeCode: &consumeCode, - CreateNewCodeForDevice: &createNewCodeForDevice, - GetUserByEmail: &getUserByEmail, - GetUserByID: &getUserByID, - GetUserByPhoneNumber: &getUserByPhoneNumber, - ListCodesByDeviceID: &listCodesByDeviceID, - ListCodesByEmail: &listCodesByEmail, - ListCodesByPhoneNumber: &listCodesByPhoneNumber, - ListCodesByPreAuthSessionID: &listCodesByPreAuthSessionID, - RevokeAllCodes: &revokeAllCodes, - RevokeCode: &revokeCode, - UpdateUser: &updateUser, - DeleteEmailForUser: &deleteEmailForUser, - DeletePhoneNumberForUser: &deletePhoneNumberForUser, - } -} diff --git a/recipe/thirdpartypasswordless/recipeimplementation/thirdPartyRecipeImplementation.go b/recipe/thirdpartypasswordless/recipeimplementation/thirdPartyRecipeImplementation.go deleted file mode 100644 index 18f02919..00000000 --- a/recipe/thirdpartypasswordless/recipeimplementation/thirdPartyRecipeImplementation.go +++ /dev/null @@ -1,140 +0,0 @@ -/* Copyright (c) 2021, VRAI Labs and/or its affiliates. All rights reserved. - * - * This software is licensed under the Apache License, Version 2.0 (the - * "License") as published by the Apache Software Foundation. - * - * You may not use this file except in compliance with the License. You may - * obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -package recipeimplementation - -import ( - "github.com/supertokens/supertokens-golang/recipe/thirdparty/tpmodels" - "github.com/supertokens/supertokens-golang/recipe/thirdpartypasswordless/tplmodels" - "github.com/supertokens/supertokens-golang/supertokens" -) - -func MakeThirdPartyRecipeImplementation(recipeImplementation tplmodels.RecipeInterface) tpmodels.RecipeInterface { - - getUserByThirdPartyInfo := func(thirdPartyID string, thirdPartyUserID string, tenantId string, userContext supertokens.UserContext) (*tpmodels.User, error) { - user, err := (*recipeImplementation.GetUserByThirdPartyInfo)(thirdPartyID, thirdPartyUserID, tenantId, userContext) - if err != nil { - return nil, err - } - if user == nil || user.ThirdParty == nil { - return nil, nil - } - return &tpmodels.User{ - ID: user.ID, - Email: *user.Email, - TimeJoined: user.TimeJoined, - TenantIds: user.TenantIds, - ThirdParty: *user.ThirdParty, - }, nil - } - - signInUp := func(thirdPartyID string, thirdPartyUserID string, email string, oAuthTokens tpmodels.TypeOAuthTokens, rawUserInfoFromProvider tpmodels.TypeRawUserInfoFromProvider, tenantId string, userContext supertokens.UserContext) (tpmodels.SignInUpResponse, error) { - result, err := (*recipeImplementation.ThirdPartySignInUp)(thirdPartyID, thirdPartyUserID, email, oAuthTokens, rawUserInfoFromProvider, tenantId, userContext) - if err != nil { - return tpmodels.SignInUpResponse{}, err - } - - return tpmodels.SignInUpResponse{ - OK: &struct { - CreatedNewUser bool - User tpmodels.User - OAuthTokens map[string]interface{} - RawUserInfoFromProvider tpmodels.TypeRawUserInfoFromProvider - }{ - CreatedNewUser: result.OK.CreatedNewUser, - User: tpmodels.User{ - ID: result.OK.User.ID, - Email: *result.OK.User.Email, - TimeJoined: result.OK.User.TimeJoined, - ThirdParty: *result.OK.User.ThirdParty, - }, - OAuthTokens: result.OK.OAuthTokens, - RawUserInfoFromProvider: result.OK.RawUserInfoFromProvider, - }, - }, nil - } - - manuallyCreateOrUpdateUser := func(thirdPartyID string, thirdPartyUserID string, email string, tenantId string, userContext supertokens.UserContext) (tpmodels.ManuallyCreateOrUpdateUserResponse, error) { - result, err := (*recipeImplementation.ThirdPartyManuallyCreateOrUpdateUser)(thirdPartyID, thirdPartyUserID, email, tenantId, userContext) - if err != nil { - return tpmodels.ManuallyCreateOrUpdateUserResponse{}, err - } - - return tpmodels.ManuallyCreateOrUpdateUserResponse{ - OK: &struct { - CreatedNewUser bool - User tpmodels.User - }{ - CreatedNewUser: result.OK.CreatedNewUser, - User: tpmodels.User{ - ID: result.OK.User.ID, - Email: *result.OK.User.Email, - TimeJoined: result.OK.User.TimeJoined, - ThirdParty: *result.OK.User.ThirdParty, - }, - }, - }, nil - } - - getUserByID := func(userID string, userContext supertokens.UserContext) (*tpmodels.User, error) { - user, err := (*recipeImplementation.GetUserByID)(userID, userContext) - if err != nil { - return nil, err - } - if user == nil || user.ThirdParty == nil { - return nil, nil - } - return &tpmodels.User{ - ID: user.ID, - Email: *user.Email, - TimeJoined: user.TimeJoined, - ThirdParty: *user.ThirdParty, - }, nil - } - - getUserByEmail := func(email string, tenantId string, userContext supertokens.UserContext) ([]tpmodels.User, error) { - users, err := (*recipeImplementation.GetUsersByEmail)(email, tenantId, userContext) - if err != nil { - return nil, err - } - - finalResult := []tpmodels.User{} - - for _, tpepUser := range users { - if tpepUser.ThirdParty != nil { - finalResult = append(finalResult, tpmodels.User{ - ID: tpepUser.ID, - TimeJoined: tpepUser.TimeJoined, - Email: *tpepUser.Email, - ThirdParty: *tpepUser.ThirdParty, - }) - } - } - return finalResult, nil - } - - getProvider := func(thirdPartyID string, clientType *string, tenantId string, userContext supertokens.UserContext) (*tpmodels.TypeProvider, error) { - return (*recipeImplementation.ThirdPartyGetProvider)(thirdPartyID, clientType, tenantId, userContext) - } - - return tpmodels.RecipeInterface{ - GetUserByID: &getUserByID, - GetUsersByEmail: &getUserByEmail, - GetUserByThirdPartyInfo: &getUserByThirdPartyInfo, - SignInUp: &signInUp, - ManuallyCreateOrUpdateUser: &manuallyCreateOrUpdateUser, - GetProvider: &getProvider, - } -} diff --git a/recipe/thirdpartypasswordless/smsdelivery/backwardCompatibilityService/main.go b/recipe/thirdpartypasswordless/smsdelivery/backwardCompatibilityService/main.go deleted file mode 100644 index f198ff40..00000000 --- a/recipe/thirdpartypasswordless/smsdelivery/backwardCompatibilityService/main.go +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2022, VRAI Labs and/or its affiliates. All rights reserved. - * - * This software is licensed under the Apache License, Version 2.0 (the - * "License") as published by the Apache Software Foundation. - * - * You may not use this file except in compliance with the License. You may - * obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -package backwardCompatibilityService - -import ( - "errors" - - "github.com/supertokens/supertokens-golang/ingredients/smsdelivery" - "github.com/supertokens/supertokens-golang/recipe/passwordless/smsdelivery/backwardCompatibilityService" - "github.com/supertokens/supertokens-golang/supertokens" -) - -func MakeBackwardCompatibilityService(createAndSendCustomSms func(phoneNumber string, userInputCode *string, urlWithLinkCode *string, codeLifetime uint64, preAuthSessionId string, userContext supertokens.UserContext) error) smsdelivery.SmsDeliveryInterface { - plessBackwardCompatibilityService := backwardCompatibilityService.MakeBackwardCompatibilityService(createAndSendCustomSms) - - sendSms := func(input smsdelivery.SmsType, userContext supertokens.UserContext) error { - if input.PasswordlessLogin != nil { - return (*plessBackwardCompatibilityService.SendSms)(input, userContext) - - } else { - return errors.New("should never come here") - } - } - - return smsdelivery.SmsDeliveryInterface{ - SendSms: &sendSms, - } -} diff --git a/recipe/thirdpartypasswordless/smsdelivery/supertokensService/main.go b/recipe/thirdpartypasswordless/smsdelivery/supertokensService/main.go deleted file mode 100644 index e9e14c36..00000000 --- a/recipe/thirdpartypasswordless/smsdelivery/supertokensService/main.go +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2022, VRAI Labs and/or its affiliates. All rights reserved. - * - * This software is licensed under the Apache License, Version 2.0 (the - * "License") as published by the Apache Software Foundation. - * - * You may not use this file except in compliance with the License. You may - * obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -package supertokensService - -import ( - "github.com/supertokens/supertokens-golang/ingredients/smsdelivery" - "github.com/supertokens/supertokens-golang/recipe/passwordless/smsdelivery/supertokensService" - "github.com/supertokens/supertokens-golang/supertokens" -) - -func MakeSupertokensSMSService(apiKey string) *smsdelivery.SmsDeliveryInterface { - plessService := supertokensService.MakeSupertokensSMSService(apiKey) - - sendSms := func(input smsdelivery.SmsType, userContext supertokens.UserContext) error { - return (*plessService.SendSms)(input, userContext) - } - - return &smsdelivery.SmsDeliveryInterface{ - SendSms: &sendSms, - } -} diff --git a/recipe/thirdpartypasswordless/smsdelivery/twilioService/main.go b/recipe/thirdpartypasswordless/smsdelivery/twilioService/main.go deleted file mode 100644 index 941760c7..00000000 --- a/recipe/thirdpartypasswordless/smsdelivery/twilioService/main.go +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2022, VRAI Labs and/or its affiliates. All rights reserved. - * - * This software is licensed under the Apache License, Version 2.0 (the - * "License") as published by the Apache Software Foundation. - * - * You may not use this file except in compliance with the License. You may - * obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -package twilioService - -import ( - "github.com/supertokens/supertokens-golang/ingredients/smsdelivery" - "github.com/supertokens/supertokens-golang/recipe/passwordless/smsdelivery/twilioService" - "github.com/supertokens/supertokens-golang/supertokens" -) - -func MakeTwilioService(config smsdelivery.TwilioServiceConfig) (*smsdelivery.SmsDeliveryInterface, error) { - plessServiceImpl, err := twilioService.MakeTwilioService(config) - - if err != nil { - return nil, err - } - - sendSms := func(input smsdelivery.SmsType, userContext supertokens.UserContext) error { - return (*plessServiceImpl.SendSms)(input, userContext) - } - - return &smsdelivery.SmsDeliveryInterface{ - SendSms: &sendSms, - }, nil -} diff --git a/recipe/thirdpartypasswordless/testingUtils.go b/recipe/thirdpartypasswordless/testingUtils.go deleted file mode 100644 index 80a87d2f..00000000 --- a/recipe/thirdpartypasswordless/testingUtils.go +++ /dev/null @@ -1,295 +0,0 @@ -/* Copyright (c) 2021, VRAI Labs and/or its affiliates. All rights reserved. - * - * This software is licensed under the Apache License, Version 2.0 (the - * "License") as published by the Apache Software Foundation. - * - * You may not use this file except in compliance with the License. You may - * obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -package thirdpartypasswordless - -import ( - "errors" - "github.com/supertokens/supertokens-golang/recipe/session" - "net/http" - "net/http/httptest" - "testing" - - "github.com/stretchr/testify/assert" - "github.com/supertokens/supertokens-golang/recipe/emailverification" - "github.com/supertokens/supertokens-golang/recipe/multitenancy" - "github.com/supertokens/supertokens-golang/recipe/passwordless" - "github.com/supertokens/supertokens-golang/recipe/thirdparty" - "github.com/supertokens/supertokens-golang/recipe/thirdparty/tpmodels" - "github.com/supertokens/supertokens-golang/supertokens" - "github.com/supertokens/supertokens-golang/test/unittesting" -) - -func resetAll() { - supertokens.ResetForTest() - ResetForTest() - emailverification.ResetForTest() - thirdparty.ResetForTest() - passwordless.ResetForTest() - session.ResetForTest() - multitenancy.ResetForTest() -} - -func BeforeEach() { - unittesting.KillAllST() - resetAll() - unittesting.SetUpST() -} - -func AfterEach() { - unittesting.KillAllST() - resetAll() - unittesting.CleanST() -} - -var customProvider1 = tpmodels.ProviderInput{ - Config: tpmodels.ProviderConfig{ - ThirdPartyId: "custom", - Clients: []tpmodels.ProviderClientConfig{ - { - ClientID: "supertokens", - }, - }, - AuthorizationEndpoint: "https://test.com/oauth/auth", - AuthorizationEndpointQueryParams: map[string]interface{}{ - "scope": "test", - "client_id": "supertokens", - }, - TokenEndpoint: "https://test.com/oauth/token", - }, - Override: func(originalImplementation *tpmodels.TypeProvider) *tpmodels.TypeProvider { - originalImplementation.GetUserInfo = func(oAuthTokens tpmodels.TypeOAuthTokens, userContext supertokens.UserContext) (tpmodels.TypeUserInfo, error) { - return tpmodels.TypeUserInfo{ - ThirdPartyUserId: "user", - Email: &tpmodels.EmailStruct{ - ID: "email@test.com", - IsVerified: true, - }, - }, nil - - } - return originalImplementation - }, -} - -var mockThirdPartyProvider1 = tpmodels.ProviderInput{ - Config: tpmodels.ProviderConfig{ - ThirdPartyId: "mock1", - }, -} - -var mockThirdPartyProvider2 = tpmodels.ProviderInput{ - Config: tpmodels.ProviderConfig{ - ThirdPartyId: "mock2", - }, -} - -var SigninupCustomProvider1 = tpmodels.ProviderInput{ - Config: tpmodels.ProviderConfig{ - ThirdPartyId: "custom", - Clients: []tpmodels.ProviderClientConfig{ - { - ClientID: "supertokens", - }, - }, - AuthorizationEndpoint: "https://test.com/oauth/auth", - TokenEndpoint: "https://test.com/oauth/token", - }, - Override: func(originalImplementation *tpmodels.TypeProvider) *tpmodels.TypeProvider { - originalImplementation.GetUserInfo = func(oAuthTokens tpmodels.TypeOAuthTokens, userContext supertokens.UserContext) (tpmodels.TypeUserInfo, error) { - return tpmodels.TypeUserInfo{ - ThirdPartyUserId: "user", - Email: &tpmodels.EmailStruct{ - ID: "email@test.com", - IsVerified: true, - }, - }, nil - } - return originalImplementation - }, -} - -var signinupCustomProvider3 = tpmodels.ProviderInput{ - Config: tpmodels.ProviderConfig{ - ThirdPartyId: "custom", - Clients: []tpmodels.ProviderClientConfig{ - { - ClientID: "supertokens", - }, - }, - AuthorizationEndpoint: "https://test.com/oauth/auth", - TokenEndpoint: "https://test.com/oauth/token", - }, - Override: func(originalImplementation *tpmodels.TypeProvider) *tpmodels.TypeProvider { - originalImplementation.GetUserInfo = func(oAuthTokens tpmodels.TypeOAuthTokens, userContext supertokens.UserContext) (tpmodels.TypeUserInfo, error) { - return tpmodels.TypeUserInfo{ - ThirdPartyUserId: "user", - }, nil - } - return originalImplementation - }, -} - -var signinupCustomProvider4 = tpmodels.ProviderInput{ - Config: tpmodels.ProviderConfig{ - ThirdPartyId: "custom", - Clients: []tpmodels.ProviderClientConfig{ - { - ClientID: "supertokens", - }, - }, - AuthorizationEndpoint: "https://test.com/oauth/auth", - TokenEndpoint: "https://test.com/oauth/token", - }, - Override: func(originalImplementation *tpmodels.TypeProvider) *tpmodels.TypeProvider { - originalImplementation.GetUserInfo = func(oAuthTokens tpmodels.TypeOAuthTokens, userContext supertokens.UserContext) (tpmodels.TypeUserInfo, error) { - return tpmodels.TypeUserInfo{}, errors.New("error from getUserInfo") - } - return originalImplementation - }, -} - -var signinupCustomProvider5 = tpmodels.ProviderInput{ - Config: tpmodels.ProviderConfig{ - ThirdPartyId: "custom", - Clients: []tpmodels.ProviderClientConfig{ - { - ClientID: "supertokens", - }, - }, - AuthorizationEndpoint: "https://test.com/oauth/auth", - TokenEndpoint: "https://test.com/oauth/token", - }, - Override: func(originalImplementation *tpmodels.TypeProvider) *tpmodels.TypeProvider { - originalImplementation.GetUserInfo = func(oAuthTokens tpmodels.TypeOAuthTokens, userContext supertokens.UserContext) (tpmodels.TypeUserInfo, error) { - return tpmodels.TypeUserInfo{ - ThirdPartyUserId: "user", - Email: &tpmodels.EmailStruct{ - ID: "email@test.com", - IsVerified: false, - }, - }, nil - } - return originalImplementation - }, -} - -var signinupCustomProvider6 = tpmodels.ProviderInput{ - Config: tpmodels.ProviderConfig{ - ThirdPartyId: "custom", - Clients: []tpmodels.ProviderClientConfig{ - { - ClientID: "supertokens", - }, - }, - AuthorizationEndpoint: "https://test.com/oauth/auth", - TokenEndpoint: "https://test.com/oauth/token", - }, - Override: func(originalImplementation *tpmodels.TypeProvider) *tpmodels.TypeProvider { - originalImplementation.GetUserInfo = func(oAuthTokens tpmodels.TypeOAuthTokens, userContext supertokens.UserContext) (tpmodels.TypeUserInfo, error) { - if oAuthTokens["access_token"] == nil { - return tpmodels.TypeUserInfo{}, nil - } - return tpmodels.TypeUserInfo{ - ThirdPartyUserId: "user", - Email: &tpmodels.EmailStruct{ - ID: "email@test.com", - IsVerified: true, - }, - }, nil - } - return originalImplementation - }, -} - -var userTestCustomProvider = tpmodels.ProviderInput{ - Config: tpmodels.ProviderConfig{ - ThirdPartyId: "custom", - Clients: []tpmodels.ProviderClientConfig{ - { - ClientID: "supertokens", - }, - }, - AuthorizationEndpoint: "https://test.com/oauth/auth", - TokenEndpoint: "https://test.com/oauth/token", - }, - Override: func(originalImplementation *tpmodels.TypeProvider) *tpmodels.TypeProvider { - originalImplementation.GetUserInfo = func(oAuthTokens tpmodels.TypeOAuthTokens, userContext supertokens.UserContext) (tpmodels.TypeUserInfo, error) { - return tpmodels.TypeUserInfo{ - ThirdPartyUserId: oAuthTokens["id"].(string), - Email: &tpmodels.EmailStruct{ - ID: oAuthTokens["email"].(string), - IsVerified: true, - }, - }, nil - } - return originalImplementation - }, -} - -type PostDataForCustomProvider struct { - ThirdPartyId string `json:"thirdPartyId"` - OAuthTokens map[string]interface{} `json:"oAuthTokens"` - // RedirectUri string `json:"redirectURI"` -} - -var customProviderForEmailVerification = tpmodels.ProviderInput{ - Config: tpmodels.ProviderConfig{ - ThirdPartyId: "custom", - Clients: []tpmodels.ProviderClientConfig{ - { - ClientID: "supertokens", - }, - }, - AuthorizationEndpoint: "https://test.com/oauth/auth", - TokenEndpoint: "https://test.com/oauth/token", - }, - Override: func(originalImplementation *tpmodels.TypeProvider) *tpmodels.TypeProvider { - originalImplementation.GetUserInfo = func(oAuthTokens tpmodels.TypeOAuthTokens, userContext supertokens.UserContext) (tpmodels.TypeUserInfo, error) { - if oAuthTokens["access_token"] == nil { - return tpmodels.TypeUserInfo{}, nil - } - return tpmodels.TypeUserInfo{ - ThirdPartyUserId: "user", - Email: &tpmodels.EmailStruct{ - ID: "test@example.com", - IsVerified: false, - }, - }, nil - } - return originalImplementation - }, -} - -func supertokensInitForTest(t *testing.T, recipes ...supertokens.Recipe) *httptest.Server { - config := supertokens.TypeInput{ - Supertokens: &supertokens.ConnectionInfo{ - ConnectionURI: "http://localhost:8080", - }, - AppInfo: supertokens.AppInfo{ - APIDomain: "api.supertokens.io", - AppName: "SuperTokens", - WebsiteDomain: "supertokens.io", - }, - RecipeList: recipes, - } - - err := supertokens.Init(config) - assert.NoError(t, err) - - mux := http.NewServeMux() - testServer := httptest.NewServer(supertokens.Middleware(mux)) - return testServer -} diff --git a/recipe/thirdpartypasswordless/tplmodels/apiInterface.go b/recipe/thirdpartypasswordless/tplmodels/apiInterface.go deleted file mode 100644 index 21545554..00000000 --- a/recipe/thirdpartypasswordless/tplmodels/apiInterface.go +++ /dev/null @@ -1,65 +0,0 @@ -/* Copyright (c) 2021, VRAI Labs and/or its affiliates. All rights reserved. - * - * This software is licensed under the Apache License, Version 2.0 (the - * "License") as published by the Apache Software Foundation. - * - * You may not use this file except in compliance with the License. You may - * obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -package tplmodels - -import ( - "github.com/supertokens/supertokens-golang/recipe/passwordless/plessmodels" - "github.com/supertokens/supertokens-golang/recipe/session/sessmodels" - "github.com/supertokens/supertokens-golang/recipe/thirdparty/tpmodels" - "github.com/supertokens/supertokens-golang/supertokens" -) - -type APIInterface struct { - AuthorisationUrlGET *func(provider *tpmodels.TypeProvider, redirectURIOnProviderDashboard string, tenantId string, options tpmodels.APIOptions, userContext supertokens.UserContext) (tpmodels.AuthorisationUrlGETResponse, error) - AppleRedirectHandlerPOST *func(formPostInfoFromProvider map[string]interface{}, options tpmodels.APIOptions, userContext supertokens.UserContext) error - ThirdPartySignInUpPOST *func(provider *tpmodels.TypeProvider, input tpmodels.TypeSignInUpInput, tenantId string, options tpmodels.APIOptions, userContext supertokens.UserContext) (ThirdPartySignInUpPOSTResponse, error) - - CreateCodePOST *func(email *string, phoneNumber *string, tenantId string, options plessmodels.APIOptions, userContext supertokens.UserContext) (plessmodels.CreateCodePOSTResponse, error) - ResendCodePOST *func(deviceID string, preAuthSessionID string, tenantId string, options plessmodels.APIOptions, userContext supertokens.UserContext) (plessmodels.ResendCodePOSTResponse, error) - ConsumeCodePOST *func(userInput *plessmodels.UserInputCodeWithDeviceID, linkCode *string, preAuthSessionID string, tenantId string, options plessmodels.APIOptions, userContext supertokens.UserContext) (ConsumeCodePOSTResponse, error) - PasswordlessEmailExistsGET *func(email string, tenantId string, options plessmodels.APIOptions, userContext supertokens.UserContext) (plessmodels.EmailExistsGETResponse, error) - PasswordlessPhoneNumberExistsGET *func(email string, tenantId string, options plessmodels.APIOptions, userContext supertokens.UserContext) (plessmodels.PhoneNumberExistsGETResponse, error) -} - -type ConsumeCodePOSTResponse struct { - OK *struct { - CreatedNewUser bool - User User - Session sessmodels.SessionContainer - } - IncorrectUserInputCodeError *struct { - FailedCodeInputAttemptCount int - MaximumCodeInputAttempts int - } - ExpiredUserInputCodeError *struct { - FailedCodeInputAttemptCount int - MaximumCodeInputAttempts int - } - RestartFlowError *struct{} - GeneralError *supertokens.GeneralErrorResponse -} - -type ThirdPartySignInUpPOSTResponse struct { - OK *struct { - CreatedNewUser bool - User User - Session sessmodels.SessionContainer - OAuthTokens tpmodels.TypeOAuthTokens - RawUserInfoFromProvider tpmodels.TypeRawUserInfoFromProvider - } - NoEmailGivenByProviderError *struct{} - GeneralError *supertokens.GeneralErrorResponse -} diff --git a/recipe/thirdpartypasswordless/tplmodels/models.go b/recipe/thirdpartypasswordless/tplmodels/models.go deleted file mode 100644 index 30e157fe..00000000 --- a/recipe/thirdpartypasswordless/tplmodels/models.go +++ /dev/null @@ -1,70 +0,0 @@ -/* Copyright (c) 2021, VRAI Labs and/or its affiliates. All rights reserved. - * - * This software is licensed under the Apache License, Version 2.0 (the - * "License") as published by the Apache Software Foundation. - * - * You may not use this file except in compliance with the License. You may - * obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -package tplmodels - -import ( - "github.com/supertokens/supertokens-golang/ingredients/emaildelivery" - "github.com/supertokens/supertokens-golang/ingredients/smsdelivery" - "github.com/supertokens/supertokens-golang/recipe/passwordless/plessmodels" - "github.com/supertokens/supertokens-golang/recipe/thirdparty/tpmodels" - "github.com/supertokens/supertokens-golang/supertokens" -) - -type User struct { - ID string `json:"id"` - TimeJoined uint64 `json:"timeJoined"` - Email *string `json:"email"` - PhoneNumber *string `json:"phoneNumber"` - ThirdParty *struct { - ID string `json:"id"` - UserID string `json:"userId"` - } `json:"thirdParty"` - TenantIds []string `json:"tenantIds"` -} - -type TypeInput struct { - ContactMethodPhone plessmodels.ContactMethodPhoneConfig - ContactMethodEmail plessmodels.ContactMethodEmailConfig - ContactMethodEmailOrPhone plessmodels.ContactMethodEmailOrPhoneConfig - FlowType string - GetCustomUserInputCode func(tenantId string, userContext supertokens.UserContext) (string, error) - Providers []tpmodels.ProviderInput - Override *OverrideStruct - EmailDelivery *emaildelivery.TypeInput - SmsDelivery *smsdelivery.TypeInput -} - -type TypeNormalisedInput struct { - ContactMethodPhone plessmodels.ContactMethodPhoneConfig - ContactMethodEmail plessmodels.ContactMethodEmailConfig - ContactMethodEmailOrPhone plessmodels.ContactMethodEmailOrPhoneConfig - FlowType string - GetCustomUserInputCode func(tenantId string, userContext supertokens.UserContext) (string, error) - Providers []tpmodels.ProviderInput - Override OverrideStruct - GetEmailDeliveryConfig func() emaildelivery.TypeInputWithService - GetSmsDeliveryConfig func() smsdelivery.TypeInputWithService -} - -type OverrideStruct struct { - Functions func(originalImplementation RecipeInterface) RecipeInterface - APIs func(originalImplementation APIInterface) APIInterface -} - -type EmailStruct struct { - ID string `json:"id"` - IsVerified bool `json:"isVerified"` -} diff --git a/recipe/thirdpartypasswordless/tplmodels/recipeInterface.go b/recipe/thirdpartypasswordless/tplmodels/recipeInterface.go deleted file mode 100644 index 8f306b56..00000000 --- a/recipe/thirdpartypasswordless/tplmodels/recipeInterface.go +++ /dev/null @@ -1,92 +0,0 @@ -/* Copyright (c) 2021, VRAI Labs and/or its affiliates. All rights reserved. - * - * This software is licensed under the Apache License, Version 2.0 (the - * "License") as published by the Apache Software Foundation. - * - * You may not use this file except in compliance with the License. You may - * obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -package tplmodels - -import ( - "github.com/supertokens/supertokens-golang/recipe/passwordless/plessmodels" - "github.com/supertokens/supertokens-golang/recipe/thirdparty/tpmodels" - "github.com/supertokens/supertokens-golang/supertokens" -) - -type RecipeInterface struct { - GetUserByID *func(userID string, userContext supertokens.UserContext) (*User, error) - GetUsersByEmail *func(email string, tenantId string, userContext supertokens.UserContext) ([]User, error) - GetUserByPhoneNumber *func(phoneNumber string, tenantId string, userContext supertokens.UserContext) (*User, error) - GetUserByThirdPartyInfo *func(thirdPartyID string, thirdPartyUserID string, tenantId string, userContext supertokens.UserContext) (*User, error) - - ThirdPartySignInUp *func(thirdPartyID string, thirdPartyUserID string, email string, oAuthTokens tpmodels.TypeOAuthTokens, rawUserInfoFromProvider tpmodels.TypeRawUserInfoFromProvider, tenantId string, userContext supertokens.UserContext) (ThirdPartySignInUp, error) - ThirdPartyManuallyCreateOrUpdateUser *func(thirdPartyID string, thirdPartyUserID string, email string, tenantId string, userContext supertokens.UserContext) (ManuallyCreateOrUpdateUserResponse, error) - ThirdPartyGetProvider *func(thirdPartyID string, clientType *string, tenantId string, userContext supertokens.UserContext) (*tpmodels.TypeProvider, error) - - CreateCode *func(email *string, phoneNumber *string, userInputCode *string, tenantId string, userContext supertokens.UserContext) (plessmodels.CreateCodeResponse, error) - CreateNewCodeForDevice *func(deviceID string, userInputCode *string, tenantId string, userContext supertokens.UserContext) (plessmodels.ResendCodeResponse, error) - ConsumeCode *func(userInput *plessmodels.UserInputCodeWithDeviceID, linkCode *string, preAuthSessionID string, tenantId string, userContext supertokens.UserContext) (ConsumeCodeResponse, error) - UpdatePasswordlessUser *func(userID string, email *string, phoneNumber *string, userContext supertokens.UserContext) (plessmodels.UpdateUserResponse, error) - DeleteEmailForPasswordlessUser *func(userID string, userContext supertokens.UserContext) (plessmodels.DeleteUserResponse, error) - DeletePhoneNumberForUser *func(userID string, userContext supertokens.UserContext) (plessmodels.DeleteUserResponse, error) - RevokeAllCodes *func(email *string, phoneNumber *string, tenantId string, userContext supertokens.UserContext) error - RevokeCode *func(codeID string, tenantId string, userContext supertokens.UserContext) error - ListCodesByEmail *func(email string, tenantId string, userContext supertokens.UserContext) ([]plessmodels.DeviceType, error) - ListCodesByPhoneNumber *func(phoneNumber string, tenantId string, userContext supertokens.UserContext) ([]plessmodels.DeviceType, error) - ListCodesByDeviceID *func(deviceID string, tenantId string, userContext supertokens.UserContext) (*plessmodels.DeviceType, error) - ListCodesByPreAuthSessionID *func(preAuthSessionID string, tenantId string, userContext supertokens.UserContext) (*plessmodels.DeviceType, error) -} - -type ConsumeCodeResponse struct { - OK *struct { - CreatedNewUser bool - User User - } - IncorrectUserInputCodeError *struct { - FailedCodeInputAttemptCount int - MaximumCodeInputAttempts int - } - ExpiredUserInputCodeError *struct { - FailedCodeInputAttemptCount int - MaximumCodeInputAttempts int - } - RestartFlowError *struct{} -} - -type ThirdPartySignInUp struct { - OK *struct { - CreatedNewUser bool - User User - OAuthTokens map[string]interface{} - RawUserInfoFromProvider tpmodels.TypeRawUserInfoFromProvider - } -} - -type ManuallyCreateOrUpdateUserResponse struct { - OK *struct { - CreatedNewUser bool - User User - } -} - -type SignUpResponse struct { - OK *struct { - User User - } - EmailAlreadyExistsError *struct{} -} - -type SignInResponse struct { - OK *struct { - User User - } - WrongCredentialsError *struct{} -} diff --git a/recipe/thirdpartypasswordless/utils.go b/recipe/thirdpartypasswordless/utils.go deleted file mode 100644 index c0233af8..00000000 --- a/recipe/thirdpartypasswordless/utils.go +++ /dev/null @@ -1,93 +0,0 @@ -/* Copyright (c) 2021, VRAI Labs and/or its affiliates. All rights reserved. - * - * This software is licensed under the Apache License, Version 2.0 (the - * "License") as published by the Apache Software Foundation. - * - * You may not use this file except in compliance with the License. You may - * obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -package thirdpartypasswordless - -import ( - "github.com/supertokens/supertokens-golang/ingredients/emaildelivery" - "github.com/supertokens/supertokens-golang/ingredients/smsdelivery" - "github.com/supertokens/supertokens-golang/recipe/passwordless" - "github.com/supertokens/supertokens-golang/recipe/thirdpartypasswordless/emaildelivery/backwardCompatibilityService" - smsBackwardCompatibilityService "github.com/supertokens/supertokens-golang/recipe/thirdpartypasswordless/smsdelivery/backwardCompatibilityService" - "github.com/supertokens/supertokens-golang/recipe/thirdpartypasswordless/tplmodels" - "github.com/supertokens/supertokens-golang/supertokens" -) - -func validateAndNormaliseUserInput(recipeInstance *Recipe, appInfo supertokens.NormalisedAppinfo, config tplmodels.TypeInput) (tplmodels.TypeNormalisedInput, error) { - typeNormalisedInput := makeTypeNormalisedInput(recipeInstance, config) - - typeNormalisedInput.GetEmailDeliveryConfig = func() emaildelivery.TypeInputWithService { - sendPasswordlessLoginEmail := passwordless.DefaultCreateAndSendCustomEmail(appInfo) - - emailService := backwardCompatibilityService.MakeBackwardCompatibilityService(appInfo, sendPasswordlessLoginEmail) - if config.EmailDelivery != nil && config.EmailDelivery.Service != nil { - emailService = *config.EmailDelivery.Service - } - result := emaildelivery.TypeInputWithService{ - Service: emailService, - } - if config.EmailDelivery != nil && config.EmailDelivery.Override != nil { - result.Override = config.EmailDelivery.Override - } - - return result - } - - typeNormalisedInput.GetSmsDeliveryConfig = func() smsdelivery.TypeInputWithService { - sendPasswordlessLoginSms := passwordless.DefaultCreateAndSendCustomTextMessage(appInfo) - - smsService := smsBackwardCompatibilityService.MakeBackwardCompatibilityService(sendPasswordlessLoginSms) - if config.SmsDelivery != nil && config.SmsDelivery.Service != nil { - smsService = *config.SmsDelivery.Service - } - result := smsdelivery.TypeInputWithService{ - Service: smsService, - } - if config.SmsDelivery != nil && config.SmsDelivery.Override != nil { - result.Override = config.SmsDelivery.Override - } - return result - } - - if config.Override != nil { - if config.Override.Functions != nil { - typeNormalisedInput.Override.Functions = config.Override.Functions - } - if config.Override.APIs != nil { - typeNormalisedInput.Override.APIs = config.Override.APIs - } - } - - return typeNormalisedInput, nil -} - -func makeTypeNormalisedInput(recipeInstance *Recipe, inputConfig tplmodels.TypeInput) tplmodels.TypeNormalisedInput { - return tplmodels.TypeNormalisedInput{ - Providers: inputConfig.Providers, - ContactMethodPhone: inputConfig.ContactMethodPhone, - ContactMethodEmail: inputConfig.ContactMethodEmail, - ContactMethodEmailOrPhone: inputConfig.ContactMethodEmailOrPhone, - FlowType: inputConfig.FlowType, - GetCustomUserInputCode: inputConfig.GetCustomUserInputCode, - Override: tplmodels.OverrideStruct{ - Functions: func(originalImplementation tplmodels.RecipeInterface) tplmodels.RecipeInterface { - return originalImplementation - }, - APIs: func(originalImplementation tplmodels.APIInterface) tplmodels.APIInterface { - return originalImplementation - }, - }, - } -} diff --git a/test/auth-react-server/main.go b/test/auth-react-server/main.go index ef4418bc..60139127 100644 --- a/test/auth-react-server/main.go +++ b/test/auth-react-server/main.go @@ -44,8 +44,6 @@ import ( "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/thirdpartypasswordless" - "github.com/supertokens/supertokens-golang/recipe/thirdpartypasswordless/tplmodels" "github.com/supertokens/supertokens-golang/recipe/userroles" "github.com/supertokens/supertokens-golang/recipe/userroles/userrolesclaims" "github.com/supertokens/supertokens-golang/supertokens" @@ -92,7 +90,6 @@ func callSTInit(passwordlessConfig *plessmodels.TypeInput) { passwordless.ResetForTest() session.ResetForTest() thirdparty.ResetForTest() - thirdpartypasswordless.ResetForTest() userroles.ResetForTest() multitenancy.ResetForTest() @@ -530,111 +527,111 @@ func callSTInit(passwordlessConfig *plessmodels.TypeInput) { }, }, }), - thirdpartypasswordless.Init(tplmodels.TypeInput{ - ContactMethodPhone: passwordlessConfig.ContactMethodPhone, - ContactMethodEmail: passwordlessConfig.ContactMethodEmail, - ContactMethodEmailOrPhone: passwordlessConfig.ContactMethodEmailOrPhone, - FlowType: passwordlessConfig.FlowType, - GetCustomUserInputCode: passwordlessConfig.GetCustomUserInputCode, - EmailDelivery: passwordlessConfig.EmailDelivery, - SmsDelivery: passwordlessConfig.SmsDelivery, - Providers: []tpmodels.ProviderInput{ - { - Config: tpmodels.ProviderConfig{ - ThirdPartyId: "google", - Clients: []tpmodels.ProviderClientConfig{ - { - ClientID: os.Getenv("GOOGLE_CLIENT_ID"), - ClientSecret: os.Getenv("GOOGLE_CLIENT_SECRET"), - }, - }, - }, - }, - { - Config: tpmodels.ProviderConfig{ - ThirdPartyId: "github", - Clients: []tpmodels.ProviderClientConfig{ - { - ClientID: os.Getenv("GITHUB_CLIENT_ID"), - ClientSecret: os.Getenv("GITHUB_CLIENT_SECRET"), - }, - }, - }, - }, - { - Config: tpmodels.ProviderConfig{ - ThirdPartyId: "facebook", - Clients: []tpmodels.ProviderClientConfig{ - { - ClientID: os.Getenv("FACEBOOK_CLIENT_ID"), - ClientSecret: os.Getenv("FACEBOOK_CLIENT_SECRET"), - }, - }, - }, - }, - customAuth0Provider(), - }, - Override: &tplmodels.OverrideStruct{ - APIs: func(originalImplementation tplmodels.APIInterface) tplmodels.APIInterface { - ogConsumeCodePOST := *originalImplementation.ConsumeCodePOST - ogCreateCodePOST := *originalImplementation.CreateCodePOST - ogResendCodePOST := *originalImplementation.ResendCodePOST - ogAuthorisationUrlGET := *originalImplementation.AuthorisationUrlGET - ogSignInUpPOST := *originalImplementation.ThirdPartySignInUpPOST + // thirdpartypasswordless.Init(tplmodels.TypeInput{ + // ContactMethodPhone: passwordlessConfig.ContactMethodPhone, + // ContactMethodEmail: passwordlessConfig.ContactMethodEmail, + // ContactMethodEmailOrPhone: passwordlessConfig.ContactMethodEmailOrPhone, + // FlowType: passwordlessConfig.FlowType, + // GetCustomUserInputCode: passwordlessConfig.GetCustomUserInputCode, + // EmailDelivery: passwordlessConfig.EmailDelivery, + // SmsDelivery: passwordlessConfig.SmsDelivery, + // Providers: []tpmodels.ProviderInput{ + // { + // Config: tpmodels.ProviderConfig{ + // ThirdPartyId: "google", + // Clients: []tpmodels.ProviderClientConfig{ + // { + // ClientID: os.Getenv("GOOGLE_CLIENT_ID"), + // ClientSecret: os.Getenv("GOOGLE_CLIENT_SECRET"), + // }, + // }, + // }, + // }, + // { + // Config: tpmodels.ProviderConfig{ + // ThirdPartyId: "github", + // Clients: []tpmodels.ProviderClientConfig{ + // { + // ClientID: os.Getenv("GITHUB_CLIENT_ID"), + // ClientSecret: os.Getenv("GITHUB_CLIENT_SECRET"), + // }, + // }, + // }, + // }, + // { + // Config: tpmodels.ProviderConfig{ + // ThirdPartyId: "facebook", + // Clients: []tpmodels.ProviderClientConfig{ + // { + // ClientID: os.Getenv("FACEBOOK_CLIENT_ID"), + // ClientSecret: os.Getenv("FACEBOOK_CLIENT_SECRET"), + // }, + // }, + // }, + // }, + // customAuth0Provider(), + // }, + // Override: &tplmodels.OverrideStruct{ + // APIs: func(originalImplementation tplmodels.APIInterface) tplmodels.APIInterface { + // ogConsumeCodePOST := *originalImplementation.ConsumeCodePOST + // ogCreateCodePOST := *originalImplementation.CreateCodePOST + // ogResendCodePOST := *originalImplementation.ResendCodePOST + // ogAuthorisationUrlGET := *originalImplementation.AuthorisationUrlGET + // ogSignInUpPOST := *originalImplementation.ThirdPartySignInUpPOST - (*originalImplementation.AuthorisationUrlGET) = func(provider *tpmodels.TypeProvider, redirectURIOnProviderDashboard string, tenantId string, options tpmodels.APIOptions, userContext supertokens.UserContext) (tpmodels.AuthorisationUrlGETResponse, error) { - gr := returnGeneralErrorIfNeeded(*options.Req, "general error from API authorisation url get", true) - if gr != nil { - return tpmodels.AuthorisationUrlGETResponse{ - GeneralError: gr, - }, nil - } - return ogAuthorisationUrlGET(provider, redirectURIOnProviderDashboard, tenantId, options, userContext) - } + // (*originalImplementation.AuthorisationUrlGET) = func(provider *tpmodels.TypeProvider, redirectURIOnProviderDashboard string, tenantId string, options tpmodels.APIOptions, userContext supertokens.UserContext) (tpmodels.AuthorisationUrlGETResponse, error) { + // gr := returnGeneralErrorIfNeeded(*options.Req, "general error from API authorisation url get", true) + // if gr != nil { + // return tpmodels.AuthorisationUrlGETResponse{ + // GeneralError: gr, + // }, nil + // } + // return ogAuthorisationUrlGET(provider, redirectURIOnProviderDashboard, tenantId, options, userContext) + // } - (*originalImplementation.ThirdPartySignInUpPOST) = func(provider *tpmodels.TypeProvider, input tpmodels.TypeSignInUpInput, tenantId string, options tpmodels.APIOptions, userContext supertokens.UserContext) (tplmodels.ThirdPartySignInUpPOSTResponse, error) { - gr := returnGeneralErrorIfNeeded(*options.Req, "general error from API sign in up", false) - if gr != nil { - return tplmodels.ThirdPartySignInUpPOSTResponse{ - GeneralError: gr, - }, nil - } - return ogSignInUpPOST(provider, input, tenantId, options, userContext) - } + // (*originalImplementation.ThirdPartySignInUpPOST) = func(provider *tpmodels.TypeProvider, input tpmodels.TypeSignInUpInput, tenantId string, options tpmodels.APIOptions, userContext supertokens.UserContext) (tplmodels.ThirdPartySignInUpPOSTResponse, error) { + // gr := returnGeneralErrorIfNeeded(*options.Req, "general error from API sign in up", false) + // if gr != nil { + // return tplmodels.ThirdPartySignInUpPOSTResponse{ + // GeneralError: gr, + // }, nil + // } + // return ogSignInUpPOST(provider, input, tenantId, options, userContext) + // } - (*originalImplementation.ConsumeCodePOST) = func(userInput *plessmodels.UserInputCodeWithDeviceID, linkCode *string, preAuthSessionID string, tenantId string, options plessmodels.APIOptions, userContext supertokens.UserContext) (tplmodels.ConsumeCodePOSTResponse, error) { - gr := returnGeneralErrorIfNeeded(*options.Req, "general error from API consume code", false) - if gr != nil { - return tplmodels.ConsumeCodePOSTResponse{ - GeneralError: gr, - }, nil - } - return ogConsumeCodePOST(userInput, linkCode, preAuthSessionID, tenantId, options, userContext) - } + // (*originalImplementation.ConsumeCodePOST) = func(userInput *plessmodels.UserInputCodeWithDeviceID, linkCode *string, preAuthSessionID string, tenantId string, options plessmodels.APIOptions, userContext supertokens.UserContext) (tplmodels.ConsumeCodePOSTResponse, error) { + // gr := returnGeneralErrorIfNeeded(*options.Req, "general error from API consume code", false) + // if gr != nil { + // return tplmodels.ConsumeCodePOSTResponse{ + // GeneralError: gr, + // }, nil + // } + // return ogConsumeCodePOST(userInput, linkCode, preAuthSessionID, tenantId, options, userContext) + // } - (*originalImplementation.CreateCodePOST) = func(email, phoneNumber *string, tenantId string, options plessmodels.APIOptions, userContext supertokens.UserContext) (plessmodels.CreateCodePOSTResponse, error) { - gr := returnGeneralErrorIfNeeded(*options.Req, "general error from API create code", false) - if gr != nil { - return plessmodels.CreateCodePOSTResponse{ - GeneralError: gr, - }, nil - } - return ogCreateCodePOST(email, phoneNumber, tenantId, options, userContext) - } + // (*originalImplementation.CreateCodePOST) = func(email, phoneNumber *string, tenantId string, options plessmodels.APIOptions, userContext supertokens.UserContext) (plessmodels.CreateCodePOSTResponse, error) { + // gr := returnGeneralErrorIfNeeded(*options.Req, "general error from API create code", false) + // if gr != nil { + // return plessmodels.CreateCodePOSTResponse{ + // GeneralError: gr, + // }, nil + // } + // return ogCreateCodePOST(email, phoneNumber, tenantId, options, userContext) + // } - (*originalImplementation.ResendCodePOST) = func(deviceID, preAuthSessionID string, tenantId string, options plessmodels.APIOptions, userContext supertokens.UserContext) (plessmodels.ResendCodePOSTResponse, error) { - gr := returnGeneralErrorIfNeeded(*options.Req, "general error from API resend code", false) - if gr != nil { - return plessmodels.ResendCodePOSTResponse{ - GeneralError: gr, - }, nil - } - return ogResendCodePOST(deviceID, preAuthSessionID, tenantId, options, userContext) - } - return originalImplementation - }, - }, - }), + // (*originalImplementation.ResendCodePOST) = func(deviceID, preAuthSessionID string, tenantId string, options plessmodels.APIOptions, userContext supertokens.UserContext) (plessmodels.ResendCodePOSTResponse, error) { + // gr := returnGeneralErrorIfNeeded(*options.Req, "general error from API resend code", false) + // if gr != nil { + // return plessmodels.ResendCodePOSTResponse{ + // GeneralError: gr, + // }, nil + // } + // return ogResendCodePOST(deviceID, preAuthSessionID, tenantId, options, userContext) + // } + // return originalImplementation + // }, + // }, + // }), userroles.Init(nil), }, })