Your question
We run our own oAuth provider at work, and I'm trying to write an integration for it in next-auth, however i'm running into an issue when signing in where it's erroring with Missing or invalid provider account. having debugged the code, it seems to be missing an id on the providerAccount in the callback-handler.js.
What are you trying to do
Using this as my custom provider, I should be able to login to our own oAuth2 service.
{
id: 'openimp',
name: 'OpenImp',
type: 'oauth',
version: '2.0',
accessTokenUrl: 'https://auth.example.com/oauth/token',
authorizationUrl: 'https://auth.example.com/dialog/authorise?response_type=code',
profileUrl: 'https://auth.example.com/api/userinfo',
scope: [],
params: { grant_type: 'authorization_code' },
profile: (profile) => {
return {
username: profile.identifier,
name: profile.cn + ' ' + profile.sn,
email: profile.email,
};
},
clientId: 'blah',
clientSecret: 'secretblah',
}
instead it returns an error of:
[next-auth][error][oauth_callback_handler_error] Error: Missing or invalid provider account
at /Users/jared/Projects/ssh-key-service/src/frontend/node_modules/next-auth/dist/server/lib/callback-handler.js:33:15
at Generator.next (<anonymous>)
at asyncGeneratorStep (/Users/jared/Projects/ssh-key-service/src/frontend/node_modules/next-auth/dist/server/lib/callback-handler.js:20:103)
at _next (/Users/jared/Projects/ssh-key-service/src/frontend/node_modules/next-auth/dist/server/lib/callback-handler.js:22:194)
at /Users/jared/Projects/ssh-key-service/src/frontend/node_modules/next-auth/dist/server/lib/callback-handler.js:22:364
at new Promise (<anonymous>)
at /Users/jared/Projects/ssh-key-service/src/frontend/node_modules/next-auth/dist/server/lib/callback-handler.js:22:97
at /Users/jared/Projects/ssh-key-service/src/frontend/node_modules/next-auth/dist/server/lib/callback-handler.js:186:17
at /Users/jared/Projects/ssh-key-service/src/frontend/node_modules/next-auth/dist/server/routes/callback.js:108:54
at Generator.next (<anonymous>)
https://next-auth.js.org/errors#oauth_callback_handler_error
The providerAccount looks like:
{
provider: 'openimp',
type: 'oauth',
id: undefined,
refreshToken: undefined,
accessToken: 'long token',
accessTokenExpires: null
}
Is my code wrong, or is our oAuth2 service oncorrectly setup?
Feedback
Documentation refers to searching through online documentation, code comments and issue history. The example project refers to next-auth-example.
Hi there,
If you return the username as id from in profile function, that should resolve your problem!
profile: (profile) => {
return {
// Return Username as ID
// username: profile.identifier,
id: profile.identifier,
name: profile.cn + ' ' + profile.sn,
email: profile.email,
};
},
Note: The ID can be a string or an int, it only needs to be unique to your provider.
that did work indeed... thank you
Most helpful comment
Hi there,
If you return the
usernameasidfrom in profile function, that should resolve your problem!Note: The ID can be a string or an int, it only needs to be unique to your provider.