supertokens / supertokens/supertokens-python

Custom third party provider id_token values override the expected values

Open
#552 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
HTML
Stars
148
Forks
48
PR merge metrics
No merged PRs in 30d

Description

I want only values from user_info API response. Used this configuration.

    input.config.user_info_map = UserInfoMap(
        from_id_token_payload=UserFields(),
        from_user_info_api=UserFields(
            user_id="id",
            email="userPrincipalName",
        ),
    )

But the third_party_user_id and email are not the expected values.

Was able to trace it to https://github.com/supertokens/supertokens-python/blob/master/supertokens_python/recipe/thirdparty/providers/custom.py#L101 where after getting the value from user info API, it again gets the value from id_token and overrides it.

But since, I set from_id_token_payload=UserFields(), that should not be happening.

https://github.com/supertokens/supertokens-python/blob/master/supertokens_python/recipe/thirdparty/providers/custom.py#L235 is setting the value to sub, and since the id_token has sub field set, it overrides the id value from the user_info_api.

I think the logic needs to be something like,

  • if from_user_info_api config is set, get values.
  • if from_id_token_payload config is set, get values.
  • if no values are found, try with default values for from_user_info_api
  • if no values are found, try with default values for from_id_token_payload

Right now, the only workaround I can think of

    input.config.user_info_map = UserInfoMap(
        from_id_token_payload=UserFields(
            user_id="XYZ",  # some value which will never be in id_token
            email="XYZ",  # some value which will never be in id_token
        ),
        from_user_info_api=UserFields(
            user_id="id",
            email="userPrincipalName",
        ),
    )

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Review supertokens_python/recipe/thirdparty/providers/custom.py around lines 101 and 235, starting with how values from the user info API and ID token are selected. Confirm that an explicitly empty from_id_token_payload does not override configured user info values; done means third_party_user_id and email retain the expected API values.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
authentication, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.