Skip to content

Commit 6a25f94

Browse files
committed
Fixes are per PR comments
1 parent c2003e9 commit 6a25f94

File tree

9 files changed

+15
-74
lines changed

9 files changed

+15
-74
lines changed

recipe/session/accessToken.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ func GetInfoFromAccessToken(jwtInfo sessmodels.ParsedJWTInfo, jwks keyfunc.JWKS,
101101
}
102102

103103
payload = claimsMap
104+
break
104105
}
105106
}
106107
}

recipe/session/apiImplementation.go

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package session
1818
import (
1919
"net/http"
2020

21-
"github.com/supertokens/supertokens-golang/recipe/session/claims"
2221
"github.com/supertokens/supertokens-golang/recipe/session/sessmodels"
2322
"github.com/supertokens/supertokens-golang/supertokens"
2423
)
@@ -64,30 +63,6 @@ func MakeAPIImplementation() sessmodels.APIInterface {
6463
return nil, nil
6564
}
6665

67-
var overrideGlobalClaimValidators func(globalClaimValidators []claims.SessionClaimValidator, sessionContainer sessmodels.SessionContainer, userContext supertokens.UserContext) ([]claims.SessionClaimValidator, error) = nil
68-
if verifySessionOptions != nil {
69-
overrideGlobalClaimValidators = verifySessionOptions.OverrideGlobalClaimValidators
70-
}
71-
claimValidators := options.ClaimValidatorsAddedByOtherRecipes
72-
claimValidators, err = (*options.RecipeImplementation.GetGlobalClaimValidators)((*sessionContainer).GetUserID(), claimValidators, userContext)
73-
if err != nil {
74-
return nil, err
75-
}
76-
if overrideGlobalClaimValidators != nil {
77-
claimValidators, err = overrideGlobalClaimValidators(claimValidators, sessionContainer, userContext)
78-
if err != nil {
79-
return nil, err
80-
}
81-
}
82-
83-
if err != nil {
84-
return nil, err
85-
}
86-
err = (*sessionContainer).AssertClaimsWithContext(claimValidators, userContext)
87-
if err != nil {
88-
return nil, err
89-
}
90-
9166
return sessionContainer, nil
9267
}
9368
}

