Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PKCE functionality to support authentication in SPAs #109

Open
amandesai01 opened this issue Jun 24, 2024 · 4 comments
Open

Add PKCE functionality to support authentication in SPAs #109

amandesai01 opened this issue Jun 24, 2024 · 4 comments
Labels
enhancement New feature or request

Comments

@amandesai01
Copy link

I am very well aware of the efforts taken in #12, however, I do not agree with the implementation.

PKCEs are a way for SPAs to authenticate securely. They are protected by redirect_uris and use SHA-256 checksum to prevent XSS attacks.
They are pretty well adopted and almost all decent auth providers allow PKCE for authentication.

Therefore, implementing PKCE for server side code doesn't make sense. Also, PR is not being actively worked on.

Implementation Proposal:
A Nuxt plugin for providers which runs client side and performs PKCE logic.

Ref: https://github.com/bitinflow/nuxt-oauth/blob/main/src/runtime/plugin.ts

I am open to PR if we are going to merge it.

@atinux atinux added the enhancement New feature or request label Jul 30, 2024
@atinux
Copy link
Owner

atinux commented Jul 30, 2024

Thanks for the issue, this module is focused on Nuxt applications running with a server so far (and it's already quite complex).

I like the idea of the plugin but yours is working only for one specific OAuth endpoint right? We will need to have the logic for each provider in this case.

@amandesai01
Copy link
Author

Yes, my proposal is to have similar system like in backend. Implement general PKCE and let it be customisable.

@shgnplaatjies
Copy link

Yes, my proposal is to have similar system like in backend. Implement general PKCE and let it be customisable.

Have you implemented a workaround? I'm trying to integrate this into a SPA as well and bumped into a AADSTS9002325: Proof Key for Code Exchange is required for cross-origin authorization code redemption. error from Microsoft Entra ID.

@itpropro
Copy link

itpropro commented Sep 26, 2024

Thanks for the issue, this module is focused on Nuxt applications running with a server so far (and it's already quite complex).

I like the idea of the plugin but yours is working only for one specific OAuth endpoint right? We will need to have the logic for each provider in this case.

PKCE should also be used on a confidential client flow (auth code grant with a client secret) and the implementation logic should not differ between server side client side, so the utility can be universal. There are even IdPs like Zitadel who offer a PKCE only flow (no client secret).

The steps would be

  1. Generate and store a PkceVerifier in the current authorization flow session
  2. Generate a PkceCodeChallenge based on the PkceVerifier and attach it to the login request in the code_challenge field
  3. When sending the callback token request to get a access (and/or id) token, add the PkceVerifier in the code_verifier field
  4. Clear the temporary auth session used during oauth flow and use the user session or clear the PKCE fields

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants