itpropro / nuxt-oidc-auth

OIDC (OpenID connect) focused auth module for Nuxt
https://nuxtoidc.cloud
MIT License
88 stars 23 forks source link

Token request failed - [nuxt-oidc-auth]: [POST] "https://github.com/login/oauth/access_token": <no response> fetch failed #44

Open DiogoCunhaMoreira opened 4 months ago

DiogoCunhaMoreira commented 4 months ago

Hello guys,

I'm having this error when trying to implement authentication in my webapp. I tryed the playground with github just to see if i could understand it better (like if i got a working example i could try to reproduce it in my app) but unfortunately i have the same error using github.

When i try to fetch the token with postman it works...

I also have this errors in vs-code:

image

This is what i have in my nuxt.config:

image

My .env:

image

Im redirected to github and 'im able to autenticate. The problem is while trying fetching the token (as far as i understand). I also printed in the console what is really being fetched and everything seems correct.

Can you help me please?

EDIT: I also tried with different different tokenRequestType and nothing.

UPDATE: What i found out is that you can't use a proxy while using this module because this is using ofetch without that option. I've downloaded the source code and changed the ofetch request in oidc.ts and it worked, now it can make the request correctly. Still have a problem with the session. I'm using nginx as a reverse proxy to redirect the redirect_uri used in the idp and when it arrives to the app the module is not able to retrieve the session.

Thanks a lot! Diogo

itpropro commented 3 months ago

Hi Diogo, would it help if we add proxy support with ofetch?

DiogoCunhaMoreira commented 3 months ago

Hi Diogo, would it help if we add proxy support with ofetch?

Hello Itpropro!

It would be awesome if you had proxy support.

I'm still struggling with retrieving the session when being redirected to my app. Using PKCE im not able to fetch the token because i loose the code verifier.

Do you have any tips?

Thanks a lot, Diogo

itpropro commented 3 months ago

Auth is generally hard to handle with proxies. I am currently looking into adding proxy support to the config to hand it over to ofetch. Any chance you can exclude the traffic between the backend and the IdP from your proxy?

DiogoCunhaMoreira commented 2 months ago

For now i'm using your source code with some changes in the ofetch call to include the proxy.

I can't exclude the trafic because i have security restrictions in my company.

Regarding the session problem, do you want me to open another issue?

Thanks a lot!

A quarta, 4/09/2024, 19:29, Jan-Henrik Damaschke @.***> escreveu:

Auth is generally hard to handle with proxies. I am currently looking into adding proxy support to the config to hand it over to ofetch. Any chance you can exclude the traffic between the backend and the IdP from your proxy?

— Reply to this email directly, view it on GitHub https://github.com/itpropro/nuxt-oidc-auth/issues/44#issuecomment-2330425431, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOQNUHVYWVYLWBG2BCXES7LZU6XYTAVCNFSM6AAAAABL4EFLACVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMZQGQZDKNBTGE . You are receiving this because you authored the thread.Message ID: @.***>

DiogoCunhaMoreira commented 2 months ago

Hi again itpropro,

Just sending a mensage because i didn't understand if in the end you were talking about the reverse proxy i'm using (Nginx) or the company proxy used in the ofetch to make the requests from my app.

Regarding the second, the problem was solved changing the ofetch call in the source code.

The first i'm still struggling with the session. At this moment i don't even understand if the issue is in the nginx configuration or in the module itself. Did you tried something similiar? (or anyone else)

Thanks a lot for all your help! Diogo

itpropro commented 1 month ago

Hi again itpropro,

Just sending a mensage because i didn't understand if in the end you were talking about the reverse proxy i'm using (Nginx) or the company proxy used in the ofetch to make the requests from my app.

Regarding the second, the problem was solved changing the ofetch call in the source code.

The first i'm still struggling with the session. At this moment i don't even understand if the issue is in the nginx configuration or in the module itself. Did you tried something similiar? (or anyone else)

Thanks a lot for all your help! Diogo

Hey, Can you maybe share the changes you did with the ofetch call? That way I could make it configurable in case other people run into a similar issue. It would be great if you could open the session problem in a separate issue so we can track that accordingly.

DiogoCunhaMoreira commented 1 month ago

Hi again itpropro, Just sending a mensage because i didn't understand if in the end you were talking about the reverse proxy i'm using (Nginx) or the company proxy used in the ofetch to make the requests from my app. Regarding the second, the problem was solved changing the ofetch call in the source code. The first i'm still struggling with the session. At this moment i don't even understand if the issue is in the nginx configuration or in the module itself. Did you tried something similiar? (or anyone else) Thanks a lot for all your help! Diogo

Hey, Can you maybe share the changes you did with the ofetch call? That way I could make it configurable in case other people run into a similar issue. It would be great if you could open the session problem in a separate issue so we can track that accordingly.

Hello!

Off course!

So i just changed in the server/handler/callback.ts (in the 0.17.0 version was in the server/lib/oidc.ts, other versions i don't know) the ofetch calls to retrieve the token (using the code previous sent by the idp) and also in the ofetch of the openIdConfiguration (if you have the token validation).

The change:

image

You will need the import: image

The requestTls also could be a nice feature, so if you are in development mode, using self-signed certificates, making the rejectUnauthorized: false, will bypass the certificate verification.

If you need anything else please let me know.

Thanks, Diogo