From 1937c905f348e60215263c4d954e7ddaad887af7 Mon Sep 17 00:00:00 2001 From: Mayank Thakur Date: Mon, 6 Nov 2023 11:49:13 +0530 Subject: [PATCH] passed userContext to the querier functions --- recipe/dashboard/api/analyticsPOST.go | 2 +- recipe/dashboard/api/search/tagsGet.go | 2 +- recipe/dashboard/api/signInPost.go | 2 +- recipe/dashboard/api/signOutPost.go | 2 +- recipe/dashboard/recipeimplementation.go | 2 +- .../emailpassword/network_interceptor_test.go | 41 +++++++++++++++++ recipe/emailpassword/recipeImplementation.go | 14 +++--- .../emailverification/recipeimplementation.go | 10 ++--- recipe/jwt/recipeimplementation.go | 4 +- recipe/multitenancy/recipeimplementation.go | 16 +++---- recipe/passwordless/recipeimplementation.go | 30 ++++++------- recipe/session/accessTokenVersions_test.go | 12 ++--- recipe/session/querier_test.go | 12 ++--- recipe/session/recipeImplementation.go | 22 +++++----- recipe/session/sessionFunctions.go | 44 +++++++++---------- recipe/thirdparty/recipeImplementation.go | 10 ++--- recipe/usermetadata/recipeimplementation.go | 6 +-- recipe/userroles/recipeimplementation.go | 20 ++++----- supertokens/querier.go | 20 ++++----- supertokens/supertokens.go | 6 +-- supertokens/userIdMapping.go | 8 ++-- test/frontendIntegration/main.go | 2 +- 22 files changed, 164 insertions(+), 123 deletions(-) diff --git a/recipe/dashboard/api/analyticsPOST.go b/recipe/dashboard/api/analyticsPOST.go index d6b50fb7..d96ea8b0 100644 --- a/recipe/dashboard/api/analyticsPOST.go +++ b/recipe/dashboard/api/analyticsPOST.go @@ -76,7 +76,7 @@ func AnalyticsPost(apiInterface dashboardmodels.APIInterface, tenantId string, o return analyticsPostResponse{}, err } - response, err := querier.SendGetRequest("/telemetry", nil) + response, err := querier.SendGetRequest("/telemetry", nil, userContext) if err != nil { // We don't send telemetry events if this fails return analyticsPostResponse{ diff --git a/recipe/dashboard/api/search/tagsGet.go b/recipe/dashboard/api/search/tagsGet.go index 4ff61972..fdf3b76a 100644 --- a/recipe/dashboard/api/search/tagsGet.go +++ b/recipe/dashboard/api/search/tagsGet.go @@ -32,7 +32,7 @@ func SearchTagsGet(apiImplementation dashboardmodels.APIInterface, tenantId stri return searchTagsResponse{}, querierErr } - apiResponse, apiErr := querier.SendGetRequest("/user/search/tags", nil) + apiResponse, apiErr := querier.SendGetRequest("/user/search/tags", nil, userContext) if apiErr != nil { return searchTagsResponse{}, apiErr } diff --git a/recipe/dashboard/api/signInPost.go b/recipe/dashboard/api/signInPost.go index 1f00b9e4..b489ca75 100644 --- a/recipe/dashboard/api/signInPost.go +++ b/recipe/dashboard/api/signInPost.go @@ -52,7 +52,7 @@ func SignInPost(apiInterface dashboardmodels.APIInterface, options dashboardmode apiResponse, apiErr := querier.SendPostRequest("/recipe/dashboard/signin", map[string]interface{}{ "email": *readBody.Email, "password": *readBody.Password, - }) + }, userContext) if apiErr != nil { return apiErr diff --git a/recipe/dashboard/api/signOutPost.go b/recipe/dashboard/api/signOutPost.go index 6d344cff..f44e64ea 100644 --- a/recipe/dashboard/api/signOutPost.go +++ b/recipe/dashboard/api/signOutPost.go @@ -32,7 +32,7 @@ func SignOutPost(apiInterface dashboardmodels.APIInterface, tenantId string, opt _, apiError := querier.SendDeleteRequest("/recipe/dashboard/session", map[string]interface{}{}, map[string]string{ "sessionId": sessionIdFromHeader, - }) + }, userContext) if apiError != nil { return signOutPostResponse{}, apiError diff --git a/recipe/dashboard/recipeimplementation.go b/recipe/dashboard/recipeimplementation.go index 2cccad12..35133bc2 100644 --- a/recipe/dashboard/recipeimplementation.go +++ b/recipe/dashboard/recipeimplementation.go @@ -41,7 +41,7 @@ func makeRecipeImplementation(querier supertokens.Querier) dashboardmodels.Recip verifyResponse, err := querier.SendPostRequest("/recipe/dashboard/session/verify", map[string]interface{}{ "sessionId": authHeaderValue, - }) + }, userContext) if err != nil { return false, err diff --git a/recipe/emailpassword/network_interceptor_test.go b/recipe/emailpassword/network_interceptor_test.go index 605d448f..09593217 100644 --- a/recipe/emailpassword/network_interceptor_test.go +++ b/recipe/emailpassword/network_interceptor_test.go @@ -55,3 +55,44 @@ func TestNetworkInterceptorDuringSignIn(t *testing.T) { assert.Equal(t, 200, res.StatusCode) assert.Equal(t, true, isNetworkIntercepted) } + +func TestNetworkInterceptorNotSet(t *testing.T) { + isNetworkIntercepted = false + configValue := supertokens.TypeInput{ + Supertokens: &supertokens.ConnectionInfo{ + ConnectionURI: "http://localhost:8080", + }, + AppInfo: supertokens.AppInfo{ + AppName: "SuperTokens", + APIDomain: "api.supertokens.io", + WebsiteDomain: "supertokens.io", + }, + RecipeList: []supertokens.Recipe{ + Init(nil), + }, + } + BeforeEach() + + unittesting.StartUpST("localhost", "8080") + + defer AfterEach() + + err := supertokens.Init(configValue) + + if err != nil { + t.Error(err.Error()) + } + + mux := http.NewServeMux() + testServer := httptest.NewServer(supertokens.Middleware(mux)) + defer testServer.Close() + + res, err := unittesting.SignInRequest("random@gmail.com", "validpass123", testServer.URL) + + if err != nil { + t.Error(err.Error()) + } + + assert.Equal(t, 200, res.StatusCode) + assert.Equal(t, false, isNetworkIntercepted) +} diff --git a/recipe/emailpassword/recipeImplementation.go b/recipe/emailpassword/recipeImplementation.go index e7c2d492..0dca11f9 100644 --- a/recipe/emailpassword/recipeImplementation.go +++ b/recipe/emailpassword/recipeImplementation.go @@ -25,7 +25,7 @@ func MakeRecipeImplementation(querier supertokens.Querier, getEmailPasswordConfi response, err := querier.SendPostRequest(tenantId+"/recipe/signup", map[string]interface{}{ "email": email, "password": password, - }) + }, userContext) if err != nil { return epmodels.SignUpResponse{}, err } @@ -48,7 +48,7 @@ func MakeRecipeImplementation(querier supertokens.Querier, getEmailPasswordConfi response, err := querier.SendPostRequest(tenantId+"/recipe/signin", map[string]interface{}{ "email": email, "password": password, - }) + }, userContext) if err != nil { return epmodels.SignInResponse{}, err } @@ -70,7 +70,7 @@ func MakeRecipeImplementation(querier supertokens.Querier, getEmailPasswordConfi getUserByID := func(userID string, userContext supertokens.UserContext) (*epmodels.User, error) { response, err := querier.SendGetRequest("/recipe/user", map[string]string{ "userId": userID, - }) + }, userContext) if err != nil { return nil, err } @@ -88,7 +88,7 @@ func MakeRecipeImplementation(querier supertokens.Querier, getEmailPasswordConfi getUserByEmail := func(email string, tenantId string, userContext supertokens.UserContext) (*epmodels.User, error) { response, err := querier.SendGetRequest(tenantId+"/recipe/user", map[string]string{ "email": email, - }) + }, userContext) if err != nil { return nil, err } @@ -106,7 +106,7 @@ func MakeRecipeImplementation(querier supertokens.Querier, getEmailPasswordConfi createResetPasswordToken := func(userID string, tenantId string, userContext supertokens.UserContext) (epmodels.CreateResetPasswordTokenResponse, error) { response, err := querier.SendPostRequest(tenantId+"/recipe/user/password/reset/token", map[string]interface{}{ "userId": userID, - }) + }, userContext) if err != nil { return epmodels.CreateResetPasswordTokenResponse{}, err } @@ -126,7 +126,7 @@ func MakeRecipeImplementation(querier supertokens.Querier, getEmailPasswordConfi "method": "token", "token": token, "newPassword": newPassword, - }) + }, userContext) if err != nil { return epmodels.ResetPasswordUsingTokenResponse{}, nil } @@ -182,7 +182,7 @@ func MakeRecipeImplementation(querier supertokens.Querier, getEmailPasswordConfi } requestBody["password"] = password } - response, err := querier.SendPutRequest("/recipe/user", requestBody) + response, err := querier.SendPutRequest("/recipe/user", requestBody, userContext) if err != nil { return epmodels.UpdateEmailOrPasswordResponse{}, nil } diff --git a/recipe/emailverification/recipeimplementation.go b/recipe/emailverification/recipeimplementation.go index d55042a4..89f3d93b 100644 --- a/recipe/emailverification/recipeimplementation.go +++ b/recipe/emailverification/recipeimplementation.go @@ -25,7 +25,7 @@ func makeRecipeImplementation(querier supertokens.Querier) evmodels.RecipeInterf response, err := querier.SendPostRequest(tenantId+"/recipe/user/email/verify/token", map[string]interface{}{ "userId": userID, "email": email, - }) + }, userContext) if err != nil { return evmodels.CreateEmailVerificationTokenResponse{}, err } @@ -45,7 +45,7 @@ func makeRecipeImplementation(querier supertokens.Querier) evmodels.RecipeInterf response, err := querier.SendPostRequest(tenantId+"/recipe/user/email/verify", map[string]interface{}{ "method": "token", "token": token, - }) + }, userContext) if err != nil { return evmodels.VerifyEmailUsingTokenResponse{}, err } @@ -67,7 +67,7 @@ func makeRecipeImplementation(querier supertokens.Querier) evmodels.RecipeInterf response, err := querier.SendGetRequest("/recipe/user/email/verify", map[string]string{ "userId": userID, "email": email, - }) + }, userContext) if err != nil { return false, err } @@ -78,7 +78,7 @@ func makeRecipeImplementation(querier supertokens.Querier) evmodels.RecipeInterf _, err := querier.SendPostRequest(tenantId+"/recipe/user/email/verify/token/remove", map[string]interface{}{ "userId": userId, "email": email, - }) + }, userContext) if err != nil { return evmodels.RevokeEmailVerificationTokensResponse{}, err } @@ -91,7 +91,7 @@ func makeRecipeImplementation(querier supertokens.Querier) evmodels.RecipeInterf _, err := querier.SendPostRequest("/recipe/user/email/verify/remove", map[string]interface{}{ "userId": userId, "email": email, - }) + }, userContext) if err != nil { return evmodels.UnverifyEmailResponse{}, err } diff --git a/recipe/jwt/recipeimplementation.go b/recipe/jwt/recipeimplementation.go index 4fd7dc21..db0f70e9 100644 --- a/recipe/jwt/recipeimplementation.go +++ b/recipe/jwt/recipeimplementation.go @@ -46,7 +46,7 @@ func makeRecipeImplementation(querier supertokens.Querier, config jwtmodels.Type "algorithm": "RS256", "jwksDomain": appInfo.APIDomain.GetAsStringDangerous(), "useStaticSigningKey": shouldUseStaticSigningKey, - }) + }, userContext) if err != nil { return jwtmodels.CreateJWTResponse{}, err } @@ -65,7 +65,7 @@ func makeRecipeImplementation(querier supertokens.Querier, config jwtmodels.Type } } getJWKS := func(userContext supertokens.UserContext) (jwtmodels.GetJWKSResponse, error) { - response, headers, err := querier.SendGetRequestWithResponseHeaders("/.well-known/jwks.json", map[string]string{}) + response, headers, err := querier.SendGetRequestWithResponseHeaders("/.well-known/jwks.json", map[string]string{}, userContext) if err != nil { return jwtmodels.GetJWKSResponse{}, err } diff --git a/recipe/multitenancy/recipeimplementation.go b/recipe/multitenancy/recipeimplementation.go index f6439a61..107bbe4d 100644 --- a/recipe/multitenancy/recipeimplementation.go +++ b/recipe/multitenancy/recipeimplementation.go @@ -45,7 +45,7 @@ func makeRecipeImplementation(querier supertokens.Querier, config multitenancymo if config.CoreConfig != nil { requestBody["coreConfig"] = config.CoreConfig } - createOrUpdateResponse, err := querier.SendPutRequest("/recipe/multitenancy/tenant", requestBody) + createOrUpdateResponse, err := querier.SendPutRequest("/recipe/multitenancy/tenant", requestBody, userContext) if err != nil { return multitenancymodels.CreateOrUpdateTenantResponse{}, err } @@ -65,7 +65,7 @@ func makeRecipeImplementation(querier supertokens.Querier, config multitenancymo deleteTenant := func(tenantId string, userContext supertokens.UserContext) (multitenancymodels.DeleteTenantResponse, error) { deleteTenantResponse, err := querier.SendPostRequest("/recipe/multitenancy/tenant/remove", map[string]interface{}{ "tenantId": tenantId, - }) + }, userContext) if err != nil { return multitenancymodels.DeleteTenantResponse{}, err } @@ -82,7 +82,7 @@ func makeRecipeImplementation(querier supertokens.Querier, config multitenancymo } getTenant := func(tenantId string, userContext supertokens.UserContext) (*multitenancymodels.Tenant, error) { - tenantResponse, err := querier.SendGetRequest(fmt.Sprintf("/%s/recipe/multitenancy/tenant", tenantId), map[string]string{}) + tenantResponse, err := querier.SendGetRequest(fmt.Sprintf("/%s/recipe/multitenancy/tenant", tenantId), map[string]string{}, userContext) if err != nil { return nil, err } @@ -107,7 +107,7 @@ func makeRecipeImplementation(querier supertokens.Querier, config multitenancymo } listAllTenants := func(userContext supertokens.UserContext) (multitenancymodels.ListAllTenantsResponse, error) { - tenantsResponse, err := querier.SendGetRequest("/recipe/multitenancy/tenant/list", map[string]string{}) + tenantsResponse, err := querier.SendGetRequest("/recipe/multitenancy/tenant/list", map[string]string{}, userContext) if err != nil { return multitenancymodels.ListAllTenantsResponse{}, err } @@ -135,7 +135,7 @@ func makeRecipeImplementation(querier supertokens.Querier, config multitenancymo if skipValidation != nil { requestBody["skipValidation"] = *skipValidation } - response, err := querier.SendPutRequest(fmt.Sprintf("/%s/recipe/multitenancy/config/thirdparty", tenantId), requestBody) + response, err := querier.SendPutRequest(fmt.Sprintf("/%s/recipe/multitenancy/config/thirdparty", tenantId), requestBody, userContext) if err != nil { return multitenancymodels.CreateOrUpdateThirdPartyConfigResponse{}, err } @@ -151,7 +151,7 @@ func makeRecipeImplementation(querier supertokens.Querier, config multitenancymo deleteThirdPartyConfig := func(tenantId string, thirdPartyId string, userContext supertokens.UserContext) (multitenancymodels.DeleteThirdPartyConfigResponse, error) { response, err := querier.SendPostRequest(fmt.Sprintf("/%s/recipe/multitenancy/config/thirdparty/remove", tenantId), map[string]interface{}{ "thirdPartyId": thirdPartyId, - }) + }, userContext) if err != nil { return multitenancymodels.DeleteThirdPartyConfigResponse{}, err } @@ -166,7 +166,7 @@ func makeRecipeImplementation(querier supertokens.Querier, config multitenancymo associateUserToTenant := func(tenantId string, userId string, userContext supertokens.UserContext) (multitenancymodels.AssociateUserToTenantResponse, error) { response, err := querier.SendPostRequest(fmt.Sprintf("/%s/recipe/multitenancy/tenant/user", tenantId), map[string]interface{}{ "userId": userId, - }) + }, userContext) if err != nil { return multitenancymodels.AssociateUserToTenantResponse{}, err } @@ -180,7 +180,7 @@ func makeRecipeImplementation(querier supertokens.Querier, config multitenancymo disassociateUserFromTenant := func(tenantId string, userId string, userContext supertokens.UserContext) (multitenancymodels.DisassociateUserFromTenantResponse, error) { response, err := querier.SendPostRequest(fmt.Sprintf("/%s/recipe/multitenancy/tenant/user/remove", tenantId), map[string]interface{}{ "userId": userId, - }) + }, userContext) if err != nil { return multitenancymodels.DisassociateUserFromTenantResponse{}, err } diff --git a/recipe/passwordless/recipeimplementation.go b/recipe/passwordless/recipeimplementation.go index 28358788..17a9778d 100644 --- a/recipe/passwordless/recipeimplementation.go +++ b/recipe/passwordless/recipeimplementation.go @@ -33,7 +33,7 @@ func MakeRecipeImplementation(querier supertokens.Querier) plessmodels.RecipeInt if userInputCode != nil { body["userInputCode"] = *userInputCode } - response, err := querier.SendPostRequest(tenantId+"/recipe/signinup/code", body) + response, err := querier.SendPostRequest(tenantId+"/recipe/signinup/code", body, userContext) if err != nil { return plessmodels.CreateCodeResponse{}, err } @@ -60,7 +60,7 @@ func MakeRecipeImplementation(querier supertokens.Querier) plessmodels.RecipeInt } else if linkCode != nil { body["linkCode"] = *linkCode } - response, err := querier.SendPostRequest(tenantId+"/recipe/signinup/code/consume", body) + response, err := querier.SendPostRequest(tenantId+"/recipe/signinup/code/consume", body, userContext) if err != nil { return plessmodels.ConsumeCodeResponse{}, err } @@ -112,7 +112,7 @@ func MakeRecipeImplementation(querier supertokens.Querier) plessmodels.RecipeInt body["userInputCode"] = *userInputCode } - response, err := querier.SendPostRequest(tenantId+"/recipe/signinup/code", body) + response, err := querier.SendPostRequest(tenantId+"/recipe/signinup/code", body, userContext) if err != nil { return plessmodels.ResendCodeResponse{}, err } @@ -145,7 +145,7 @@ func MakeRecipeImplementation(querier supertokens.Querier) plessmodels.RecipeInt getUserByEmail := func(email string, tenantId string, userContext supertokens.UserContext) (*plessmodels.User, error) { response, err := querier.SendGetRequest(tenantId+"/recipe/user", map[string]string{ "email": email, - }) + }, userContext) if err != nil { return nil, err } @@ -161,7 +161,7 @@ func MakeRecipeImplementation(querier supertokens.Querier) plessmodels.RecipeInt getUserByID := func(userID string, userContext supertokens.UserContext) (*plessmodels.User, error) { response, err := querier.SendGetRequest("/recipe/user", map[string]string{ "userId": userID, - }) + }, userContext) if err != nil { return nil, err } @@ -177,7 +177,7 @@ func MakeRecipeImplementation(querier supertokens.Querier) plessmodels.RecipeInt getUserByPhoneNumber := func(phoneNumber string, tenantId string, userContext supertokens.UserContext) (*plessmodels.User, error) { response, err := querier.SendGetRequest(tenantId+"/recipe/user", map[string]string{ "phoneNumber": phoneNumber, - }) + }, userContext) if err != nil { return nil, err } @@ -193,7 +193,7 @@ func MakeRecipeImplementation(querier supertokens.Querier) plessmodels.RecipeInt listCodesByDeviceID := func(deviceID string, tenantId string, userContext supertokens.UserContext) (*plessmodels.DeviceType, error) { response, err := querier.SendGetRequest(tenantId+"/recipe/signinup/codes", map[string]string{ "deviceId": deviceID, - }) + }, userContext) if err != nil { return nil, err @@ -211,7 +211,7 @@ func MakeRecipeImplementation(querier supertokens.Querier) plessmodels.RecipeInt listCodesByEmail := func(email string, tenantId string, userContext supertokens.UserContext) ([]plessmodels.DeviceType, error) { response, err := querier.SendGetRequest(tenantId+"/recipe/signinup/codes", map[string]string{ "email": email, - }) + }, userContext) if err != nil { return nil, err @@ -223,7 +223,7 @@ func MakeRecipeImplementation(querier supertokens.Querier) plessmodels.RecipeInt listCodesByPhoneNumber := func(phoneNumber string, tenantId string, userContext supertokens.UserContext) ([]plessmodels.DeviceType, error) { response, err := querier.SendGetRequest(tenantId+"/recipe/signinup/codes", map[string]string{ "phoneNumber": phoneNumber, - }) + }, userContext) if err != nil { return nil, err @@ -235,7 +235,7 @@ func MakeRecipeImplementation(querier supertokens.Querier) plessmodels.RecipeInt listCodesByPreAuthSessionID := func(preAuthSessionID string, tenantId string, userContext supertokens.UserContext) (*plessmodels.DeviceType, error) { response, err := querier.SendGetRequest(tenantId+"/recipe/signinup/codes", map[string]string{ "preAuthSessionId": preAuthSessionID, - }) + }, userContext) if err != nil { return nil, err @@ -257,7 +257,7 @@ func MakeRecipeImplementation(querier supertokens.Querier) plessmodels.RecipeInt } else if phoneNumber != nil { body["phoneNumber"] = *phoneNumber } - _, err := querier.SendPostRequest(tenantId+"/recipe/signinup/codes/remove", body) + _, err := querier.SendPostRequest(tenantId+"/recipe/signinup/codes/remove", body, userContext) if err != nil { return err } @@ -268,7 +268,7 @@ func MakeRecipeImplementation(querier supertokens.Querier) plessmodels.RecipeInt body := map[string]interface{}{ "codeId": codeID, } - _, err := querier.SendPostRequest(tenantId+"/recipe/signinup/code/remove", body) + _, err := querier.SendPostRequest(tenantId+"/recipe/signinup/code/remove", body, userContext) if err != nil { return err } @@ -286,7 +286,7 @@ func MakeRecipeImplementation(querier supertokens.Querier) plessmodels.RecipeInt body["phoneNumber"] = *phoneNumber } - response, err := querier.SendPutRequest("/recipe/user", body) + response, err := querier.SendPutRequest("/recipe/user", body, userContext) if err != nil { return plessmodels.UpdateUserResponse{}, err } @@ -318,7 +318,7 @@ func MakeRecipeImplementation(querier supertokens.Querier) plessmodels.RecipeInt "email": nil, } - response, err := querier.SendPutRequest("/recipe/user", body) + response, err := querier.SendPutRequest("/recipe/user", body, userContext) if err != nil { return plessmodels.DeleteUserResponse{}, err } @@ -344,7 +344,7 @@ func MakeRecipeImplementation(querier supertokens.Querier) plessmodels.RecipeInt "phoneNumber": nil, } - response, err := querier.SendPutRequest("/recipe/user", body) + response, err := querier.SendPutRequest("/recipe/user", body, userContext) if err != nil { return plessmodels.DeleteUserResponse{}, err } diff --git a/recipe/session/accessTokenVersions_test.go b/recipe/session/accessTokenVersions_test.go index da06b1e1..cad413be 100644 --- a/recipe/session/accessTokenVersions_test.go +++ b/recipe/session/accessTokenVersions_test.go @@ -236,7 +236,7 @@ func TestMergeIntoATShouldHelpMigratingV2TokenUsingProtectedProps(t *testing.T) "sub": "asdf", }, "userDataInDatabase": map[string]interface{}{}, - }) + }, nil) if err != nil { t.Error(err.Error()) } @@ -366,7 +366,7 @@ func TestShouldHelpMigratingV2TokenUsingProtectedPropsWhenCalledUsingSessionHand "sub": "asdf", }, "userDataInDatabase": map[string]interface{}{}, - }) + }, nil) if err != nil { t.Error(err.Error()) } @@ -472,7 +472,7 @@ func TestVerifyShouldValidateV2Tokens(t *testing.T) { "sub": "asdf", }, "userDataInDatabase": map[string]interface{}{}, - }) + }, nil) if err != nil { t.Error(err.Error()) } @@ -559,7 +559,7 @@ func TestVerifyShouldValidateV2TokensWithCheckDatabaseEnabled(t *testing.T) { "sub": "asdf", }, "userDataInDatabase": map[string]interface{}{}, - }) + }, nil) if err != nil { t.Error(err.Error()) } @@ -890,7 +890,7 @@ func TestShouldRefreshLegacySessionsToNewVersion(t *testing.T) { "enableAntiCsrf": false, "userDataInJWT": map[string]interface{}{}, "userDataInDatabase": map[string]interface{}{}, - }) + }, nil) if err != nil { t.Error(err.Error()) } @@ -970,7 +970,7 @@ func TestShouldThrowWhenRefreshInLegacySessionsWithProtectedProp(t *testing.T) { "sub": "asdf", }, "userDataInDatabase": map[string]interface{}{}, - }) + }, nil) if err != nil { t.Error(err.Error()) } diff --git a/recipe/session/querier_test.go b/recipe/session/querier_test.go index 6a004110..3348300c 100644 --- a/recipe/session/querier_test.go +++ b/recipe/session/querier_test.go @@ -98,7 +98,7 @@ func TestThatNetworkCallIsRetried(t *testing.T) { t.Error(err.Error()) } - _, err = q.SendGetRequest("/testing", map[string]string{}) + _, err = q.SendGetRequest("/testing", map[string]string{}, nil) if err == nil { t.Error(errors.New("request should have failed but didnt").Error()) } else { @@ -107,12 +107,12 @@ func TestThatNetworkCallIsRetried(t *testing.T) { } } - _, err = q.SendGetRequest("/testing2", map[string]string{}) + _, err = q.SendGetRequest("/testing2", map[string]string{}, nil) if err != nil { t.Error(err.Error()) } - _, err = q.SendGetRequest("/testing3", map[string]string{}) + _, err = q.SendGetRequest("/testing3", map[string]string{}, nil) if err != nil { t.Error(err.Error()) } @@ -174,7 +174,7 @@ func TestThatRateLimitErrorsAreThrownBackToTheUser(t *testing.T) { t.Error(err.Error()) } - _, err = q.SendGetRequest("/testing", map[string]string{}) + _, err = q.SendGetRequest("/testing", map[string]string{}, nil) if err == nil { t.Error(errors.New("request should have failed but didnt").Error()) } else { @@ -251,7 +251,7 @@ func TestThatParallelCallsHaveIndependentRetryCounters(t *testing.T) { go func() { _, err = q.SendGetRequest("/testing", map[string]string{ "id": "1", - }) + }, nil) if err == nil { t.Error(errors.New("request should have failed but didnt").Error()) } else { @@ -266,7 +266,7 @@ func TestThatParallelCallsHaveIndependentRetryCounters(t *testing.T) { go func() { _, err = q.SendGetRequest("/testing", map[string]string{ "id": "2", - }) + }, nil) if err == nil { t.Error(errors.New("request should have failed but didnt").Error()) } else { diff --git a/recipe/session/recipeImplementation.go b/recipe/session/recipeImplementation.go index d582d0d4..8f8ce68f 100644 --- a/recipe/session/recipeImplementation.go +++ b/recipe/session/recipeImplementation.go @@ -153,7 +153,7 @@ func MakeRecipeImplementation(querier supertokens.Querier, config sessmodels.Typ supertokens.LogDebugMessage("createNewSession: Started") sessionResponse, err := createNewSessionHelper( - config, querier, userID, disableAntiCsrf != nil && *disableAntiCsrf == true, accessTokenPayload, sessionDataInDatabase, tenantId, + config, querier, userID, disableAntiCsrf != nil && *disableAntiCsrf == true, accessTokenPayload, sessionDataInDatabase, tenantId, userContext, ) if err != nil { return nil, err @@ -242,7 +242,7 @@ func MakeRecipeImplementation(querier supertokens.Querier, config sessmodels.Typ doAntiCsrfCheck = false } - response, err := getSessionHelper(config, querier, *accessToken, antiCsrfToken, doAntiCsrfCheck, alwaysCheckCore) + response, err := getSessionHelper(config, querier, *accessToken, antiCsrfToken, doAntiCsrfCheck, alwaysCheckCore, userContext) if err != nil { return nil, err } @@ -284,7 +284,7 @@ func MakeRecipeImplementation(querier supertokens.Querier, config sessmodels.Typ } getSessionInformation := func(sessionHandle string, userContext supertokens.UserContext) (*sessmodels.SessionInformation, error) { - return getSessionInformationHelper(querier, sessionHandle) + return getSessionInformationHelper(querier, sessionHandle, userContext) } refreshSession := func(refreshToken string, antiCsrfToken *string, disableAntiCsrf bool, userContext supertokens.UserContext) (sessmodels.SessionContainer, error) { @@ -294,7 +294,7 @@ func MakeRecipeImplementation(querier supertokens.Querier, config sessmodels.Typ supertokens.LogDebugMessage("refreshSession: Started") - response, err := refreshSessionHelper(config, querier, refreshToken, antiCsrfToken, disableAntiCsrf) + response, err := refreshSessionHelper(config, querier, refreshToken, antiCsrfToken, disableAntiCsrf, userContext) if err != nil { return nil, err } @@ -315,27 +315,27 @@ func MakeRecipeImplementation(querier supertokens.Querier, config sessmodels.Typ } revokeAllSessionsForUser := func(userID string, tenantId string, revokeAcrossAllTenants *bool, userContext supertokens.UserContext) ([]string, error) { - return revokeAllSessionsForUserHelper(querier, userID, tenantId, revokeAcrossAllTenants) + return revokeAllSessionsForUserHelper(querier, userID, tenantId, revokeAcrossAllTenants, userContext) } getAllSessionHandlesForUser := func(userID string, tenantId string, fetchAcrossAllTenants *bool, userContext supertokens.UserContext) ([]string, error) { - return getAllSessionHandlesForUserHelper(querier, userID, tenantId, fetchAcrossAllTenants) + return getAllSessionHandlesForUserHelper(querier, userID, tenantId, fetchAcrossAllTenants, userContext) } revokeSession := func(sessionHandle string, userContext supertokens.UserContext) (bool, error) { - return revokeSessionHelper(querier, sessionHandle) + return revokeSessionHelper(querier, sessionHandle, userContext) } revokeMultipleSessions := func(sessionHandles []string, userContext supertokens.UserContext) ([]string, error) { - return revokeMultipleSessionsHelper(querier, sessionHandles) + return revokeMultipleSessionsHelper(querier, sessionHandles, userContext) } updateSessionDataInDatabase := func(sessionHandle string, newSessionData map[string]interface{}, userContext supertokens.UserContext) (bool, error) { - return updateSessionDataInDatabaseHelper(querier, sessionHandle, newSessionData) + return updateSessionDataInDatabaseHelper(querier, sessionHandle, newSessionData, userContext) } regenerateAccessToken := func(accessToken string, newAccessTokenPayload *map[string]interface{}, userContext supertokens.UserContext) (*sessmodels.RegenerateAccessTokenResponse, error) { - return regenerateAccessTokenHelper(querier, newAccessTokenPayload, accessToken) + return regenerateAccessTokenHelper(querier, newAccessTokenPayload, accessToken, userContext) } mergeIntoAccessTokenPayload := func(sessionHandle string, accessTokenPayloadUpdate map[string]interface{}, userContext supertokens.UserContext) (bool, error) { @@ -365,7 +365,7 @@ func MakeRecipeImplementation(querier supertokens.Querier, config sessmodels.Typ } } - return updateAccessTokenPayloadHelper(querier, sessionHandle, newAccessTokenPayload) + return updateAccessTokenPayloadHelper(querier, sessionHandle, newAccessTokenPayload, userContext) } getGlobalClaimValidators := func(userId string, claimValidatorsAddedByOtherRecipes []claims.SessionClaimValidator, tenantId string, userContext supertokens.UserContext) ([]claims.SessionClaimValidator, error) { diff --git a/recipe/session/sessionFunctions.go b/recipe/session/sessionFunctions.go index d229700b..363d97aa 100644 --- a/recipe/session/sessionFunctions.go +++ b/recipe/session/sessionFunctions.go @@ -26,7 +26,7 @@ import ( "github.com/supertokens/supertokens-golang/supertokens" ) -func createNewSessionHelper(config sessmodels.TypeNormalisedInput, querier supertokens.Querier, userID string, disableAntiCsrf bool, AccessTokenPayload, sessionDataInDatabase map[string]interface{}, tenantId string) (sessmodels.CreateOrRefreshAPIResponse, error) { +func createNewSessionHelper(config sessmodels.TypeNormalisedInput, querier supertokens.Querier, userID string, disableAntiCsrf bool, AccessTokenPayload, sessionDataInDatabase map[string]interface{}, tenantId string, userContext supertokens.UserContext) (sessmodels.CreateOrRefreshAPIResponse, error) { if AccessTokenPayload == nil { AccessTokenPayload = map[string]interface{}{} } @@ -41,7 +41,7 @@ func createNewSessionHelper(config sessmodels.TypeNormalisedInput, querier super "useDynamicSigningKey": config.UseDynamicAccessTokenSigningKey, } - response, err := querier.SendPostRequest(tenantId+"/recipe/session", requestBody) + response, err := querier.SendPostRequest(tenantId+"/recipe/session", requestBody, userContext) if err != nil { return sessmodels.CreateOrRefreshAPIResponse{}, err } @@ -59,7 +59,7 @@ func createNewSessionHelper(config sessmodels.TypeNormalisedInput, querier super return resp, nil } -func getSessionHelper(config sessmodels.TypeNormalisedInput, querier supertokens.Querier, parsedAccessToken sessmodels.ParsedJWTInfo, antiCsrfToken *string, doAntiCsrfCheck, alwaysCheckCore bool) (sessmodels.GetSessionResponse, error) { +func getSessionHelper(config sessmodels.TypeNormalisedInput, querier supertokens.Querier, parsedAccessToken sessmodels.ParsedJWTInfo, antiCsrfToken *string, doAntiCsrfCheck, alwaysCheckCore bool, userContext supertokens.UserContext) (sessmodels.GetSessionResponse, error) { var accessTokenInfo *AccessTokenInfoStruct = nil var err error = nil combinedJwks, jwksError := GetCombinedJWKS() @@ -162,7 +162,7 @@ func getSessionHelper(config sessmodels.TypeNormalisedInput, querier supertokens if supertokens.IsRunningInTestMode() { didGetSessionCallCore = true } - response, err := querier.SendPostRequest("/recipe/session/verify", requestBody) + response, err := querier.SendPostRequest("/recipe/session/verify", requestBody, userContext) if err != nil { return sessmodels.GetSessionResponse{}, err } @@ -202,11 +202,11 @@ func getSessionHelper(config sessmodels.TypeNormalisedInput, querier supertokens } } -func getSessionInformationHelper(querier supertokens.Querier, sessionHandle string) (*sessmodels.SessionInformation, error) { +func getSessionInformationHelper(querier supertokens.Querier, sessionHandle string, userContext supertokens.UserContext) (*sessmodels.SessionInformation, error) { response, err := querier.SendGetRequest("/recipe/session", map[string]string{ "sessionHandle": sessionHandle, - }) + }, userContext) if err != nil { return nil, err } @@ -224,7 +224,7 @@ func getSessionInformationHelper(querier supertokens.Querier, sessionHandle stri return nil, nil } -func refreshSessionHelper(config sessmodels.TypeNormalisedInput, querier supertokens.Querier, refreshToken string, antiCsrfToken *string, disableAntiCsrf bool) (sessmodels.CreateOrRefreshAPIResponse, error) { +func refreshSessionHelper(config sessmodels.TypeNormalisedInput, querier supertokens.Querier, refreshToken string, antiCsrfToken *string, disableAntiCsrf bool, userContext supertokens.UserContext) (sessmodels.CreateOrRefreshAPIResponse, error) { requestBody := map[string]interface{}{ "refreshToken": refreshToken, "enableAntiCsrf": !disableAntiCsrf && config.AntiCsrf == AntiCSRF_VIA_TOKEN, @@ -237,7 +237,7 @@ func refreshSessionHelper(config sessmodels.TypeNormalisedInput, querier superto return sessmodels.CreateOrRefreshAPIResponse{}, defaultErrors.New("Please either use VIA_TOKEN, NONE or call with doAntiCsrfCheck false") } - response, err := querier.SendPostRequest("/recipe/session/refresh", requestBody) + response, err := querier.SendPostRequest("/recipe/session/refresh", requestBody, userContext) if err != nil { return sessmodels.CreateOrRefreshAPIResponse{}, err } @@ -270,14 +270,14 @@ func refreshSessionHelper(config sessmodels.TypeNormalisedInput, querier superto } } -func revokeAllSessionsForUserHelper(querier supertokens.Querier, userID string, tenantId string, revokeAcrossAllTenants *bool) ([]string, error) { +func revokeAllSessionsForUserHelper(querier supertokens.Querier, userID string, tenantId string, revokeAcrossAllTenants *bool, userContext supertokens.UserContext) ([]string, error) { requestBody := map[string]interface{}{ "userId": userID, } if revokeAcrossAllTenants != nil { requestBody["revokeAcrossAllTenants"] = *revokeAcrossAllTenants } - response, err := querier.SendPostRequest(tenantId+"/recipe/session/remove", requestBody) + response, err := querier.SendPostRequest(tenantId+"/recipe/session/remove", requestBody, userContext) if err != nil { return nil, err } @@ -293,14 +293,14 @@ func revokeAllSessionsForUserHelper(querier supertokens.Querier, userID string, return result, nil } -func getAllSessionHandlesForUserHelper(querier supertokens.Querier, userID string, tenantId string, fetchAcrossAllTenants *bool) ([]string, error) { +func getAllSessionHandlesForUserHelper(querier supertokens.Querier, userID string, tenantId string, fetchAcrossAllTenants *bool, userContext supertokens.UserContext) ([]string, error) { queryParams := map[string]string{ "userId": userID, } if fetchAcrossAllTenants != nil { queryParams["fetchAcrossAllTenants"] = strings.ToLower(fmt.Sprintf("%v", *fetchAcrossAllTenants)) } - response, err := querier.SendGetRequest("/recipe/session/user", queryParams) + response, err := querier.SendGetRequest("/recipe/session/user", queryParams, userContext) if err != nil { return nil, err } @@ -316,22 +316,22 @@ func getAllSessionHandlesForUserHelper(querier supertokens.Querier, userID strin return result, nil } -func revokeSessionHelper(querier supertokens.Querier, sessionHandle string) (bool, error) { +func revokeSessionHelper(querier supertokens.Querier, sessionHandle string, userContext supertokens.UserContext) (bool, error) { response, err := querier.SendPostRequest("/recipe/session/remove", map[string]interface{}{ "sessionHandles": [1]string{sessionHandle}, - }) + }, userContext) if err != nil { return false, err } return len(response["sessionHandlesRevoked"].([]interface{})) == 1, nil } -func revokeMultipleSessionsHelper(querier supertokens.Querier, sessionHandles []string) ([]string, error) { +func revokeMultipleSessionsHelper(querier supertokens.Querier, sessionHandles []string, userContext supertokens.UserContext) ([]string, error) { response, err := querier.SendPostRequest("/recipe/session/remove", map[string]interface{}{ "sessionHandles": sessionHandles, - }) + }, userContext) if err != nil { return nil, err } @@ -346,7 +346,7 @@ func revokeMultipleSessionsHelper(querier supertokens.Querier, sessionHandles [] return result, nil } -func updateSessionDataInDatabaseHelper(querier supertokens.Querier, sessionHandle string, newSessionData map[string]interface{}) (bool, error) { +func updateSessionDataInDatabaseHelper(querier supertokens.Querier, sessionHandle string, newSessionData map[string]interface{}, userContext supertokens.UserContext) (bool, error) { if newSessionData == nil { newSessionData = map[string]interface{}{} } @@ -354,7 +354,7 @@ func updateSessionDataInDatabaseHelper(querier supertokens.Querier, sessionHandl map[string]interface{}{ "sessionHandle": sessionHandle, "userDataInDatabase": newSessionData, - }) + }, userContext) if err != nil { return false, err } @@ -364,14 +364,14 @@ func updateSessionDataInDatabaseHelper(querier supertokens.Querier, sessionHandl return true, nil } -func updateAccessTokenPayloadHelper(querier supertokens.Querier, sessionHandle string, newAccessTokenPayload map[string]interface{}) (bool, error) { +func updateAccessTokenPayloadHelper(querier supertokens.Querier, sessionHandle string, newAccessTokenPayload map[string]interface{}, userContext supertokens.UserContext) (bool, error) { if newAccessTokenPayload == nil { newAccessTokenPayload = map[string]interface{}{} } response, err := querier.SendPutRequest("/recipe/jwt/data", map[string]interface{}{ "sessionHandle": sessionHandle, "userDataInJWT": newAccessTokenPayload, - }) + }, userContext) if err != nil { return false, err } @@ -381,14 +381,14 @@ func updateAccessTokenPayloadHelper(querier supertokens.Querier, sessionHandle s return true, nil } -func regenerateAccessTokenHelper(querier supertokens.Querier, newAccessTokenPayload *map[string]interface{}, accessToken string) (*sessmodels.RegenerateAccessTokenResponse, error) { +func regenerateAccessTokenHelper(querier supertokens.Querier, newAccessTokenPayload *map[string]interface{}, accessToken string, userContext supertokens.UserContext) (*sessmodels.RegenerateAccessTokenResponse, error) { if newAccessTokenPayload == nil { newAccessTokenPayload = &map[string]interface{}{} } response, err := querier.SendPostRequest("/recipe/session/regenerate", map[string]interface{}{ "accessToken": accessToken, "userDataInJWT": newAccessTokenPayload, - }) + }, userContext) if err != nil { return nil, err } diff --git a/recipe/thirdparty/recipeImplementation.go b/recipe/thirdparty/recipeImplementation.go index 43937ffe..b499b7ca 100644 --- a/recipe/thirdparty/recipeImplementation.go +++ b/recipe/thirdparty/recipeImplementation.go @@ -51,7 +51,7 @@ func MakeRecipeImplementation(querier supertokens.Querier, providers []tpmodels. "thirdPartyId": thirdPartyID, "thirdPartyUserId": thirdPartyUserID, "email": map[string]interface{}{"id": email}, - }) + }, userContext) if err != nil { return tpmodels.SignInUpResponse{}, err } @@ -79,7 +79,7 @@ func MakeRecipeImplementation(querier supertokens.Querier, providers []tpmodels. "thirdPartyId": thirdPartyID, "thirdPartyUserId": thirdPartyUserID, "email": map[string]interface{}{"id": email}, - }) + }, userContext) if err != nil { return tpmodels.ManuallyCreateOrUpdateUserResponse{}, err } @@ -101,7 +101,7 @@ func MakeRecipeImplementation(querier supertokens.Querier, providers []tpmodels. getUserByID := func(userID string, userContext supertokens.UserContext) (*tpmodels.User, error) { response, err := querier.SendGetRequest("/recipe/user", map[string]string{ "userId": userID, - }) + }, userContext) if err != nil { return nil, err } @@ -119,7 +119,7 @@ func MakeRecipeImplementation(querier supertokens.Querier, providers []tpmodels. response, err := querier.SendGetRequest(tenantId+"/recipe/user", map[string]string{ "thirdPartyId": thirdPartyID, "thirdPartyUserId": thirdPartyUserID, - }) + }, userContext) if err != nil { return nil, err } @@ -136,7 +136,7 @@ func MakeRecipeImplementation(querier supertokens.Querier, providers []tpmodels. getUsersByEmail := func(email string, tenantId string, userContext supertokens.UserContext) ([]tpmodels.User, error) { response, err := querier.SendGetRequest(tenantId+"/recipe/users/by-email", map[string]string{ "email": email, - }) + }, userContext) if err != nil { return []tpmodels.User{}, err } diff --git a/recipe/usermetadata/recipeimplementation.go b/recipe/usermetadata/recipeimplementation.go index 5f15bbc6..37e51b56 100644 --- a/recipe/usermetadata/recipeimplementation.go +++ b/recipe/usermetadata/recipeimplementation.go @@ -24,7 +24,7 @@ func makeRecipeImplementation(querier supertokens.Querier, config usermetadatamo getUserMetadata := func(userID string, userContext supertokens.UserContext) (map[string]interface{}, error) { response, err := querier.SendGetRequest("/recipe/user/metadata", map[string]string{ "userId": userID, - }) + }, userContext) if err != nil { return map[string]interface{}{}, err } @@ -36,7 +36,7 @@ func makeRecipeImplementation(querier supertokens.Querier, config usermetadatamo response, err := querier.SendPutRequest("/recipe/user/metadata", map[string]interface{}{ "userId": userID, "metadataUpdate": metadataUpdate, - }) + }, userContext) if err != nil { return map[string]interface{}{}, err } @@ -47,7 +47,7 @@ func makeRecipeImplementation(querier supertokens.Querier, config usermetadatamo clearUserMetadata := func(userID string, userContext supertokens.UserContext) error { _, err := querier.SendPostRequest("/recipe/user/metadata/remove", map[string]interface{}{ "userId": userID, - }) + }, userContext) return err } diff --git a/recipe/userroles/recipeimplementation.go b/recipe/userroles/recipeimplementation.go index 59ed1854..b77fa5db 100644 --- a/recipe/userroles/recipeimplementation.go +++ b/recipe/userroles/recipeimplementation.go @@ -26,7 +26,7 @@ func makeRecipeImplementation(querier supertokens.Querier, config userrolesmodel response, err := querier.SendPutRequest(tenantId+"/recipe/user/role", map[string]interface{}{ "userId": userID, "role": role, - }) + }, userContext) if err != nil { return userrolesmodels.AddRoleToUserResponse{}, err } @@ -48,7 +48,7 @@ func makeRecipeImplementation(querier supertokens.Querier, config userrolesmodel response, err := querier.SendPostRequest(tenantId+"/recipe/user/role/remove", map[string]interface{}{ "userId": userID, "role": role, - }) + }, userContext) if err != nil { return userrolesmodels.RemoveUserRoleResponse{}, err } @@ -69,7 +69,7 @@ func makeRecipeImplementation(querier supertokens.Querier, config userrolesmodel getRolesForUser := func(userID string, tenantId string, userContext supertokens.UserContext) (userrolesmodels.GetRolesForUserResponse, error) { response, err := querier.SendGetRequest(tenantId+"/recipe/user/roles", map[string]string{ "userId": userID, - }) + }, userContext) if err != nil { return userrolesmodels.GetRolesForUserResponse{}, err } @@ -85,7 +85,7 @@ func makeRecipeImplementation(querier supertokens.Querier, config userrolesmodel getUsersThatHaveRole := func(role string, tenantId string, userContext supertokens.UserContext) (userrolesmodels.GetUsersThatHaveRoleResponse, error) { response, err := querier.SendGetRequest(tenantId+"/recipe/role/users", map[string]string{ "role": role, - }) + }, userContext) if err != nil { return userrolesmodels.GetUsersThatHaveRoleResponse{}, err } @@ -107,7 +107,7 @@ func makeRecipeImplementation(querier supertokens.Querier, config userrolesmodel response, err := querier.SendPutRequest("/recipe/role", map[string]interface{}{ "role": role, "permissions": permissions, - }) + }, userContext) if err != nil { return userrolesmodels.CreateNewRoleOrAddPermissionsResponse{}, err } @@ -122,7 +122,7 @@ func makeRecipeImplementation(querier supertokens.Querier, config userrolesmodel getPermissionsForRole := func(role string, userContext supertokens.UserContext) (userrolesmodels.GetPermissionsForRoleResponse, error) { response, err := querier.SendGetRequest("/recipe/role/permissions", map[string]string{ "role": role, - }) + }, userContext) if err != nil { return userrolesmodels.GetPermissionsForRoleResponse{}, err } @@ -144,7 +144,7 @@ func makeRecipeImplementation(querier supertokens.Querier, config userrolesmodel response, err := querier.SendPostRequest("/recipe/role/permissions/remove", map[string]interface{}{ "role": role, "permissions": permissions, - }) + }, userContext) if err != nil { return userrolesmodels.RemovePermissionsFromRoleResponse{}, err } @@ -163,7 +163,7 @@ func makeRecipeImplementation(querier supertokens.Querier, config userrolesmodel getRolesThatHavePermission := func(permission string, userContext supertokens.UserContext) (userrolesmodels.GetRolesThatHavePermissionResponse, error) { response, err := querier.SendGetRequest("/recipe/permission/roles", map[string]string{ "permission": permission, - }) + }, userContext) if err != nil { return userrolesmodels.GetRolesThatHavePermissionResponse{}, err } @@ -178,7 +178,7 @@ func makeRecipeImplementation(querier supertokens.Querier, config userrolesmodel deleteRole := func(role string, userContext supertokens.UserContext) (userrolesmodels.DeleteRoleResponse, error) { response, err := querier.SendPostRequest("/recipe/role/remove", map[string]interface{}{ "role": role, - }) + }, userContext) if err != nil { return userrolesmodels.DeleteRoleResponse{}, err } @@ -191,7 +191,7 @@ func makeRecipeImplementation(querier supertokens.Querier, config userrolesmodel } getAllRoles := func(userContext supertokens.UserContext) (userrolesmodels.GetAllRolesResponse, error) { - response, err := querier.SendGetRequest("/recipe/roles", map[string]string{}) + response, err := querier.SendGetRequest("/recipe/roles", map[string]string{}, userContext) if err != nil { return userrolesmodels.GetAllRolesResponse{}, err } diff --git a/supertokens/querier.go b/supertokens/querier.go index ec6d8aa7..a9b6d265 100644 --- a/supertokens/querier.go +++ b/supertokens/querier.go @@ -114,7 +114,7 @@ func initQuerier(hosts []QuerierHost, APIKey string, interceptor func(*http.Requ } } -func (q *Querier) SendPostRequest(path string, data map[string]interface{}) (map[string]interface{}, error) { +func (q *Querier) SendPostRequest(path string, data map[string]interface{}, userContext UserContext) (map[string]interface{}, error) { nP, err := NewNormalisedURLPath(path) if err != nil { return nil, err @@ -147,7 +147,7 @@ func (q *Querier) SendPostRequest(path string, data map[string]interface{}) (map } if querierInterceptor != nil { - req = querierInterceptor(req, nil) + req = querierInterceptor(req, userContext) } client := &http.Client{} @@ -156,7 +156,7 @@ func (q *Querier) SendPostRequest(path string, data map[string]interface{}) (map return resp, err } -func (q *Querier) SendDeleteRequest(path string, data map[string]interface{}, params map[string]string) (map[string]interface{}, error) { +func (q *Querier) SendDeleteRequest(path string, data map[string]interface{}, params map[string]string, userContext UserContext) (map[string]interface{}, error) { nP, err := NewNormalisedURLPath(path) if err != nil { return nil, err @@ -193,7 +193,7 @@ func (q *Querier) SendDeleteRequest(path string, data map[string]interface{}, pa } if querierInterceptor != nil { - req = querierInterceptor(req, nil) + req = querierInterceptor(req, userContext) } client := &http.Client{} @@ -202,7 +202,7 @@ func (q *Querier) SendDeleteRequest(path string, data map[string]interface{}, pa return resp, err } -func (q *Querier) SendGetRequest(path string, params map[string]string) (map[string]interface{}, error) { +func (q *Querier) SendGetRequest(path string, params map[string]string, userContext UserContext) (map[string]interface{}, error) { nP, err := NewNormalisedURLPath(path) if err != nil { return nil, err @@ -233,7 +233,7 @@ func (q *Querier) SendGetRequest(path string, params map[string]string) (map[str } if querierInterceptor != nil { - req = querierInterceptor(req, nil) + req = querierInterceptor(req, userContext) } client := &http.Client{} @@ -242,7 +242,7 @@ func (q *Querier) SendGetRequest(path string, params map[string]string) (map[str return resp, err } -func (q *Querier) SendGetRequestWithResponseHeaders(path string, params map[string]string) (map[string]interface{}, http.Header, error) { +func (q *Querier) SendGetRequestWithResponseHeaders(path string, params map[string]string, userContext UserContext) (map[string]interface{}, http.Header, error) { nP, err := NewNormalisedURLPath(path) if err != nil { return nil, nil, err @@ -274,7 +274,7 @@ func (q *Querier) SendGetRequestWithResponseHeaders(path string, params map[stri } if querierInterceptor != nil { - req = querierInterceptor(req, nil) + req = querierInterceptor(req, userContext) } client := &http.Client{} @@ -282,7 +282,7 @@ func (q *Querier) SendGetRequestWithResponseHeaders(path string, params map[stri }, len(QuerierHosts), nil) } -func (q *Querier) SendPutRequest(path string, data map[string]interface{}) (map[string]interface{}, error) { +func (q *Querier) SendPutRequest(path string, data map[string]interface{}, userContext UserContext) (map[string]interface{}, error) { nP, err := NewNormalisedURLPath(path) if err != nil { return nil, err @@ -312,7 +312,7 @@ func (q *Querier) SendPutRequest(path string, data map[string]interface{}) (map[ } if querierInterceptor != nil { - req = querierInterceptor(req, nil) + req = querierInterceptor(req, userContext) } client := &http.Client{} diff --git a/supertokens/supertokens.go b/supertokens/supertokens.go index 9c209f38..a846e82f 100644 --- a/supertokens/supertokens.go +++ b/supertokens/supertokens.go @@ -330,7 +330,7 @@ func GetUsersWithSearchParams(tenantId string, timeJoinedOrder string, paginatio requestBody["includeRecipeIds"] = strings.Join((*includeRecipeIds)[:], ",") } - resp, err := querier.SendGetRequest(tenantId+"/users", requestBody) + resp, err := querier.SendGetRequest(tenantId+"/users", requestBody, nil) if err != nil { return UserPaginationResult{}, err @@ -369,7 +369,7 @@ func getUserCount(includeRecipeIds *[]string, tenantId string, includeAllTenants requestBody["includeAllTenants"] = strconv.FormatBool(*includeAllTenants) } - resp, err := querier.SendGetRequest(tenantId+"/users/count", requestBody) + resp, err := querier.SendGetRequest(tenantId+"/users/count", requestBody, nil) if err != nil { return -1, err @@ -392,7 +392,7 @@ func deleteUser(userId string) error { if MaxVersion(cdiVersion, "2.10") == cdiVersion { _, err = querier.SendPostRequest("/user/remove", map[string]interface{}{ "userId": userId, - }) + }, nil) if err != nil { return err diff --git a/supertokens/userIdMapping.go b/supertokens/userIdMapping.go index b3811ec5..8c18aa91 100644 --- a/supertokens/userIdMapping.go +++ b/supertokens/userIdMapping.go @@ -44,7 +44,7 @@ func CreateUserIdMapping(supertokensUserId string, externalUserId string, extern if externalUserIdInfo != nil { data["externalUserIdInfo"] = *externalUserIdInfo } - resp, err := querier.SendPostRequest("/recipe/userid/map", data) + resp, err := querier.SendPostRequest("/recipe/userid/map", data, nil) if err != nil { return CreateUserIdMappingResult{}, err } @@ -98,7 +98,7 @@ func GetUserIdMapping(userId string, userIdType *UserIdType) (GetUserIdMappingRe if userIdType != nil { data["userIdType"] = string(*userIdType) } - resp, err := querier.SendGetRequest("/recipe/userid/map", data) + resp, err := querier.SendGetRequest("/recipe/userid/map", data, nil) if err != nil { return GetUserIdMappingResult{}, err } @@ -153,7 +153,7 @@ func DeleteUserIdMapping(userId string, userIdType *UserIdType, force *bool) (De if force != nil { data["force"] = *force } - resp, err := querier.SendPostRequest("/recipe/userid/map/remove", data) + resp, err := querier.SendPostRequest("/recipe/userid/map/remove", data, nil) if err != nil { return DeleteUserIdMappingResult{}, err } @@ -190,7 +190,7 @@ func UpdateOrDeleteUserIdMappingInfo(userId string, userIdType *UserIdType, exte data["userIdType"] = string(*userIdType) } - resp, err := querier.SendPutRequest("/recipe/userid/external-user-id-info", data) + resp, err := querier.SendPutRequest("/recipe/userid/external-user-id-info", data, nil) if err != nil { return UpdateOrDeleteUserIdMappingInfoResult{}, err } diff --git a/test/frontendIntegration/main.go b/test/frontendIntegration/main.go index 29e2c13a..8c6085f7 100644 --- a/test/frontendIntegration/main.go +++ b/test/frontendIntegration/main.go @@ -540,7 +540,7 @@ func login218(response http.ResponseWriter, request *http.Request) { "userDataInJWT": payload, "userDataInDatabase": map[string]interface{}{}, "enableAntiCsrf": false, - }) + }, nil) if err != nil { response.WriteHeader(500)