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
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
                ),

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

No branches or pull requests

2 participants