logto-io / logto

🧑‍🚀 The better identity infrastructure for developers and the open-source alternative to Auth0.
https://logto.io
Mozilla Public License 2.0
8.51k stars 423 forks source link

bug: redirect_uri` did not match any of the client's registered `redirect_uris when using Cloudflare Tunnel #6648

Open clho40 opened 6 days ago

clho40 commented 6 days ago

Describe the bug

The background is, I have a VPS, installed Coolify on it, and used Coolify's template to deploy a Logto application. My custom domain is parked on Cloudflare, and I use Cloudflare Tunnel to point the DNS to my VPS. and I have used Cloudflare's SSL/TLS redirect in order to redirect all the traffic from HTTP to HTTPS.

So the problem is, when I configure the ADMIN_ENDPOINT as http://logto-admin.mydomain.com, Cloudflare will automatically redirect the traffic to https://logto-admin.mydomain.com and when I click the Create Account button I get the following error

{
    "code": "oidc.invalid_redirect_uri",
    "message": "`redirect_uri` did not match any of the client's registered `redirect_uris`.",
    "error": "invalid_redirect_uri",
    "error_description": "redirect_uri did not match any of the client's registered redirect_uris",
    "state": "JKtuiY1FXwScYAPeMEGwBCFX80oyLtMx3C2oS9E-9ohfbboh9qorZCsSDzfkaGBb3bV4lAZIWUqmIecTtKdjHg",
    "iss": "http://logto-admin.mydomain.com/oidc"
}

It seems like Logto does not recognize the redirected URL? How do I solve this problem?

Expected behavior

How to reproduce?

Context

Screenshots

xiaoyijun commented 6 days ago

Hi @clho40 , set ADMIN_ENDPOINT to the URL you finally visited (https://logto-admin.mydomain.com).

And check the error content from the URL where you see the error json page:

{
    "code": "oidc.invalid_redirect_uri",
    "message": "`redirect_uri` did not match any of the client's registered `redirect_uris`.",
    "error": "invalid_redirect_uri",
    "error_description": "redirect_uri did not match any of the client's registered redirect_uris",
    "state": "JKtuiY1FXwScYAPeMEGwBCFX80oyLtMx3C2oS9E-9ohfbboh9qorZCsSDzfkaGBb3bV4lAZIWUqmIecTtKdjHg",
    "iss": "http://logto-admin.mydomain.com/oidc"
}

The URL will be like:

http://localhost:3001/oidc/auth?client_id=???&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Facallback&code_challenge=....

from the URL, you will see the callback uri actually used, and add the URI to the application's redirect uri field:

image
clho40 commented 6 days ago

Hello,

I can't set the ADMIN_ENDPOINT to https - I get the error logto-admin.mydomain.com redirected you too many times. because Cloudflare redirects the traffic.

I get this even before I can login to the portal Screenshot 2024-10-01 093851 Screenshot 2024-10-01 093947

a0zzy commented 2 days ago

+1 Same exact issue

a0zzy commented 2 days ago

I was able to get around this by changing "https" to "http" for a quick workaround and it allowed me to create an account and login, but I was not able to get to the dashboard because I get this error:

Screenshot 2024-10-04 at 13 09 10 Screenshot 2024-10-04 at 13 09 33