From 83e5b920b52b451147a09128b2427a2ab5f82c05 Mon Sep 17 00:00:00 2001 From: Nemi Shah Date: Wed, 20 Sep 2023 11:17:29 +0530 Subject: [PATCH 01/13] Fix logic to handle AWS public URLS --- recipe/session/config_test.go | 81 +++++++++++++++++++++++++++++++++++ supertokens/utils.go | 14 ++++++ 2 files changed, 95 insertions(+) diff --git a/recipe/session/config_test.go b/recipe/session/config_test.go index 503d2d29..ab68b6e1 100644 --- a/recipe/session/config_test.go +++ b/recipe/session/config_test.go @@ -1215,3 +1215,84 @@ func TestThatJWKSAndOpenIdEndpointsAreExposed(t *testing.T) { assert.NotNil(t, openIdAPI) assert.Equal(t, openIdAPI.PathWithoutAPIBasePath.GetAsStringDangerous(), "/.well-known/openid-configuration") } + +func TestCookieSameSiteWithEC2PublicURL(t *testing.T) { + apiBasePath := "/" + configValue := supertokens.TypeInput{ + Supertokens: &supertokens.ConnectionInfo{ + ConnectionURI: "http://localhost:8080", + }, + AppInfo: supertokens.AppInfo{ + AppName: "SuperTokens", + APIDomain: "https://ec2-xx-yyy-zzz-0.compute-1.amazonaws.com:3001", + WebsiteDomain: "https://blog.supertokens.com", + APIBasePath: &apiBasePath, + }, + RecipeList: []supertokens.Recipe{ + Init(&sessmodels.TypeInput{ + GetTokenTransferMethod: func(req *http.Request, forCreateNewSession bool, userContext supertokens.UserContext) sessmodels.TokenTransferMethod { + return sessmodels.CookieTransferMethod + }, + }), + }, + } + + BeforeEach() + + unittesting.StartUpST("localhost", "8080") + + defer AfterEach() + + err := supertokens.Init(configValue) + + if err != nil { + t.Error(err.Error()) + } + + recipe, err := getRecipeInstanceOrThrowError() + + if err != nil { + t.Error(err.Error()) + } + + assert.True(t, recipe.Config.CookieDomain == nil) + assert.Equal(t, recipe.Config.CookieSameSite, "none") + assert.True(t, recipe.Config.CookieSecure) + + resetAll() + + configValue = supertokens.TypeInput{ + Supertokens: &supertokens.ConnectionInfo{ + ConnectionURI: "http://localhost:8080", + }, + AppInfo: supertokens.AppInfo{ + AppName: "SuperTokens", + APIDomain: "http://ec2-xx-yyy-zzz-0.compute-1.amazonaws.com:3001", + WebsiteDomain: "http://ec2-xx-yyy-zzz-0.compute-1.amazonaws.com:3000", + APIBasePath: &apiBasePath, + }, + RecipeList: []supertokens.Recipe{ + Init(&sessmodels.TypeInput{ + GetTokenTransferMethod: func(req *http.Request, forCreateNewSession bool, userContext supertokens.UserContext) sessmodels.TokenTransferMethod { + return sessmodels.CookieTransferMethod + }, + }), + }, + } + + err = supertokens.Init(configValue) + + if err != nil { + t.Error(err.Error()) + } + + recipe, err = getRecipeInstanceOrThrowError() + + if err != nil { + t.Error(err.Error()) + } + + assert.True(t, recipe.Config.CookieDomain == nil) + assert.Equal(t, recipe.Config.CookieSameSite, "lax") + assert.False(t, recipe.Config.CookieSecure) +} diff --git a/supertokens/utils.go b/supertokens/utils.go index 9cc4f51f..8b4ce683 100644 --- a/supertokens/utils.go +++ b/supertokens/utils.go @@ -318,6 +318,20 @@ func GetTopLevelDomainForSameSiteResolution(URL string) (string, error) { if strings.HasPrefix(hostname, "localhost") || strings.HasPrefix(hostname, "localhost.org") || isAnIP { return "localhost", nil } + + /** + EffectiveTLDPlusOne fails if the TLD and the input domain are the same which is true in the case of some aws URLS + which are listedhere: https://publicsuffix.org/list/public_suffix_list.dat + + Instead, we use PublicSuffix to get the parsed suffix. EffectiveTLDPlusOne internally uses PublicSuffix + */ + _publicSuffix, _ := publicsuffix.PublicSuffix(hostname) + + // This check is added because of this issue: https://github.com/supertokens/supertokens-python/issues/394 + if strings.HasSuffix(hostname, ".amazonaws.com") && strings.HasSuffix(_publicSuffix, hostname) { + return hostname, nil + } + parsedURL, err := publicsuffix.EffectiveTLDPlusOne(hostname) if err != nil { return "", errors.New("Please make sure that the apiDomain and websiteDomain have correct values") From b93697b098fe5752c2868469f75c586f990cf188 Mon Sep 17 00:00:00 2001 From: Nemi Shah Date: Wed, 20 Sep 2023 11:28:16 +0530 Subject: [PATCH 02/13] Update CHANGELOG --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index dd41c2d7..bd033865 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [unreleased] +- Handle AWS Public URLs (ending with `.amazonaws.com`) separately while extracting TLDs for SameSite attribute. + ## [0.14.0] - 2023-09-11 ### Added From 054a3d1a0e41713e73a8bde33300ae6e51e56534 Mon Sep 17 00:00:00 2001 From: Nemi Shah Date: Wed, 20 Sep 2023 11:44:43 +0530 Subject: [PATCH 03/13] Update CHANGELOG --- supertokens/utils.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/supertokens/utils.go b/supertokens/utils.go index 8b4ce683..f0e8c027 100644 --- a/supertokens/utils.go +++ b/supertokens/utils.go @@ -328,7 +328,7 @@ func GetTopLevelDomainForSameSiteResolution(URL string) (string, error) { _publicSuffix, _ := publicsuffix.PublicSuffix(hostname) // This check is added because of this issue: https://github.com/supertokens/supertokens-python/issues/394 - if strings.HasSuffix(hostname, ".amazonaws.com") && strings.HasSuffix(_publicSuffix, hostname) { + if strings.HasSuffix(hostname, ".amazonaws.com") && _publicSuffix == hostname { return hostname, nil } From 4aa09a463d9b8ab7ffe14ff695108200a7bc0b62 Mon Sep 17 00:00:00 2001 From: Nemi Shah Date: Fri, 22 Sep 2023 13:02:56 +0530 Subject: [PATCH 04/13] Update logic of get jwks to include cache control header handling --- recipe/jwt/api/implementation.go | 8 ++- recipe/jwt/getJWKS_test.go | 80 +++++++++++++++++++++++++ recipe/jwt/jwtmodels/recipeInterface.go | 3 +- recipe/jwt/recipeimplementation.go | 30 +++++++++- supertokens/querier.go | 63 +++++++++++++++---- 5 files changed, 168 insertions(+), 16 deletions(-) diff --git a/recipe/jwt/api/implementation.go b/recipe/jwt/api/implementation.go index 0c93fa83..e6e96fc0 100644 --- a/recipe/jwt/api/implementation.go +++ b/recipe/jwt/api/implementation.go @@ -16,6 +16,7 @@ package api import ( + "fmt" "github.com/supertokens/supertokens-golang/recipe/jwt/jwtmodels" "github.com/supertokens/supertokens-golang/supertokens" ) @@ -26,8 +27,13 @@ func MakeAPIImplementation() jwtmodels.APIInterface { if err != nil { return jwtmodels.GetJWKSAPIResponse{}, err } + options.Res.Header().Set("Cache-Control", fmt.Sprintf("max-age=%d, must-revalidate", resp.OK.ValidityInSeconds)) return jwtmodels.GetJWKSAPIResponse{ - OK: resp.OK, + OK: &struct { + Keys []jwtmodels.JsonWebKeys + }{ + Keys: resp.OK.Keys, + }, }, nil } return jwtmodels.APIInterface{ diff --git a/recipe/jwt/getJWKS_test.go b/recipe/jwt/getJWKS_test.go index c139ab9e..371ab3db 100644 --- a/recipe/jwt/getJWKS_test.go +++ b/recipe/jwt/getJWKS_test.go @@ -127,4 +127,84 @@ func TestDefaultGetJWKSWorksFine(t *testing.T) { result := *unittesting.HttpResponseToConsumableInformation(resp.Body) assert.NotNil(t, result) assert.Greater(t, len(result["keys"].([]interface{})), 0) + + cacheControl := resp.Header.Get("Cache-Control") + assert.Equal(t, cacheControl, "max-age=60, must-revalidate") +} + +func TestThatWeCanOverrideCacheControlThroughRecipeFunction(t *testing.T) { + configValue := supertokens.TypeInput{ + Supertokens: &supertokens.ConnectionInfo{ + ConnectionURI: "http://localhost:8080", + }, + AppInfo: supertokens.AppInfo{ + APIDomain: "api.supertokens.io", + AppName: "SuperTokens", + WebsiteDomain: "supertokens.io", + }, + RecipeList: []supertokens.Recipe{ + Init(&jwtmodels.TypeInput{ + Override: &jwtmodels.OverrideStruct{ + Functions: func(originalImplementation jwtmodels.RecipeInterface) jwtmodels.RecipeInterface { + originalGetJWKS := *originalImplementation.GetJWKS + + getJWKs := func(userContext supertokens.UserContext) (jwtmodels.GetJWKSResponse, error) { + result, err := originalGetJWKS(userContext) + + if err != nil { + return jwtmodels.GetJWKSResponse{}, err + } + + return jwtmodels.GetJWKSResponse{ + OK: &struct { + Keys []jwtmodels.JsonWebKeys + ValidityInSeconds int + }{Keys: result.OK.Keys, ValidityInSeconds: 1234}, + }, nil + } + + *originalImplementation.GetJWKS = getJWKs + + return originalImplementation + }, + }, + }), + }, + } + + BeforeEach() + unittesting.StartUpST("localhost", "8080") + defer AfterEach() + err := supertokens.Init(configValue) + if err != nil { + t.Error(err.Error()) + } + + q, err := supertokens.GetNewQuerierInstanceOrThrowError("") + if err != nil { + t.Error(err.Error()) + } + apiV, err := q.GetQuerierAPIVersion() + if err != nil { + t.Error(err.Error()) + } + + if unittesting.MaxVersion(apiV, "2.8") == "2.8" { + return + } + mux := http.NewServeMux() + testServer := httptest.NewServer(supertokens.Middleware(mux)) + defer testServer.Close() + + resp, err := http.Get(testServer.URL + "/auth/jwt/jwks.json") + if err != nil { + t.Error(err.Error()) + } + + result := *unittesting.HttpResponseToConsumableInformation(resp.Body) + assert.NotNil(t, result) + assert.Greater(t, len(result["keys"].([]interface{})), 0) + + cacheControl := resp.Header.Get("Cache-Control") + assert.Equal(t, cacheControl, "max-age=1234, must-revalidate") } diff --git a/recipe/jwt/jwtmodels/recipeInterface.go b/recipe/jwt/jwtmodels/recipeInterface.go index c3367397..d64d1587 100644 --- a/recipe/jwt/jwtmodels/recipeInterface.go +++ b/recipe/jwt/jwtmodels/recipeInterface.go @@ -31,6 +31,7 @@ type CreateJWTResponse struct { type GetJWKSResponse struct { OK *struct { - Keys []JsonWebKeys + Keys []JsonWebKeys + ValidityInSeconds int } } diff --git a/recipe/jwt/recipeimplementation.go b/recipe/jwt/recipeimplementation.go index 48728df5..4fd7dc21 100644 --- a/recipe/jwt/recipeimplementation.go +++ b/recipe/jwt/recipeimplementation.go @@ -18,8 +18,12 @@ package jwt import ( "github.com/supertokens/supertokens-golang/recipe/jwt/jwtmodels" "github.com/supertokens/supertokens-golang/supertokens" + "regexp" + "strconv" ) +var defaultJWKSMaxAge = 60 // This corresponds to the dynamicSigningKeyOverlapMS in the core + func makeRecipeImplementation(querier supertokens.Querier, config jwtmodels.TypeNormalisedInput, appInfo supertokens.NormalisedAppinfo) jwtmodels.RecipeInterface { createJWT := func(payload map[string]interface{}, validitySecondsPointer *uint64, useStaticSigningKey *bool, userContext supertokens.UserContext) (jwtmodels.CreateJWTResponse, error) { validitySeconds := config.JwtValiditySeconds @@ -61,7 +65,7 @@ func makeRecipeImplementation(querier supertokens.Querier, config jwtmodels.Type } } getJWKS := func(userContext supertokens.UserContext) (jwtmodels.GetJWKSResponse, error) { - response, err := querier.SendGetRequest("/.well-known/jwks.json", map[string]string{}) + response, headers, err := querier.SendGetRequestWithResponseHeaders("/.well-known/jwks.json", map[string]string{}) if err != nil { return jwtmodels.GetJWKSResponse{}, err } @@ -79,9 +83,29 @@ func makeRecipeImplementation(querier supertokens.Querier, config jwtmodels.Type }) } + validityInSeconds := defaultJWKSMaxAge + cacheControlHeader := headers.Get("Cache-Control") + + if cacheControlHeader != "" { + regex := regexp.MustCompile(`/,?\s*max-age=(\d+)(?:,|$)/`) + maxAgeHeader := regex.FindAllString(cacheControlHeader, -1) + + if maxAgeHeader != nil && len(maxAgeHeader) > 0 { + validityInSeconds, err = strconv.Atoi(maxAgeHeader[1]) + + if err != nil { + validityInSeconds = defaultJWKSMaxAge + } + } + } + return jwtmodels.GetJWKSResponse{ - OK: &struct{ Keys []jwtmodels.JsonWebKeys }{ - Keys: keys, + OK: &struct { + Keys []jwtmodels.JsonWebKeys + ValidityInSeconds int + }{ + Keys: keys, + ValidityInSeconds: validityInSeconds, }, }, nil } diff --git a/supertokens/querier.go b/supertokens/querier.go index 725195be..263442f8 100644 --- a/supertokens/querier.go +++ b/supertokens/querier.go @@ -56,7 +56,7 @@ func (q *Querier) GetQuerierAPIVersion() (string, error) { if querierAPIVersion != "" { return querierAPIVersion, nil } - response, err := q.sendRequestHelper(NormalisedURLPath{value: "/apiversion"}, func(url string) (*http.Response, error) { + response, _, err := q.sendRequestHelper(NormalisedURLPath{value: "/apiversion"}, func(url string) (*http.Response, error) { req, err := http.NewRequest("GET", url, nil) if err != nil { return nil, err @@ -117,7 +117,7 @@ func (q *Querier) SendPostRequest(path string, data map[string]interface{}) (map if err != nil { return nil, err } - return q.sendRequestHelper(nP, func(url string) (*http.Response, error) { + resp, _, err := q.sendRequestHelper(nP, func(url string) (*http.Response, error) { if data == nil { data = map[string]interface{}{} } @@ -147,6 +147,7 @@ func (q *Querier) SendPostRequest(path string, data map[string]interface{}) (map client := &http.Client{} return client.Do(req) }, len(QuerierHosts), nil) + return resp, err } func (q *Querier) SendDeleteRequest(path string, data map[string]interface{}, params map[string]string) (map[string]interface{}, error) { @@ -154,7 +155,7 @@ func (q *Querier) SendDeleteRequest(path string, data map[string]interface{}, pa if err != nil { return nil, err } - return q.sendRequestHelper(nP, func(url string) (*http.Response, error) { + resp, _, err := q.sendRequestHelper(nP, func(url string) (*http.Response, error) { jsonData, err := json.Marshal(data) if err != nil { return nil, err @@ -188,6 +189,7 @@ func (q *Querier) SendDeleteRequest(path string, data map[string]interface{}, pa client := &http.Client{} return client.Do(req) }, len(QuerierHosts), nil) + return resp, err } func (q *Querier) SendGetRequest(path string, params map[string]string) (map[string]interface{}, error) { @@ -195,6 +197,43 @@ func (q *Querier) SendGetRequest(path string, params map[string]string) (map[str if err != nil { return nil, err } + resp, _, err := q.sendRequestHelper(nP, func(url string) (*http.Response, error) { + req, err := http.NewRequest("GET", url, nil) + if err != nil { + return nil, err + } + + query := req.URL.Query() + + for k, v := range params { + query.Add(k, v) + } + req.URL.RawQuery = query.Encode() + + apiVerion, querierAPIVersionError := q.GetQuerierAPIVersion() + if querierAPIVersionError != nil { + return nil, querierAPIVersionError + } + req.Header.Set("cdi-version", apiVerion) + if QuerierAPIKey != nil { + req.Header.Set("api-key", *QuerierAPIKey) + } + if nP.IsARecipePath() && q.RIDToCore != "" { + req.Header.Set("rid", q.RIDToCore) + } + + client := &http.Client{} + return client.Do(req) + }, len(QuerierHosts), nil) + return resp, err +} + +func (q *Querier) SendGetRequestWithResponseHeaders(path string, params map[string]string) (map[string]interface{}, http.Header, error) { + nP, err := NewNormalisedURLPath(path) + if err != nil { + return nil, nil, err + } + return q.sendRequestHelper(nP, func(url string) (*http.Response, error) { req, err := http.NewRequest("GET", url, nil) if err != nil { @@ -230,7 +269,7 @@ func (q *Querier) SendPutRequest(path string, data map[string]interface{}) (map[ if err != nil { return nil, err } - return q.sendRequestHelper(nP, func(url string) (*http.Response, error) { + resp, _, err := q.sendRequestHelper(nP, func(url string) (*http.Response, error) { jsonData, err := json.Marshal(data) if err != nil { return nil, err @@ -257,6 +296,7 @@ func (q *Querier) SendPutRequest(path string, data map[string]interface{}) (map[ client := &http.Client{} return client.Do(req) }, len(QuerierHosts), nil) + return resp, err } type httpRequestFunction func(url string) (*http.Response, error) @@ -279,9 +319,9 @@ func GetAllCoreUrlsForPath(path string) []string { return result } -func (q *Querier) sendRequestHelper(path NormalisedURLPath, httpRequest httpRequestFunction, numberOfTries int, retryInfoMap *map[string]int) (map[string]interface{}, error) { +func (q *Querier) sendRequestHelper(path NormalisedURLPath, httpRequest httpRequestFunction, numberOfTries int, retryInfoMap *map[string]int) (map[string]interface{}, http.Header, error) { if numberOfTries == 0 { - return nil, errors.New("no SuperTokens core available to query") + return nil, nil, errors.New("no SuperTokens core available to query") } querierHostLock.Lock() @@ -316,14 +356,14 @@ func (q *Querier) sendRequestHelper(path NormalisedURLPath, httpRequest httpRequ if resp != nil { resp.Body.Close() } - return nil, err + return nil, nil, err } defer resp.Body.Close() body, readErr := ioutil.ReadAll(resp.Body) if readErr != nil { - return nil, readErr + return nil, nil, readErr } if resp.StatusCode != 200 { if resp.StatusCode == RateLimitStatusCode { @@ -341,17 +381,18 @@ func (q *Querier) sendRequestHelper(path NormalisedURLPath, httpRequest httpRequ } } - return nil, fmt.Errorf("SuperTokens core threw an error for a request to path: '%s' with status code: %v and message: %s", path.GetAsStringDangerous(), resp.StatusCode, body) + return nil, nil, fmt.Errorf("SuperTokens core threw an error for a request to path: '%s' with status code: %v and message: %s", path.GetAsStringDangerous(), resp.StatusCode, body) } + headers := resp.Header.Clone() finalResult := make(map[string]interface{}) jsonError := json.Unmarshal(body, &finalResult) if jsonError != nil { return map[string]interface{}{ "result": string(body), - }, nil + }, headers, nil } - return finalResult, nil + return finalResult, headers, nil } func ResetQuerierForTest() { From 091549139b8c72c1b37267f2cebc52eb84c7e4be Mon Sep 17 00:00:00 2001 From: Nemi Shah Date: Mon, 25 Sep 2023 10:36:58 +0530 Subject: [PATCH 05/13] Add twitter provider --- recipe/thirdparty/providers/config_utils.go | 2 + recipe/thirdparty/providers/twitter.go | 84 +++++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 recipe/thirdparty/providers/twitter.go diff --git a/recipe/thirdparty/providers/config_utils.go b/recipe/thirdparty/providers/config_utils.go index 0be068c1..b40cf462 100644 --- a/recipe/thirdparty/providers/config_utils.go +++ b/recipe/thirdparty/providers/config_utils.go @@ -75,6 +75,8 @@ func createProvider(input tpmodels.ProviderInput) *tpmodels.TypeProvider { return Linkedin(input) } else if strings.HasPrefix(input.Config.ThirdPartyId, "boxy-saml") { return BoxySaml(input) + } else if strings.HasPrefix(input.Config.ThirdPartyId, "twitter") { + return Twitter(input) } return NewProvider(input) diff --git a/recipe/thirdparty/providers/twitter.go b/recipe/thirdparty/providers/twitter.go new file mode 100644 index 00000000..c2010fd3 --- /dev/null +++ b/recipe/thirdparty/providers/twitter.go @@ -0,0 +1,84 @@ +package providers + +import ( + "encoding/base64" + "github.com/supertokens/supertokens-golang/recipe/thirdparty/tpmodels" + "github.com/supertokens/supertokens-golang/supertokens" +) + +func Twitter(input tpmodels.ProviderInput) *tpmodels.TypeProvider { + if input.Config.Name == "" { + input.Config.Name = "Twitter" + } + + if input.Config.AuthorizationEndpoint == "" { + input.Config.AuthorizationEndpoint = "https://twitter.com/i/oauth2/authorize" + } + + if input.Config.TokenEndpoint == "" { + input.Config.TokenEndpoint = "https://api.twitter.com/2/oauth2/token" + } + + if input.Config.UserInfoEndpoint == "" { + input.Config.UserInfoEndpoint = "https://api.twitter.com/2/users/me" + } + + if input.Config.RequireEmail == nil { + False := false + input.Config.RequireEmail = &False + } + + if input.Config.UserInfoMap.FromUserInfoAPI.UserId == "" { + input.Config.UserInfoMap.FromUserInfoAPI.UserId = "data.id" + } + + oOverride := input.Override + + input.Override = func(originalImplementation *tpmodels.TypeProvider) *tpmodels.TypeProvider { + oGetConfig := originalImplementation.GetConfigForClientType + originalImplementation.GetConfigForClientType = func(clientType *string, userContext supertokens.UserContext) (tpmodels.ProviderConfigForClientType, error) { + config, err := oGetConfig(clientType, userContext) + if err != nil { + return tpmodels.ProviderConfigForClientType{}, err + } + + if len(config.Scope) == 0 { + config.Scope = []string{"users.read", "tweet.read"} + } + + if config.ForcePKCE == nil { + True := true + config.ForcePKCE = &True + } + + return config, nil + } + + originalImplementation.ExchangeAuthCodeForOAuthTokens = func(redirectURIInfo tpmodels.TypeRedirectURIInfo, userContext supertokens.UserContext) (tpmodels.TypeOAuthTokens, error) { + basicAuthToken := base64.StdEncoding.EncodeToString([]byte(originalImplementation.Config.ClientID + ":" + originalImplementation.Config.ClientSecret)) + twitterOauthParams := map[string]interface{}{} + + if originalImplementation.Config.TokenEndpointBodyParams != nil { + twitterOauthParams = originalImplementation.Config.TokenEndpointBodyParams + } + + twitterOauthParams["grant_type"] = "authorization_code" + twitterOauthParams["client_id"] = originalImplementation.Config.ClientID + twitterOauthParams["code_verifier"] = redirectURIInfo.PKCECodeVerifier + twitterOauthParams["redirect_uri"] = redirectURIInfo.RedirectURIOnProviderDashboard + twitterOauthParams["code"] = redirectURIInfo.RedirectURIQueryParams["code"] + + return doPostRequest(originalImplementation.Config.TokenEndpoint, twitterOauthParams, map[string]interface{}{ + "Authorization": "Basic " + basicAuthToken, + }) + } + + if oOverride != nil { + originalImplementation = oOverride(originalImplementation) + } + + return originalImplementation + } + + return NewProvider(input) +} From b144bd429f03338175ffffd93e90e758c4e75bd4 Mon Sep 17 00:00:00 2001 From: Nemi Shah Date: Mon, 25 Sep 2023 11:09:04 +0530 Subject: [PATCH 06/13] Refactor for twitter provider --- recipe/thirdparty/providers/twitter.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/recipe/thirdparty/providers/twitter.go b/recipe/thirdparty/providers/twitter.go index c2010fd3..cb641c72 100644 --- a/recipe/thirdparty/providers/twitter.go +++ b/recipe/thirdparty/providers/twitter.go @@ -62,9 +62,15 @@ func Twitter(input tpmodels.ProviderInput) *tpmodels.TypeProvider { twitterOauthParams = originalImplementation.Config.TokenEndpointBodyParams } + codeVerifier := "" + + if redirectURIInfo.PKCECodeVerifier != nil { + codeVerifier = *redirectURIInfo.PKCECodeVerifier + } + twitterOauthParams["grant_type"] = "authorization_code" twitterOauthParams["client_id"] = originalImplementation.Config.ClientID - twitterOauthParams["code_verifier"] = redirectURIInfo.PKCECodeVerifier + twitterOauthParams["code_verifier"] = codeVerifier twitterOauthParams["redirect_uri"] = redirectURIInfo.RedirectURIOnProviderDashboard twitterOauthParams["code"] = redirectURIInfo.RedirectURIQueryParams["code"] From 4e49ffe95418474f8e4e3dcf56878b6bd2cb635f Mon Sep 17 00:00:00 2001 From: Sattvik Chakravarthy Date: Tue, 26 Sep 2023 09:49:08 +0530 Subject: [PATCH 07/13] fix: no panic in middleware --- CHANGELOG.md | 1 + supertokens/main.go | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bd033865..5197030e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [unreleased] - Handle AWS Public URLs (ending with `.amazonaws.com`) separately while extracting TLDs for SameSite attribute. +- Return `500` status instead of panic when `supertokens.Middleware` is used without initializing the SDK. ## [0.14.0] - 2023-09-11 diff --git a/supertokens/main.go b/supertokens/main.go index c2e07ac9..338919b1 100644 --- a/supertokens/main.go +++ b/supertokens/main.go @@ -34,7 +34,9 @@ func Init(config TypeInput) error { func Middleware(theirHandler http.Handler) http.Handler { instance, err := GetInstanceOrThrowError() if err != nil { - panic("Please call supertokens.Init function before using the Middleware") + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + http.Error(w, err.Error(), http.StatusInternalServerError) + }) } return instance.middleware(theirHandler) } From 6323147194ed713760f496175779ab9c7d9a84b9 Mon Sep 17 00:00:00 2001 From: Sattvik Chakravarthy Date: Tue, 26 Sep 2023 10:02:31 +0530 Subject: [PATCH 08/13] fix: fiber adaptor update --- examples/go.mod | 4 +-- examples/go.sum | 69 ++++++++++++++++++++++++------------- examples/with-fiber/main.go | 5 +-- 3 files changed, 49 insertions(+), 29 deletions(-) diff --git a/examples/go.mod b/examples/go.mod index 7b32b1dc..d5344c99 100644 --- a/examples/go.mod +++ b/examples/go.mod @@ -7,11 +7,9 @@ require ( github.com/gin-gonic/gin v1.7.4 github.com/go-chi/chi/v5 v5.0.4 github.com/go-chi/cors v1.2.0 - github.com/gofiber/adaptor/v2 v2.1.18 - github.com/gofiber/fiber/v2 v2.27.0 + github.com/gofiber/fiber/v2 v2.49.2 github.com/gorilla/handlers v1.5.1 github.com/gorilla/mux v1.8.0 - github.com/klauspost/compress v1.14.4 // indirect github.com/labstack/echo/v4 v4.6.1 github.com/osohq/go-oso v0.21.0 github.com/spf13/viper v1.8.1 diff --git a/examples/go.sum b/examples/go.sum index 5b526b5d..ca1bb640 100644 --- a/examples/go.sum +++ b/examples/go.sum @@ -64,8 +64,8 @@ github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRF github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho= github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a/go.mod h1:SGnFV6hVsYE877CKEZ6tDNTjaSXYUk6QqoIK6PrAtcc= github.com/alicebob/miniredis/v2 v2.22.0/go.mod h1:XNqvJdQJv5mSuVMc0ynneafpnL/zv52acZ6kqeS0t88= -github.com/andybalholm/brotli v1.0.4 h1:V7DdXeJtZscaqfNuAdSRuRFzuiKlHSC/Zh3zl9qY3JY= -github.com/andybalholm/brotli v1.0.4/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig= +github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs= +github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o= github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY= @@ -188,12 +188,8 @@ github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/me github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= github.com/goccy/go-yaml v1.8.5/go.mod h1:U/jl18uSupI5rdI2jmuCswEA2htH9eXfferR3KfscvA= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= -github.com/gofiber/adaptor/v2 v2.1.18 h1:J0UlV40ng4K0Nb9mBw7b8bgX4AcFfPQw1+cybnSyXLU= -github.com/gofiber/adaptor/v2 v2.1.18/go.mod h1:20XTo3Nxorrxwi5vBFdPpaZstEM4n/Nx3pSfakFrczg= -github.com/gofiber/fiber/v2 v2.27.0 h1:u34t1nOea7zz4jcZDK7+ZMiG+MVFYrHqMhTdYQDiFA8= -github.com/gofiber/fiber/v2 v2.27.0/go.mod h1:0bPXdTu+jRqINrEq1T6mHeVBnE0lQd67PGu35jD3hLk= -github.com/gofiber/utils v0.1.2 h1:1SH2YEz4RlNS0tJlMJ0bGwO0JkqPqvq6TbHK9tXZKtk= -github.com/gofiber/utils v0.1.2/go.mod h1:pacRFtghAE3UoknMOUiXh2Io/nLWSUHtQCi/3QASsOc= +github.com/gofiber/fiber/v2 v2.49.2 h1:ONEN3/Vc+dUCxxDgZZwpqvhISgHqb+bu+isBiEyKEQs= +github.com/gofiber/fiber/v2 v2.49.2/go.mod h1:gNsKnyrmfEWFpJxQAV0qvW6l70K1dZGno12oLtukcts= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY= @@ -274,8 +270,9 @@ github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLe github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4= +github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= github.com/googleapis/gnostic v0.5.1/go.mod h1:6U4PtQXGIEt/Z3h5MAT7FNofLnw9vXk2cUuW7uA/OeU= @@ -349,9 +346,9 @@ github.com/justinas/alice v1.2.0/go.mod h1:fN5HRH/reO/zrUflLfTN43t3vXvKzvZIENsNE github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= -github.com/klauspost/compress v1.14.1/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= -github.com/klauspost/compress v1.14.4 h1:eijASRJcobkVtSt81Olfh7JX43osYLwy5krOJo6YEu4= -github.com/klauspost/compress v1.14.4/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= +github.com/klauspost/compress v1.16.3/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= +github.com/klauspost/compress v1.16.7 h1:2mk3MPGNzKyxErAw8YaohYh69+pa4sIQSC0fPGCFR9I= +github.com/klauspost/compress v1.16.7/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= @@ -380,16 +377,21 @@ github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= -github.com/mattn/go-colorable v0.1.9 h1:sqDoxXbdeALODt0DAeJCVp38ps9ZogZEAXjus69YV3U= github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= +github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= +github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= -github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= +github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= +github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= +github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U= +github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/mattn/go-sqlite3 v1.9.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 h1:I0XW9+e1XWDxdcEniV4rQAIOPUGDq67JSCiRCgGCZLI= @@ -451,6 +453,7 @@ github.com/pelletier/go-toml v1.9.3/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCko github.com/pelletier/go-toml/v2 v2.0.2 h1:+jQXlF3scKIcSEKkdHzXhCTDLPFi5r1wnK6yPS+49Gw= github.com/pelletier/go-toml/v2 v2.0.2/go.mod h1:MovirKjgVRESsAvNZlAjtFwV867yGuwRkXbG66OzopI= github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU= +github.com/philhofer/fwd v1.1.2/go.mod h1:qkPdfjR2SIEbspLqpe1tO4n5yICnr2DY7mqEx2tUTP0= github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= github.com/pierrec/lz4 v2.6.1+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= github.com/pierrec/lz4/v4 v4.1.15/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4= @@ -489,6 +492,7 @@ github.com/prometheus/procfs v0.7.3 h1:4jVXhlkAyzOScmCkXBTOLRLTz8EeU+eyjrwB/EPq0 github.com/prometheus/procfs v0.7.3/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= github.com/rabbitmq/amqp091-go v1.1.0/go.mod h1:ogQDLSOACsLPsIq0NpbtiifNZi2YOz0VTJ0kHRghqbM= github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= +github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= @@ -541,6 +545,7 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s= github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= +github.com/tinylib/msgp v1.1.8/go.mod h1:qkpG+2ldGg4xRFmx+jfTvZPxfGFhi64BcnL9vkCm/Tw= github.com/tklauser/go-sysconf v0.3.10/go.mod h1:C8XykCvCb+Gn0oNCWPIlcb0RuglQTYaQ2hGm7jmxEFk= github.com/tklauser/numcpus v0.4.0/go.mod h1:1+UI3pD8NW14VMwdgJNJ1ESk2UnwhAnz5hMwiKKqXCQ= github.com/twilio/twilio-go v0.26.0 h1:wFW4oTe3/LKt6bvByP7eio8JsjtaLHjMQKOUEzQry7U= @@ -554,8 +559,8 @@ github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLY github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI= github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= -github.com/valyala/fasthttp v1.33.0 h1:mHBKd98J5NcXuBddgjvim1i3kWzlng1SzLhrnBOU9g8= -github.com/valyala/fasthttp v1.33.0/go.mod h1:KJRK/MXx0J+yd0c5hlR+s1tIHD72sniU8ZJjl97LIw4= +github.com/valyala/fasthttp v1.49.0 h1:9FdvCpmxB74LH4dPb7IJ1cOSsluR07XG3I1txXWwJpE= +github.com/valyala/fasthttp v1.49.0/go.mod h1:k2zXd82h/7UZc3VOdJ2WaUqt1uZ/XpXAfE9i+HBC3lA= github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8= github.com/valyala/fasttemplate v1.2.1 h1:TVEnxayobAdVkhQfrfes2IzOB6o+z4roRkPF52WA1u4= github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ= @@ -628,9 +633,9 @@ golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83/go.mod h1:jdWPYTVW3xRLrWP golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20210920023735-84f357641f63/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.0.0-20220112180741-5e0467b6c7ce/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/crypto v0.2.0 h1:BRXPfhNivWL5Yq0BGQ39a2sW6t44aODpfxkWjYdzewE= golang.org/x/crypto v0.2.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4= +golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A= +golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -667,6 +672,8 @@ golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/mod v0.7.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -712,13 +719,14 @@ golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210913180222-943fd674d43e/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210917221730-978cfadd31cf/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211209124913-491a49abca63/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.0.0-20220111093109-d55c255bac03/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20220531201128-c960675eff93/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/net v0.2.0 h1:sZfSu1wtKLGlWI4ZZayP0ck9Y73K1ynO6gqzTdBVdPU= golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY= +golang.org/x/net v0.3.0/go.mod h1:MBQ8lrhLObU/6UmLb4fmbmk5OcyYmqtbGd/9yIeKjEE= +golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ= +golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -744,6 +752,7 @@ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -812,19 +821,26 @@ golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210910150752-751e447fb3d0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220111092808-5a964db01320/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220429233432-b5fbb4746d32/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.2.0 h1:ljd4t30dBnAvMZaQCevtY0xLLD0A+bRZXbgLMLU1F/A= +golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o= +golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc= +golang.org/x/term v0.3.0/go.mod h1:q750SLmJuPmVoN1blW3UFBPREJfb1KmY3vwxfr+nFDA= +golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= +golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -834,8 +850,11 @@ golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.4.0 h1:BrVqGRd7+k1DiOgtnFvAkoQEWQvBc25ouMJM6429SFg= golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.5.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68= +golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -898,6 +917,8 @@ golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/tools v0.4.0/go.mod h1:UE5sM2OK9E/d67R0ANs2xJizIymRP5gJU295PvKXxjQ= +golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/examples/with-fiber/main.go b/examples/with-fiber/main.go index 7c635c83..2a2b1f9a 100644 --- a/examples/with-fiber/main.go +++ b/examples/with-fiber/main.go @@ -1,12 +1,13 @@ package main import ( - "github.com/supertokens/supertokens-golang/recipe/dashboard" "log" "net/http" - "github.com/gofiber/adaptor/v2" + "github.com/supertokens/supertokens-golang/recipe/dashboard" + "github.com/gofiber/fiber/v2" + "github.com/gofiber/fiber/v2/middleware/adaptor" "github.com/gofiber/fiber/v2/middleware/cors" "github.com/supertokens/supertokens-golang/recipe/emailverification" "github.com/supertokens/supertokens-golang/recipe/emailverification/evmodels" From 3ab3c5ec6bf157b7eb4459ce1a95b8255c3a90d4 Mon Sep 17 00:00:00 2001 From: Sattvik Chakravarthy Date: Tue, 26 Sep 2023 10:29:48 +0530 Subject: [PATCH 09/13] fix: changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bd033865..7888f074 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [unreleased] - Handle AWS Public URLs (ending with `.amazonaws.com`) separately while extracting TLDs for SameSite attribute. +- Updates fiber adaptor package in the fiber example. ## [0.14.0] - 2023-09-11 From 38b7e966fbe3982400cb3fe650e64f8e26cdddf0 Mon Sep 17 00:00:00 2001 From: Nemi Shah Date: Tue, 26 Sep 2023 12:40:04 +0530 Subject: [PATCH 10/13] Update version and changelog --- CHANGELOG.md | 8 ++++++++ supertokens/constants.go | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bd033865..10b362d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [unreleased] +## [0.15.0] - 2023-09-26 + +- Added a `Cache-Control` header to `/jwt/jwks.json` (`GetJWKSGET`) +- Added `ValidityInSeconds` to the return value of the overrideable `GetJWKS` function. + - This can be used to control the `Cache-Control` header mentioned above. + - It defaults to `60` or the value set in the cache-control header returned by the core + - This is optional (so you are not required to update your overrides). Returning undefined means that the header is not set. - Handle AWS Public URLs (ending with `.amazonaws.com`) separately while extracting TLDs for SameSite attribute. +- Updates fiber adaptor package in the fiber example. ## [0.14.0] - 2023-09-11 diff --git a/supertokens/constants.go b/supertokens/constants.go index adcff424..302a697a 100644 --- a/supertokens/constants.go +++ b/supertokens/constants.go @@ -21,7 +21,7 @@ const ( ) // VERSION current version of the lib -const VERSION = "0.14.0" +const VERSION = "0.15.0" var ( cdiSupported = []string{"3.0"} From 07b72e824577698059fbef084f721a68ba195cb2 Mon Sep 17 00:00:00 2001 From: Nemi Shah Date: Tue, 26 Sep 2023 12:44:49 +0530 Subject: [PATCH 11/13] Update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 10b362d3..8337a5ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [0.15.0] - 2023-09-26 +- Adds Twitter/X as a default provider to the third party recipe - Added a `Cache-Control` header to `/jwt/jwks.json` (`GetJWKSGET`) - Added `ValidityInSeconds` to the return value of the overrideable `GetJWKS` function. - This can be used to control the `Cache-Control` header mentioned above. From aa9cddf04b902421043c703eefd6b97520448dd4 Mon Sep 17 00:00:00 2001 From: Sattvik Chakravarthy Date: Tue, 26 Sep 2023 12:47:36 +0530 Subject: [PATCH 12/13] fix: test --- recipe/emailpassword/middleware_test.go | 33 +++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 recipe/emailpassword/middleware_test.go diff --git a/recipe/emailpassword/middleware_test.go b/recipe/emailpassword/middleware_test.go new file mode 100644 index 00000000..e137e4b0 --- /dev/null +++ b/recipe/emailpassword/middleware_test.go @@ -0,0 +1,33 @@ +package emailpassword + +import ( + "io/ioutil" + "net/http" + "net/http/httptest" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/supertokens/supertokens-golang/supertokens" +) + +func TestAPIWithSupertokensMiddlewareButNotInitialized(t *testing.T) { + BeforeEach() + defer AfterEach() + + mux := http.NewServeMux() + testServer := httptest.NewServer(supertokens.Middleware(mux)) + defer testServer.Close() + + resp, err := http.Post(testServer.URL+"/auth/signup", "application/json", nil) + if err != nil { + t.Error(err.Error()) + } + + assert.Equal(t, 500, resp.StatusCode) + defer resp.Body.Close() + bodyBytes, err := ioutil.ReadAll(resp.Body) + assert.NoError(t, err) + + bodyStr := string(bodyBytes) + assert.Equal(t, "initialisation not done. Did you forget to call the SuperTokens.init function?\n", bodyStr) +} From a3b8603d8ef9cac10d135660aaeda12b41bba7e4 Mon Sep 17 00:00:00 2001 From: Nemi Shah Date: Tue, 26 Sep 2023 14:11:49 +0530 Subject: [PATCH 13/13] Add dev credentials handling to twitter --- recipe/thirdparty/providers/twitter.go | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/recipe/thirdparty/providers/twitter.go b/recipe/thirdparty/providers/twitter.go index cb641c72..d383f410 100644 --- a/recipe/thirdparty/providers/twitter.go +++ b/recipe/thirdparty/providers/twitter.go @@ -55,7 +55,20 @@ func Twitter(input tpmodels.ProviderInput) *tpmodels.TypeProvider { } originalImplementation.ExchangeAuthCodeForOAuthTokens = func(redirectURIInfo tpmodels.TypeRedirectURIInfo, userContext supertokens.UserContext) (tpmodels.TypeOAuthTokens, error) { - basicAuthToken := base64.StdEncoding.EncodeToString([]byte(originalImplementation.Config.ClientID + ":" + originalImplementation.Config.ClientSecret)) + clientId := originalImplementation.Config.ClientID + redirectUri := redirectURIInfo.RedirectURIOnProviderDashboard + + // We need to do this because we don't call the original implementation + /* Transformation needed for dev keys BEGIN */ + + if isUsingDevelopmentClientId(clientId) { + clientId = getActualClientIdFromDevelopmentClientId(clientId) + redirectUri = DevOauthRedirectUrl + } + + /* Transformation needed for dev keys END */ + + basicAuthToken := base64.StdEncoding.EncodeToString([]byte(clientId + ":" + originalImplementation.Config.ClientSecret)) twitterOauthParams := map[string]interface{}{} if originalImplementation.Config.TokenEndpointBodyParams != nil { @@ -69,9 +82,9 @@ func Twitter(input tpmodels.ProviderInput) *tpmodels.TypeProvider { } twitterOauthParams["grant_type"] = "authorization_code" - twitterOauthParams["client_id"] = originalImplementation.Config.ClientID + twitterOauthParams["client_id"] = clientId twitterOauthParams["code_verifier"] = codeVerifier - twitterOauthParams["redirect_uri"] = redirectURIInfo.RedirectURIOnProviderDashboard + twitterOauthParams["redirect_uri"] = redirectUri twitterOauthParams["code"] = redirectURIInfo.RedirectURIQueryParams["code"] return doPostRequest(originalImplementation.Config.TokenEndpoint, twitterOauthParams, map[string]interface{}{