recipe/session/cookieAndHeaders.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import (
1919
"encoding/base64"
2020
"encoding/json"
2121
"errors"
22+
"fmt"
23+
"github.com/supertokens/supertokens-golang/supertokens"
2224
"net/http"
2325
"net/textproto"
2426
"net/url"
@@ -158,6 +160,7 @@ func GetToken(req *http.Request, tokenType sessmodels.TokenType, transferMethod
158160
}
159161

160162
func setToken(config sessmodels.TypeNormalisedInput, res http.ResponseWriter, tokenType sessmodels.TokenType, value string, expires uint64, transferMethod sessmodels.TokenTransferMethod) error {
163+
supertokens.LogDebugMessage(fmt.Sprint("setToken: Setting ", tokenType, " token as ", transferMethod))
161164
if transferMethod == sessmodels.CookieTransferMethod {
162165
cookieName, err := getCookieNameFromTokenType(tokenType)
163166
if err != nil {
@@ -169,7 +172,7 @@ func setToken(config sessmodels.TypeNormalisedInput, res http.ResponseWriter, to
169172
} else if tokenType == sessmodels.RefreshToken {
170173
pathType = "refreshTokenPath"
171174
}
172-
SetCookie(config, res, cookieName, value, expires, pathType)
175+
setCookie(config, res, cookieName, value, expires, pathType)
173176
} else if transferMethod == sessmodels.HeaderTransferMethod {
174177
headerName, err := getResponseHeaderNameForTokenType(tokenType)
175178
if err != nil {
@@ -193,7 +196,7 @@ func setHeader(res http.ResponseWriter, key, value string, allowDuplicateKey boo
193196
}
194197
}
195198

196-
func SetCookie(config sessmodels.TypeNormalisedInput, res http.ResponseWriter, name string, value string, expires uint64, pathType string) {
199+
func setCookie(config sessmodels.TypeNormalisedInput, res http.ResponseWriter, name string, value string, expires uint64, pathType string) {
197200
var domain string
198201
if config.CookieDomain != nil {
199202
domain = *config.CookieDomain

recipe/session/sessionFunctions.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ func getSessionHelper(config sessmodels.TypeNormalisedInput, querier supertokens
8383
return sessmodels.GetSessionResponse{}, err
8484
}
8585

86-
expiryTime := uint64(expiryTimeInPayload.(float64))
87-
timeCreated := uint64(timeCreatedInPayload.(float64))
88-
8986
if parsedAccessToken.Version < 3 {
87+
expiryTime := uint64(expiryTimeInPayload.(float64))
88+
timeCreated := uint64(timeCreatedInPayload.(float64))
89+
9090
if expiryTime < GetCurrTimeInMS() {
9191
return sessmodels.GetSessionResponse{}, err
9292
}

recipe/session/sessionRequestFunctions.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ func RefreshSessionInRequest(req *http.Request, res http.ResponseWriter, config
300300
} else {
301301
if GetCookieValue(req, legacyIdRefreshTokenCookieName) != nil {
302302
supertokens.LogDebugMessage("refreshSession: cleared legacy id refresh token because refresh token was not found")
303-
SetCookie(config, res, legacyIdRefreshTokenCookieName, "", 0, "accessTokenPath")
303+
setCookie(config, res, legacyIdRefreshTokenCookieName, "", 0, "accessTokenPath")
304304
}
305305

306306
supertokens.LogDebugMessage("refreshSession: UNAUTHORISED because refresh token in request is undefined")
@@ -339,7 +339,7 @@ func RefreshSessionInRequest(req *http.Request, res http.ResponseWriter, config
339339
if (isTokenTheftDetectedErr) || (isUnauthorisedErr && unauthorisedErr.ClearTokens != nil && *unauthorisedErr.ClearTokens) {
340340
if GetCookieValue(req, legacyIdRefreshTokenCookieName) != nil {
341341
supertokens.LogDebugMessage("refreshSession: cleared legacy id refresh token because refresh is clearing other tokens")
342-
SetCookie(config, res, legacyIdRefreshTokenCookieName, "", 0, "accessTokenPath")
342+
setCookie(config, res, legacyIdRefreshTokenCookieName, "", 0, "accessTokenPath")
343343
}
344344
}
345345

@@ -364,7 +364,7 @@ func RefreshSessionInRequest(req *http.Request, res http.ResponseWriter, config
364364

365365
if GetCookieValue(req, legacyIdRefreshTokenCookieName) != nil {
366366
supertokens.LogDebugMessage("refreshSession: cleared legacy id refresh token after successful refresh")
367-
SetCookie(config, res, legacyIdRefreshTokenCookieName, "", 0, "accessTokenPath")
367+
setCookie(config, res, legacyIdRefreshTokenCookieName, "", 0, "accessTokenPath")
368368
}
369369

370370
return result, nil

recipe/session/sessmodels/models.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828

2929
type TokenType string
3030

31-
var JWKCacheMaxAgeInMs = 600000
31+
var JWKCacheMaxAgeInMs = 60000
3232
var JWKRefreshRateLimit = 500
3333

3434
const (

recipe/session/sessmodels/recipeInterface.go

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,6 @@ import (
2020
"github.com/supertokens/supertokens-golang/supertokens"
2121
)
2222

23-
type CreateNewSessionResponse struct {
24-
Status string
25-
Session SessionContainer
26-
}
27-
28-
type GetSessionFunctionResponse struct {
29-
Status string
30-
Session *SessionContainer
31-
Error *error
32-
}
33-
34-
type GetSessionMainFunctionClaimResponse struct {
35-
Message string
36-
ClaimValidationErrors []claims.ClaimValidationError
37-
}
38-
39-
type GetSessionMainFunctionResponse struct {
40-
Status string
41-
Session *SessionContainer
42-
Error *error
43-
Response *GetSessionMainFunctionClaimResponse
44-
}
45-
4623
type RecipeInterface struct {
4724
CreateNewSession *func(userID string, accessTokenPayload map[string]interface{}, sessionDataInDatabase map[string]interface{}, disableAntiCsrf *bool, userContext supertokens.UserContext) (SessionContainer, error)
4825
GetSession *func(accessToken string, antiCSRFToken *string, options *VerifySessionOptions, userContext supertokens.UserContext) (SessionContainer, error)

recipe/session/utils.go

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -308,23 +308,6 @@ func sendTokenTheftDetectedResponse(recipeInstance Recipe, sessionHandle string,
308308
return supertokens.SendNon200ResponseWithMessage(response, "token theft detected", recipeInstance.Config.SessionExpiredStatusCode)
309309
}
310310

311-
func getKeyInfoFromJson(response map[string]interface{}) []sessmodels.KeyInfo {
312-
keyList := []sessmodels.KeyInfo{}
313-
314-
_, ok := response["jwtSigningPublicKeyList"]
315-
if ok {
316-
for _, k := range response["jwtSigningPublicKeyList"].([]interface{}) {
317-
keyList = append(keyList, sessmodels.KeyInfo{
318-
PublicKey: (k.((map[string]interface{})))["publicKey"].(string),
319-
ExpiryTime: uint64((k.((map[string]interface{})))["ExpiryTime"].(float64)),
320-
CreatedAt: uint64((k.((map[string]interface{})))["createdAt"].(float64)),
321-
})
322-
}
323-
}
324-
325-
return keyList
326-
}
327-
328311
func ValidateClaimsInPayload(claimValidators []claims.SessionClaimValidator, newAccessTokenPayload map[string]interface{}, userContext supertokens.UserContext) []claims.ClaimValidationError {
329312
validationErrors := []claims.ClaimValidationError{}
330313

supertokens/utils.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,8 @@ func SetRequestInUserContextIfNotDefined(userContext *map[string]interface{}, r
286286

287287
if userContext == nil {
288288
_userContext = map[string]interface{}{}
289+
} else {
290+
_userContext = *userContext
289291
}
290292

291293
defaultObj, ok := _userContext["_default"]

0 commit comments

Comments
 (0)