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

Refactor user schema to store provider data better #208

Merged
merged 25 commits into from
Sep 28, 2021
Merged

Conversation

kangmingtay
Copy link
Member

@kangmingtay kangmingtay commented Sep 7, 2021

What kind of change does this PR introduce?

  • All OAuth providers should return the provider id which is unique to a user (regardless of whether the user changes the email associated with the provider login, the provider id will remain the same)
  • Use provider id as primary identifier instead of email for external oauth flows
  • Create identities table to each identity associated with a user
  • raw_app_meta_data.provider field will be marked as deprecated
  • Return identities in access token payload in the following format:
{
  "aud": "authenticated",
  "exp": 1632719084,
  "sub": "12345",
  "email": "a@a.com",
  "phone": "",
  "app_metadata": {
    "provider": "google"
  },
  "user_metadata": {
    ...
  },
  "identities": [
    {
      "id": "1",
      "user_id": "12345",
      "identity_data": {
        "avatar_url": "",
        "email": "a@a.com",
        "email_verified": true,
        "full_name": "a",
        "iss": "https://www.googleapis.com/userinfo/v2/me",
        "name": "abc",
        "picture": "",
        "provider_id": "1",
        "sub": "1"
      },
      "provider": "google",
      "last_sign_in_at": "2021-09-27T10:13:48.877604+08:00",
      "created_at": "2021-09-27T10:13:48.877648+08:00",
      "updated_at": "2021-09-27T10:13:48.877652+08:00"
    },
    {
      "id": "123",
      "user_id": "12345",
      "identity_data": {
        "email": "a@a.com",
        "email_verified": true,
        "iss": "https://appleid.apple.com/auth/keys",
        "provider_id": "123",
        "sub": "123"
      },
      "provider": "apple",
      "last_sign_in_at": "2021-09-27T12:04:43.376864+08:00",
      "created_at": "2021-09-27T12:04:43.37691+08:00",
      "updated_at": "2021-09-27T12:04:43.376916+08:00"
    }
  ],
  "role": "authenticated"
}

api/provider/apple.go Outdated Show resolved Hide resolved
@sandbox-apps
Copy link

sandbox-apps commented Sep 15, 2021

I just want to fix this sentence.

  • Use provider id and provider name (e.g. google, facebook, twitter) as primary identifier instead of email for external oauth flows

@sandbox-apps
Copy link

Just for clarification. what will happen for those auth that have been registered before this fix? Does those auth account already have the provider id and provider name in them?

@kangmingtay
Copy link
Member Author

Hey @sandbox-apps, yeah that's one of the main blockers we're facing currently - some of the auth providers implemented in the past did not keep track of the provider id. We're trying to come up with a solution to reduce any breaking changes. Any ideas will be greatly appreciated :)

@kangmingtay
Copy link
Member Author

kangmingtay commented Sep 22, 2021

Hey @sandbox-apps, yeah that's one of the main blockers we're facing currently - some of the auth providers implemented in the past did not keep track of the provider id. We're trying to come up with a solution to reduce any breaking changes. Any ideas will be greatly appreciated :)

Resolved here. The idea is to check a new sign-in according to the following order:

Gotrue Auth Flow-Page-5 drawio

@kangmingtay kangmingtay changed the title [WIP] Refactor user schema to store provider data better Refactor user schema to store provider data better Sep 27, 2021
@kangmingtay kangmingtay merged commit 70ffa77 into master Sep 28, 2021
@kangmingtay kangmingtay deleted the refactor-v2 branch September 28, 2021 01:31
@github-actions
Copy link
Contributor

🎉 This PR is included in version 2.1.11 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@awalias
Copy link
Member

awalias commented Sep 28, 2021

just linking this here, I think it will be fixed by this change?

https://github.com/supabase/infrastructure/issues/1486

@kangmingtay
Copy link
Member Author

just linking this here, I think it will be fixed by this change?

supabase/infrastructure#1486

@awalias i think this issue was already fixed here

@dshukertjr
Copy link
Member

We ran into failing test on Gotrue-Dart with the latest Gotrue docker image where the user.AppMetaData["provider"] returned not string, but array of strings instead. I really like this update where you get a list of providers associated to a user, but this seems like a breaking change. Would this change go live on Supabase?

@kangmingtay
Copy link
Member Author

Hey @dshukertjr, yes this will be a breaking change and we'll make sure to document it down. It's not going to go live on Supabase just yet as we're still testing it out in our staging environment but we're definitely looking to deploy it to prod sometime in October.

@dshukertjr
Copy link
Member

Sounds good! Thanks @kangmingtay for for the explanation!

@bnjmnt4n
Copy link
Contributor

bnjmnt4n commented Oct 22, 2021

Will an API be exposed to allow modification of the list of providers associated with a given account? Potentially, this could be useful to allow addition of multiple login options for an account, which have a different email address than the original user account.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants