-
Notifications
You must be signed in to change notification settings - Fork 4k
feat(core): add allowedAccountTokens option #4893
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
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
|
Thanks for opening a PR about this! I think explicitly having the user acknowledge the fields their provider returns and making them make adjustments in the config for them will drastically reduce these types of issues. The user should know then, that if thye want to let through and store an additional field, that they will have to add it to their DB schema as well. I dont really have a strong opinion on the API design aspect of this though - maybe @balazsorban44 does. |
|
I don't like the idea of adding yet another option. We cannot control what comes back from an OAuth provider, so we just forward anything to the adapter. It's up to the adapter to handle the data and mediate with the database. IMO, the correct way would be to simply better document overriding adapter methods to accommodate for this use case. For any adapter, you could override the
In a one-liner like this: // You already have this somewhere
import { PrismaAdapter } from "@next-auth/prisma-adapter"
import { PrismaClient } from "@prisma/client"
const prisma = new PrismaClient()
const adapter = PrismaAdapter(prisma)
// Only change necessary
adapter.linkAccount = ({_unwanted, ...data}) => adapter.linkAccount(data)One of the reasons of simplifying the adapter to a function that returns an object since v3 (where it was usually a class), was to make overriding methods super easy. It just hasn't been documented well yet. |
|
I am well aware of the code you posted but it is not any more safe to use than no filtering at all. If a provider simply adds a new field this will break production. At least something like this would be required: authAdapter.linkAccount = ({
providerAccountId,
userId,
provider,
type,
refresh_token,
access_token,
expires_at,
token_type,
scope,
id_token,
session_state,
}) =>
authAdapter.linkAccount({
providerAccountId,
userId,
provider,
type,
refresh_token,
access_token,
expires_at,
token_type,
scope,
id_token,
session_state,
});IMHO its next-auth's responsibility to provide a "just works like in the docs" and "does not break randomly in the future" solution to this. And not manually patching the adapter (as can be seen by the issues that just follow the Getting Started guide with a different provider and run into this problem). Moving this option to the adapters that have a strict schema like Prisma and the other ORMs would also be a option. |
|
While this addresses a pain point for the library usage with special OAuth providers, I too don't feel like adding a new configuration is a good approach. |
|
While I like your idea @ThangHuuVu there is still one pain point for me:
if the provider decides to add a new field to the response this will break all existing deployed instances of next-auth. |
This have a HUGE impact... everytime a provider adds a new options, this will break all the applications in productions. |
|
@balazsorban44 @ThangHuuVu for sure this one is breaking a lot of production apps... at least for Azure AD or GitHub based (see related issues above) |
|
My 5 cents on the topic... possible behavior could be simply next-auth ignores the optional parameter, launches a warning but does not crash. |
If I'm not mistaken, this leads to a recursion and eventually to a Here's my approach to ignore Keycloak's const adapter = PrismaAdapter(prisma);
const _linkAccount = adapter.linkAccount;
adapter.linkAccount = (account) => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { 'not-before-policy': _, refresh_expires_in, ...data } = account;
return _linkAccount(data);
};
In general, I agree that it'd probably be better to explicitly specify all attributes to avoid breaking your application if your provider decides to deliver additional (unknown) properties in the future. |
|
Is there any consensus on a fix for this? Trying to get Azure AD auth working... |
09c0529 to
4c477bd
Compare
19c6807 to
3be7bb7
Compare
☕️ Reasoning
Just came about the problem described in #4516 when trying to use the GitLab provider.
I could simply add the missing fields to my Prisma schema or remove it in a custom prisma adapter but I would rather not bloat it with unnecessary fields.
This PR introduces a new optional option to configure which fields from the provider will be stored on the
Account:I am not fixed on a proper name yet. Maybe
allowedAccountFieldsmakes more sense to not confuse this with anything related to the JWT tokens.🧢 Checklist
🎫 Affected issues
Fixes #3818 (only the original issue, not the second part of the discussion)
Fixes #4515
Fixes #3823
Fixes #3067