supertokens / supertokens-golang

GoLang SDK for SuperTokens
https://supertokens.com
Other
115 stars 34 forks source link

Github ThirdProviderId introduced a breaking changed caused by new formatting #387

Closed 8BitJonny closed 10 months ago

8BitJonny commented 10 months ago

What

Sorry but I'm really confused if this a bug or breaking change. I'm at the end of migrating a lot of versions and suddenly I have a problem with the github sso provide in the golang backend because the formatting of the thirdPartyUserId has changed? Before (golang-sdk version v0.10.3) the google thirdPartyUserId was of format 32591853.000000 while now (v0.16.6) its in the format of 3.2591853e+07 . I tried finding mentions of that in the github issues or here in discord but found nothing. Both notations seem weird when I curl https://api.github.com/user with the auth token and get the id simply back as "id": 32591853 but yeah it cannot change because then the user can't log in to his account anymore, no?

And I think I even found the code change that causes this breaking change: ID := fmt.Sprintf("%f", userInfo["id"].(float64)) // github userId will be a number (https://github.com/supertokens/supertokens-golang/blob/c93291f8d7c7d7da5633dd81b5f9983040f64def/recipe/thirdparty/providers/github.go#L96C6-L96C89) changed to fmt.Sprint(rawUserInfoResponse.FromUserInfoAPI["user"].(map[string]interface{})["id"]) (https://github.com/supertokens/supertokens-golang/blob/7632d2f55e0a38b26ddde7a38ae038d66c3f9644/recipe/thirdparty/providers/github.go#L138C21-L138C107) so the conversion to float has been removed and thats what must be causing it.

Can you confirm this bug / breaking change?

8BitJonny commented 10 months ago

I think for now I have to go with a workaround like this

{
    Config: tpmodels.ProviderConfig{
        ThirdPartyId: "github",
        Clients: []tpmodels.ProviderClientConfig{
            {
                ClientID:     config.Get("AUTH_GITHUB_CLIENT_ID"),
                ClientSecret: config.Get("AUTH_GITHUB_CLIENT_SECRET"),
            },
        },
    },
    Override: func(originalImplementation *tpmodels.TypeProvider) *tpmodels.TypeProvider {
        originalGetUserInfo := originalImplementation.GetUserInfo
        originalImplementation.GetUserInfo = func(oAuthTokens tpmodels.TypeOAuthTokens, userContext supertokens.UserContext) (tpmodels.TypeUserInfo, error) {
            userInfo, err := originalGetUserInfo(oAuthTokens, userContext)
            if err != nil {
                return userInfo, err
            }
            number, err := strconv.ParseFloat(userInfo.ThirdPartyUserId, 64)
            if err != nil {
                return userInfo, err
            }
            userInfo.ThirdPartyUserId = fmt.Sprintf("%f", number)
            return userInfo, nil
        }

        return originalImplementation
    },
},
rishabhpoddar commented 10 months ago

Thanks for raising this issue @8BitJonny. This is indeed a bug. We will work on fixing it this week. Thanks

rishabhpoddar commented 10 months ago

This has been fixed in version 0.17 of the golang SDK. That being said, you will need to keep the workaround you have already. You could run a db migration to store the "32591853" instead of "32591853.000000" or "3.2591853e+07" and then switch to 0.17 without any work around.

8BitJonny commented 10 months ago

Thx for the quick response and help 🙌🏼