Skip to content

Commit

Permalink
Update based on PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
nkshah2 committed May 22, 2023
1 parent 0f1e9d9 commit a73b0be
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 11 deletions.
3 changes: 2 additions & 1 deletion recipe/session/accessToken.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package session

import (
"errors"
"fmt"
"github.com/MicahParks/keyfunc"
"github.com/golang-jwt/jwt/v4"
sterrors "github.com/supertokens/supertokens-golang/recipe/session/errors"
Expand All @@ -42,7 +43,7 @@ func GetInfoFromAccessToken(jwtInfo sessmodels.ParsedJWTInfo, jwks keyfunc.JWKS,
if jwtInfo.Version >= 3 {
parsedToken, parseError := jwt.Parse(jwtInfo.RawTokenString, jwks.Keyfunc)
if parseError != nil {
supertokens.LogDebugMessage("GetInfoFromAccessToken: Returning TryRefreshTokenError because access token parsing failed")
supertokens.LogDebugMessage(fmt.Sprintf("GetInfoFromAccessToken: Returning TryRefreshTokenError because access token parsing failed - %s", parseError))
return nil, sterrors.TryRefreshTokenError{
Msg: parseError.Error(),
}
Expand Down
2 changes: 0 additions & 2 deletions recipe/session/recipeImplementation.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ func MakeRecipeImplementation(querier supertokens.Querier, config sessmodels.Typ

refreshSession := func(refreshToken string, antiCsrfToken *string, disableAntiCsrf bool, userContext supertokens.UserContext) (sessmodels.SessionContainer, error) {
if disableAntiCsrf != true && config.AntiCsrf == AntiCSRF_VIA_CUSTOM_HEADER {
supertokens.LogDebugMessage("refreshSession: Since the anti-csrf mode is VIA_CUSTOM_HEADER getSession can't check the CSRF token. Please either use VIA_TOKEN or set antiCsrfCheck to false")
return nil, defaultErrors.New("Since the anti-csrf mode is VIA_CUSTOM_HEADER getSession can't check the CSRF token. Please either use VIA_TOKEN or set antiCsrfCheck to false")
}

Expand All @@ -190,7 +189,6 @@ func MakeRecipeImplementation(querier supertokens.Querier, config sessmodels.Typ

responseToken, parseErr := ParseJWTWithoutSignatureVerification(response.AccessToken.Token)
if parseErr != nil {
supertokens.LogDebugMessage("refreshSession: Failed to parse access token")
return nil, err
}

Expand Down
3 changes: 2 additions & 1 deletion recipe/session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package session

import (
"fmt"
"reflect"

"github.com/supertokens/supertokens-golang/recipe/session/claims"
Expand Down Expand Up @@ -164,7 +165,7 @@ func newSessionContainer(config sessmodels.TypeNormalisedInput, session *Session
response, err := regenerateAccessTokenHelper(*querier, &accessTokenPayload, sessionContainer.GetAccessToken())

if err != nil {
supertokens.LogDebugMessage("MergeIntoAccessTokenPayloadWithContext: Returning UnauthorizedError because regenerateAccessTokenHelper returned an error")
supertokens.LogDebugMessage(fmt.Sprintf("MergeIntoAccessTokenPayloadWithContext: Returning UnauthorizedError because we could not regenerate the session - %s", err))
return errors.UnauthorizedError{
Msg: errors.UnauthorizedErrorStr,
}
Expand Down
9 changes: 2 additions & 7 deletions recipe/session/sessionFunctions.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package session
import (
"encoding/json"
defaultErrors "errors"
"fmt"
"strings"

"github.com/supertokens/supertokens-golang/recipe/session/errors"
Expand Down Expand Up @@ -63,7 +64,7 @@ func getSessionHelper(config sessmodels.TypeNormalisedInput, querier supertokens
var err error = nil
combinedJwks, jwksError := sessmodels.GetCombinedJWKS()
if jwksError != nil {
supertokens.LogDebugMessage("getSessionHelper: Returning TryRefreshTokenError because there was an error fetching JWKs")
supertokens.LogDebugMessage(fmt.Sprintf("getSessionHelper: Returning TryRefreshTokenError because there was an error fetching JWKs - %s", jwksError))
if !defaultErrors.As(jwksError, &errors.TryRefreshTokenError{}) {
return sessmodels.GetSessionResponse{}, jwksError
}
Expand Down Expand Up @@ -236,20 +237,17 @@ func refreshSessionHelper(config sessmodels.TypeNormalisedInput, querier superto

response, err := querier.SendPostRequest("/recipe/session/refresh", requestBody)
if err != nil {
supertokens.LogDebugMessage("refreshSessionHelper: Call to /recipe/session/refresh API failed")
return sessmodels.CreateOrRefreshAPIResponse{}, err
}
if response["status"] == "OK" {
delete(response, "status")
responseByte, err := json.Marshal(response)
if err != nil {
supertokens.LogDebugMessage("refreshSessionHelper: Could not parse response from /recipe/session/refresh API")
return sessmodels.CreateOrRefreshAPIResponse{}, err
}
var result sessmodels.CreateOrRefreshAPIResponse
err = json.Unmarshal(responseByte, &result)
if err != nil {
supertokens.LogDebugMessage("refreshSessionHelper: Could not decode response from /recipe/session/refresh API")
return sessmodels.CreateOrRefreshAPIResponse{}, err
}
return result, nil
Expand Down Expand Up @@ -382,21 +380,18 @@ func regenerateAccessTokenHelper(querier supertokens.Querier, newAccessTokenPayl
"userDataInJWT": newAccessTokenPayload,
})
if err != nil {
supertokens.LogDebugMessage("regenerateAccessTokenHelper: Call to /recipe/session/regenerate failed")
return nil, err
}
if response["status"].(string) == errors.UnauthorizedErrorStr {
return nil, nil
}
responseByte, err := json.Marshal(response)
if err != nil {
supertokens.LogDebugMessage("regenerateAccessTokenHelper: Failed to parse response from core")
return nil, err
}
var resp sessmodels.RegenerateAccessTokenResponse
err = json.Unmarshal(responseByte, &resp)
if err != nil {
supertokens.LogDebugMessage("regenerateAccessTokenHelper: Failed to decode response from core")
return nil, err
}
return &resp, nil
Expand Down

0 comments on commit a73b0be

Please sign in to comment.