'500 Internal Server Error' with Bungie Provider
See original GitHub issueQuestion 💬
I’m trying to get Next Auth working with Bungie. There is a provider included with Next Auth, but it doesn’t work out of the box. I have solved one problem with it, but am now stumped with a second.
Bungie requires a few unique things for their Oauth. One, you need to use https even locally. Two, you can’t use ‘localhost’. You need 127.0.0.1 or something configured in your hosts file. I have that setup – Next is running with SSL on 127.0.0.1. I have even configured the GitHub Provider and that continues to work perfectly.
The first thing I did is recreate the Provider as a file/import within my project so I could modify it. I needed to change that authorization line to the following as Bungie errors out if you send any scope.
authorization: {
url: 'https://www.bungie.net/en/OAuth/Authorize?reauth=true',
params: {
scope: '',
},
},
Now I am getting the following error after approving the request on Bungie’s site. Again, the GitHub provider continues to work while Bungie is giving this error. I also got confirmation that I had authorized the app on my Bungie account the first time I completed this.
[next-auth][error][OAUTH_CALLBACK_ERROR]
https://next-auth.js.org/errors#oauth_callback_error expected 200 OK, got: 500 Internal Server Error {
error: {
message: 'expected 200 OK, got: 500 Internal Server Error',
stack: 'OPError: expected 200 OK, got: 500 Internal Server Error\n' +
' at processResponse (F:\\websites\\projects\\destiny-watch\\node_modules\\openid-client\\lib\\helpers\\process_response.js:41:11)\n' +
' at Client.userinfo (F:\\websites\\projects\\destiny-watch\\node_modules\\openid-client\\lib\\client.js:1257:18)\n' +
' at processTicksAndRejections (node:internal/process/task_queues:96:5)\n' +
' at async oAuthCallback (F:\\websites\\projects\\destiny-watch\\node_modules\\next-auth\\core\\lib\\oauth\\callback.js:134:17)\n' +
' at async Object.callback (F:\\websites\\projects\\destiny-watch\\node_modules\\next-auth\\core\\routes\\callback.js:50:11)\n' +
' at async NextAuthHandler (F:\\websites\\projects\\destiny-watch\\node_modules\\next-auth\\core\\index.js:139:28)\n' +
' at async NextAuthNextHandler (F:\\websites\\projects\\destiny-watch\\node_modules\\next-auth\\next\\index.js:21:19)\n' +
' at async F:\\websites\\projects\\destiny-watch\\node_modules\\next-auth\\next\\index.js:57:32\n' +
' at async Object.apiResolver (F:\\websites\\projects\\destiny-watch\\node_modules\\next\\dist\\server\\api-utils\\node.js:185:9)\n' +
' at async DevServer.runApi (F:\\websites\\projects\\destiny-watch\\node_modules\\next\\dist\\server\\next-server.js:395:9)',
name: 'OPError'
},
providerId: 'bungie2',
message: 'expected 200 OK, got: 500 Internal Server Error'
}
How to reproduce ☕️
- Install Next, Next Auth
- Configure Next to use SSL and 127.0.0.1, including adding
NEXTAUTH_URL=https://127.0.0.1:3000
to .env files. I followed the instructions at https://next-auth.js.org/providers/bungie and the linked page (https://medium.com/@anMagpie/secure-your-local-development-server-with-https-next-js-81ac6b8b3d68) - Create my own provider for Bungie based off of the one that ships with Next. See https://github.com/royanger/destiny-item-watch/blob/86c0468da7d35c27523c9095d4a39775e8f3c652/libs/auth/bungie.js
- Configure Bungie App (see image)
- Run Next app and attempt to login via Bungie.
The follow is the output from the procees:
[next-auth][debug][CREATE_STATE] { state: 'tFS-qq68Dx7D-q58oq_FkSb82WBVp3IM9YcoJa0kIO4', maxAge: 900 }
[next-auth][debug][GET_AUTHORIZATION_URL] {
url: 'https://www.bungie.net/en/OAuth/Authorize?reauth=true&client_id=40576&scope=&response_type=code&redirect_uri=https%3A%2F%2F127.0.0.1%3A3000%2Fapi%2Fauth%2Fcallback%2Fbungie2&state=tFS-qq68Dx7D-q58oq_FkSb82WBVp3IM9YcoJa0kIO4',
cookies: [
{
name: '__Secure-next-auth.state',
value: 'eyJhbGciOiJkaXIiLCJlbmMiOiJBMjU2R0NNIn0..dSzcoBCsMiZT7XyU.uZtRDBS1F4r-mZpcuKxdwgXoxXwm9N3vrqb9CnDyqqtVZ1qMZjOZh_gVUrZlBfdtRDrCHIwsMm6o6OrZKicuL2oGlka5kiMOgKpEQ6ehGDyrTrPt1fKmTvk92J1JBE1vBN-2Z-6ufK6cjUvSVQQScfh2mJ_r0f_9_QXOkm57e5xwjSHdAu8.679kdC7wStAQpoy2Ow_eDg',
options: [Object]
}
]
}
[next-auth][error][OAUTH_CALLBACK_ERROR]
https://next-auth.js.org/errors#oauth_callback_error expected 200 OK, got: 500 Internal Server Error {
error: {
message: 'expected 200 OK, got: 500 Internal Server Error',
stack: 'OPError: expected 200 OK, got: 500 Internal Server Error\n' +
' at processResponse (F:\\websites\\projects\\destiny-watch\\node_modules\\openid-client\\lib\\helpers\\process_response.js:41:11)\n' +
' at Client.userinfo (F:\\websites\\projects\\destiny-watch\\node_modules\\openid-client\\lib\\client.js:1257:18)\n' +
' at processTicksAndRejections (node:internal/process/task_queues:96:5)\n' +
' at async oAuthCallback (F:\\websites\\projects\\destiny-watch\\node_modules\\next-auth\\core\\lib\\oauth\\callback.js:134:17)\n' +
' at async Object.callback (F:\\websites\\projects\\destiny-watch\\node_modules\\next-auth\\core\\routes\\callback.js:50:11)\n' +
' at async NextAuthHandler (F:\\websites\\projects\\destiny-watch\\node_modules\\next-auth\\core\\index.js:139:28)\n' +
' at async NextAuthNextHandler (F:\\websites\\projects\\destiny-watch\\node_modules\\next-auth\\next\\index.js:21:19)\n' +
' at async F:\\websites\\projects\\destiny-watch\\node_modules\\next-auth\\next\\index.js:57:32\n' +
' at async Object.apiResolver (F:\\websites\\projects\\destiny-watch\\node_modules\\next\\dist\\server\\api-utils\\node.js:185:9)\n' +
' at async DevServer.runApi (F:\\websites\\projects\\destiny-watch\\node_modules\\next\\dist\\server\\next-server.js:395:9)',
name: 'OPError'
},
providerId: 'bungie2',
message: 'expected 200 OK, got: 500 Internal Server Error'
}
The repo is located at https://github.com/royanger/destiny-item-watch
Contributing 🙌🏽
Yes, I am willing to help answer this question in a PR
Issue Analytics
- State:
- Created a year ago
- Comments:16 (1 by maintainers)
Something I just recalled, and I’m not sure if you saw in the API docs as its barely mentioned, is that you need to be running https even locally for dev. You can’t auth with Bungie from http://localhost.
I ended up getting Bungie working for Passport and Remix-auth. I didn’t revisit this yet, as I haven’t needed to (I’m building with Vite+React and Passport). That said, there is a separate URL to that you can use for OAuth tools like this to get the membership info -> https://www.bungie.net/Platform/User/GetMembershipsForCurrentUser/ As you can see you don’t need a membershipID or anything.