Skip to content

Dynamic authorizationParameters #2173

Open
@cristianbriscaru

Description

@cristianbriscaru

Checklist

  • I have looked into the Readme, Examples, and FAQ and have not found a suitable solution or answer.
    I have looked into the API documentation and have not found a suitable solution or answer.
    I have searched the issues and have not found a suitable solution or answer.
    I have searched the Auth0 Community forums and have not found a suitable solution or answer.
    I agree to the terms within the Auth0 Code of Conduct.

Describe the problem you'd like to have solved

Currently we are passing the authorizationParameters when instantiating the Auth0Client which is a 'singleton' leaving us with no way to pass dynamic authorizationParameters.
I have a use case where in some instances we want to redirect a user directly to the signup page, we use Classic Login and we want to pass an extra authorization param 'action':'signup' and we added custom code in auth0 Classic Login initialScreen: config.extraParams.action === "signup" ? "signUp" : "login", but because we can't pass dynamic authorizationParameters we have no way of doing this.
Any ideea how we can accomplish this ?

Describe the ideal solution

To have a way to dynamically pass authorizationParameters when using auth0Client.middleware(request);

Alternatives and current workarounds

No viable workaround available, only way to do it is to create a new Auth0Client for each request which is not feasible

export const auth0 = new Auth0Client(getAuth0ClientConfig());

const signupAuth0 = new Auth0Client(getAuth0ClientConfig('signup'));

export const auth0Middleware = (request: NextRequest) => {
  let auth0Client = auth0;

  if(request.nextUrl.searchParams.has("action", "signup")){
    auth0Client = signupAuth0;
  }

  return auth0Client.middleware(request);
}

function getAuth0ClientConfig(authorizationParametersAction?: string): Auth0ClientOptions {
  return {
    domain: process.env.AUTH0_DOMAIN,
    clientId: process.env.AUTH0_CLIENT_ID,
    clientSecret: process.env.AUTH0_CLIENT_SECRET,
    appBaseUrl: process.env.NEXT_PUBLIC_APP_BASE_URL,
    secret: process.env.AUTH0_SECRET,
    authorizationParameters: {
      action: authorizationParametersAction,
      audience: process.env.AUTH0_AUDIENCE,
    }
  }
}

Additional context

No response

Activity

guabu

guabu commented on Jun 17, 2025

@guabu
Contributor

Hey @cristianbriscaru 👋 Passing the action in the query parameter to the /auth/login endpoint from the client will cause the parameter to be forwarded to the authorize endpoint. This is documented here: https://github.com/auth0/nextjs-auth0/blob/main/EXAMPLES.md#passing-authorization-parameters

For example, redirecting the user to: /auth/login?action=signup will result in action=signup being sent to the /authorize endpoint.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @frederikprijck@cristianbriscaru@guabu

        Issue actions

          Dynamic authorizationParameters · Issue #2173 · auth0/nextjs-auth0