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

Redirecting to originally blocked URL after login #74

Open
kryopix opened this issue Oct 18, 2024 · 2 comments
Open

Redirecting to originally blocked URL after login #74

kryopix opened this issue Oct 18, 2024 · 2 comments

Comments

@kryopix
Copy link

kryopix commented Oct 18, 2024

Hello,

I am using the nuxt-oidc-auth module in my Nuxt application and I’m wondering if it’s possible to redirect users back to the originally blocked URL after logging in via a provider (e.g., Keycloak), instead of redirecting them to a predefined page (e.g., redirectUri).

In sidebase/nuxt-auth, there is an option addDefaultCallbackUrl, which I tested, and it worked out of the box as expected. It is described in the documentation as follows:

addDefaultCallbackUrl
Type: boolean | string
Default: true
Whether to add a callbackUrl to sign in requests. Setting this to a string-value will result in that being used as the callbackUrl path. Setting this to true will result in the blocked original target path being chosen (if it can be determined).

Is this behavior possible with nuxt-oidc-auth, or is there a way to achieve this through middleware?

Here are my current Nuxt settings:

oidc: {
  defaultProvider: 'keycloak',
  providers: {
    keycloak: {
      audience: 'account',
      baseUrl: '',
      clientId: '',
      clientSecret: '',
      redirectUri: 'http://localhost:3200/auth/keycloak/callback',
      logoutRedirectUri: 'http://localhost:3200',
      userNameClaim: 'name'
    }
  },
  middleware: {
    globalMiddlewareEnabled: true,
    customLoginPage: false
  },
  session: {
    expirationCheck: true,
    automaticRefresh: true,
    maxAge: 0,
    cookie: {
      sameSite: 'strict',
      secure: true
    }
  }
}

I would prefer to use nuxt-oidc-auth as it works better for my use case and has more features, but I miss this functionality. Is there a way to replicate the behavior of sidebase/nuxt-auth, or can it be implemented via middleware?

Thanks in advance! I really appreciate all the hard work that has gone into this module - it’s been fantastic to work with.

@patrsc
Copy link

patrsc commented Oct 23, 2024

An additionally useful feature is to add an override parameter for the redirect URI to the login() function to allow setting the page where the user is redirected differently for different pages, for example like this:

A similar option should also be available for logout.

This would give the developer more freedom to redirect users to the most suitable page depending on context.
For example, in the user account management a "Delete account" button could first request a token with higher privileges (that requires re-authentication) from the identity provider, and then redirect to a page that actually deletes the account using an API request that need this token with higher privileges.

@itpropro
Copy link
Owner

Great idea! I will add this to the backlog, I think redirecting to the original URL would be a good addition in user experience.

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

No branches or pull requests

3 participants