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

Immediate redirect to Provider signIn #721

Open
1 of 5 tasks
r4id4h opened this issue Mar 30, 2024 · 10 comments
Open
1 of 5 tasks

Immediate redirect to Provider signIn #721

r4id4h opened this issue Mar 30, 2024 · 10 comments
Assignees
Labels
question A question about NuxtAuth

Comments

@r4id4h
Copy link

r4id4h commented Mar 30, 2024

Describe the feature

We're aiming to implement a unified authentication experience across our two Nuxt applications, which are hosted on separate subdomains. The primary application is available at example.com, while the secondary application resides at app.example.com. Additionally, our Keycloak authentication server is hosted on auth.example.com. The goal is to facilitate a smooth user journey where a user can log in once at example.com, and then navigate to app.example.com via a button click, all while remaining authenticated.

Currently I can login at example.com then redirect to app.example.com (with globalAppMiddleware activated). I will then get the nuxt-auth Sign In page where I can click the button "Sign In with Keycloak" and I'm logged in since all the cookies and request headers are set correctly. Would it be possible to add a configuration to skip the signIn page and immediately redirect to the keycloak login?

Maybe I'm overseeing something and it's already possible to achieve this but I couldn't find anything about it.

How would you implement this?

No response

Additional information

  • Would you be willing to help implement this feature?

Provider

  • AuthJS
  • Local
  • Refresh
  • New Provider
@r4id4h r4id4h added enhancement An improvement that needs to be added pending An issue waiting for triage labels Mar 30, 2024
@r4id4h
Copy link
Author

r4id4h commented Mar 31, 2024

Nevermind, I achieved the wanted behaviour by just intercepting while bootstrapping and calling useAuth.signIn

@r4id4h r4id4h closed this as completed Mar 31, 2024
@zoey-kaiser zoey-kaiser added question A question about NuxtAuth and removed pending An issue waiting for triage enhancement An improvement that needs to be added labels Jun 27, 2024
@dhondtlaurens
Copy link

I am unsure why this issue was closed, as it seems the behavior is not aligning with the documentation provided here. According to the documentation, setting the defaultProvider should redirect unauthorised users directly to the provider’s sign-in page instead of displaying the app-login page.

@dhondtlaurens
Copy link

Additionally, I wanted to note that this behaviour worked as expected in version 0.7.2, but there seems to be a regression in version 0.8.0.

@zoey-kaiser zoey-kaiser reopened this Jul 22, 2024
@zoey-kaiser
Copy link
Member

Hi @dhondtlaurens 👋

I just tried to reproduce the error you outlined above and could not reproduce the issue. Here is the link to my test playground for this issue: https://github.com/zoey-kaiser/nuxt-auth-starters/tree/721/test-default-provider/starters/authjs-github

I set defaultProvider to github and when I navigated to a protected page, I was redirected to the Github OAuth connection page. (r1).

Would you be so kind to create a reproduction of this error? You are welcome to clone the repository I linked above and attempt to reproduce the issue 😊

R1:
https://github.com/user-attachments/assets/f5aae2fd-ea5c-4aa5-a63f-c213962cc225

dhondtlaurens pushed a commit to dhondtlaurens/nuxt-auth-starters-issue-721 that referenced this issue Jul 24, 2024
@dhondtlaurens
Copy link

dhondtlaurens commented Jul 24, 2024

Hi @zoey-kaiser 👋

I’ve successfully reproduced the issue. You can find the forked repository I used for testing at this link: https://github.com/dhondtlaurens/nuxt-auth-starters-issue-721.

In my setup, I configured the defaultProvider to github in nuxt.config.ts and disabled the custom sign-in page in [...].ts. With globalAppMiddleware enabled, unauthenticated users are redirected to the GitHub OAuth page when clicking on the Secured Page link. However, if navigating directly to http://localhost:3000/secure, the app-login page is displayed instead. (R1)

Additionally, I encountered the following error when navigating directly to the secured page:

[nuxt] [request error] [unhandled] [500] The first argument must be of type string or an instance of Buffer, ArrayBuffer Array, or an Array-like Object. Received an instance of URLSearchParams

Please let me know if you need any more details or if there’s anything else I can assist with!

R1:
https://github.com/user-attachments/assets/9a6104d8-05c1-42b1-b1f2-88fab50d4456

@zoey-kaiser
Copy link
Member

zoey-kaiser commented Jul 24, 2024

Hi @dhondtlaurens 👋

Thanks for the fantastic reproduction! The only difference between our setups is that I did not remove the custom login page! I'll test out removing that from my app, too; otherwise, I work based on your reproduction!

Ill also look into the behavior differences between navigating to a page vs. opening it directly via a link!

Ill have some time tomorrow and keep you updated on the progress!

@gabrielws
Copy link

gabrielws commented Aug 14, 2024

Hi, any progress? I'm implementing IBM Verify and I wanted it to be redirected directly to the provider, and I'm also getting the error mentioned above:

ERROR  [nuxt] [request error] [unhandled] [500] The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received an instance of URLSearchParams

image

@dhondtlaurens
Copy link

Hi @zoey-kaiser

Thank you for your continued support with this issue. I wanted to check in to see if there have been any updates since I provided the reproduction. If there are any plans to address this, I’d be happy to assist further in identifying the issue or working on a fix. I appreciate all the effort you’re putting into resolving this.

Looking forward to your feedback.

Best regards,
Laurens D’Hondt

@zoey-kaiser
Copy link
Member

Hi @dhondtlaurens 👋

I have this issue on my TODO for the next steps after the last 0.9.0 release! I was sadly still pretty busy with the changes for that release and deprioritized this, as it needs a small investigation! Ill keep you posted 😊

@zoey-kaiser zoey-kaiser self-assigned this Aug 26, 2024
@Ibrahimmushtaq98
Copy link

Hi, this happens for me in the Middleware, I suspect initially the page doesn't set the CSRF cookies and thats why app login page instead of the provider login page. There is a similar issue #928

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question A question about NuxtAuth
Projects
None yet
Development

No branches or pull requests

5 participants