Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Github thirdparty provider does not set raw_user_info_from_provider in get_user_info #474

Open
brentnortham opened this issue Feb 2, 2024 · 1 comment · Fixed by #558
Assignees

Comments

@brentnortham
Copy link

Unlike other providers, the GitHub provider requests user data from the GitHub api and returns the user_id and email but never sets or provides the raw_user_info_from_provider, meaning we have to unnecessarily implement that as a second call in a thirdparty_sign_in_up_post.

@brentnortham
Copy link
Author

brentnortham commented Feb 3, 2024

For the time being I've done this:

def override_github_user_info(oi):

    async def get_user_info(
        oauth_tokens: dict[str, Any],
        user_context: dict[str, Any]
    ) -> UserInfo:
        headers = {
            "Authorization": f"Bearer {oauth_tokens.get('access_token')}",
            "Accept": "application/vnd.github.v3+json",
        }

        email_info: list[Any] = await do_get_request("https://api.github.com/user/emails", headers=headers)  # type: ignore
        user_info = await do_get_request("https://api.github.com/user", headers=headers)

        raw_user_info_from_provider = RawUserInfoFromProvider({}, {})
        raw_user_info_from_provider.from_user_info_api = user_info
        raw_user_info_from_provider.from_id_token_payload["email"] = email_info

        email = None
        is_verified = False
        for info in email_info:
            if info["primary"]:
                email = info["email"]
                is_verified = info["verified"]

        return UserInfo(
            third_party_user_id=str(user_info.get("id")),
            email = None if email is None else UserInfoEmail(email, is_verified),
            raw_user_info_from_provider=raw_user_info_from_provider,
        )

    oi.get_user_info = get_user_info

    return oi

...
                ProviderInput(
                    config=ProviderConfig(
                        third_party_id="github",
                        clients=[
                            ProviderClientConfig(
                                client_id="xxx",
                                client_secret="xxx",
                            )
                        ],
                    ),
                    override=override_github_git_user_info
                ),

mavwolverine added a commit to mavwolverine/supertokens-python that referenced this issue Dec 31, 2024
namsnath pushed a commit to namsnath/supertokens-python that referenced this issue Feb 7, 2025
@namsnath namsnath self-assigned this Feb 7, 2025
mavwolverine added a commit to mavwolverine/supertokens-python that referenced this issue Feb 7, 2025
@namsnath namsnath linked a pull request Feb 10, 2025 that will close this issue
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants