Implemeting Notion OAuth2
Hey! I have tried everything now to implement the Oauth2 flow for Notion, but I always get this error. Anyone has any ideas what could cause it?

16 Replies
I also get this error on the client

It is receiving an incorrect client_id and client_secret
That's really the only reason I know of that notion will respond with that error code
Could this be because they want it encoded in Base64 and BetterAuth doesn't do that?

better-auth should be doing it internally.
If its not, then something is wrong about that.
Not sure. I used Remix OAuth2 before and did not change anything apart from the callback URL as specified in the OAuth2 plugin here
I haven't used better-auth's generic oauth2 implementation so I can't offer more help than what I have already stated. So either better-auth isn't base64 encoding the id and secret or your id and secret are wrong
try adding
{ authentication: 'basic' }
in the configLifesaver! Now I have a email_is_missing error, but it looks like the flow went through. Thanks 🙏
email_is_missing means the oauth is not returning a email in data
try checking the socpes
I think it is because the request to api.notion.com/v1/users/me fails with a 40I. From the error it seems like Better-auth doesn't pass the authorization header when requesting, which Notion requires

ok try this
it is the endpoint which returns user data?
Yup, it is. https://developers.notion.com/reference/get-self
Notion API
Retrieve your token's bot user
Retrieves the bot User associated with the API token provided in the authorization header. The bot will have an owner field with information about the person who authorized the integration. Errors Each Public API endpoint can return several possible error codes. See the Error codes section of the St...
you can just implement your custom function if the normal one is not working
getUserInfo(tokens) {...}
access tokens, call the api, return dataThanks! WIll figure that out 🙌