Back

[SOLVED] Problem with setting up custom oauth2 provider

  • 0
  • Self Hosted
  • Users
eroo36
8 Mar, 2023, 12:13

Hello, so i tried adding my custom oauth server to the provider following https://github.com/appwrite/appwrite/blob/master/docs/tutorials/add-oauth2-provider.md#2-implement-new-provider and i was able to do it. This doc i believe is outdated a little bit but figured it somehow. 1- So i set up my client in appwrite(check second comment) 1.1- docker compose build && docker compose up -d 2- go to http://localhost/v1/account/sessions/oauth2/kollektor with project id and the response format headers, which redirects to the correct /authorize in my server then i login there 3- when login is complete and my server redirects to http://localhost/v1/account/sessions/oauth2/kollektor/redirect?project=6408533033ee5dbf1c1f&code=eyJhbG...&state={"success":"http:\/\/localhost\/auth\/oauth2\/success","failure":"http:\/\/localhost\/auth\/oauth2\/failure"}

4- Then i end up in page http://localhost/auth/oauth2/failure Missing Redirect URL Your OAuth login flow is missing a proper redirect URL. Please check the OAuth docs and send request for new session with a valid callback URL.

5- I check the logs of appwrite container:

TypeScript
appwrite  | [Error] Timestamp: 2023-03-08T11:56:17+00:00
appwrite  | [Error] Method: GET
appwrite  | [Error] URL: /v1/account/sessions/oauth2/:provider/redirect
appwrite  | [Error] Type: Appwrite\Extend\Exception
appwrite  | [Error] Message: Missing ID from OAuth2 provider.
appwrite  | [Error] File: /usr/src/code/app/controllers/api/account.php
appwrite  | [Error] Line: 460
appwrite  | [Error] Timestamp: 2023-03-08T11:56:18+00:00
appwrite  | [Error] Method: GET
appwrite  | [Error] URL: /v1/account
appwrite  | [Error] Type: Appwrite\Extend\Exception
appwrite  | [Error] Message: User (role: guests) missing scope (account)
appwrite  | [Error] File: /usr/src/code/app/controllers/general.php
appwrite  | [Error] Line: 365
TL;DR
The user had a problem setting up a custom OAuth2 provider with Appwrite. The error message "Missing ID from OAuth2 provider" was encountered. They mentioned that their OAuth server worked fine with a different project using the NextAuth package. The user provided some code files they changed in the project and the steps they followed.
eroo36
8 Mar, 2023, 12:14

the files i changed in the project:

src/Appwrite/Auth/OAuth2/Kollektor.php: https://codefile.io/f/AOuybXldR3AjOv04QEiD app/config/providers.php: https://codefile.io/f/iFZ5Y0rDBx3LW94xrWdz

added icons to console/static/icons/dark console/static/icons/light

eroo36
8 Mar, 2023, 12:21

My oauth server works fine when i tried it on a nextjs project using standard nextauth package and added custom provider there

Drake
8 Mar, 2023, 17:51

so this is the most important error:

TypeScript
appwrite  | [Error] Message: Missing ID from OAuth2 provider.

It seems like Appwrite isn't getting the user's ID from the OAuth2 provider.

eroo36
8 Mar, 2023, 17:54

okay i will check but as far as i saw it gets the user id from /user/me

eroo36
8 Mar, 2023, 17:55

but it is not called in the server

eroo36
8 Mar, 2023, 18:02

maybe i have a typo in function getUser(string $accessToken)

Drake
8 Mar, 2023, 18:33

I would dump the API response from the server to see what's getting returned

eroo36
9 Mar, 2023, 09:43

hello, thx again, problem was from my side id was returning as "sub" not "id"

eroo36
9 Mar, 2023, 09:43

sorry about that

Drake
9 Mar, 2023, 15:30

No worries! I'm glad you were able to figure it out! Oauth can be hard to troubleshoot

Drake
9 Mar, 2023, 15:31

[SOLVED] Problem with setting up custom oauth2 provider

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more