Server-side redirect for Auth0 Organization login in nodejs/express app

I am relatively new to Auth0 but have experience building identity services. I am trying to do something that seems simple but I am struggling with the impl.

In our nodejs express multi-tenant app, I would like to expose an endpoint like /customer/:name/login that will redirect the user to their Auth0 Organization login page. I already have Organizations configured. In our database, we will associate customer name with organization ID, so I have access to the Auth0 org ID on the server. The flow I want is GET /customer/:name/login → look up org ID → redirect to Auth0 login → redirect to app callback page.

The Auth0 documentation refers to calling the authorize endpoint but delegates the details to an Auth0 SDK. I looked at these libraries:

  • passport-auth0: I am not excited about the session requirement when using passport-auth0; this is a new dependency our app does not currently have.
  • express-openid-connect: Simpler than passport config, and also handles the session requirement by storing state in encrypted cookies. This blog suggests preferring express-openid-connect for new projects as a replacement for passport-auth0; however, I can’t find a way to specify an organization ID to express-openid-connect.

I feel like I’m overcomplicating this; can you help clarify which library would be better for my use case and provide any implementation tips?

1 Like

I ended up using express-openid-connect and found I can pass the claim I want to it:

res.oidc.login({
    authorizationParams: {
        organization: <organization_id>
    }
})
1 Like

This really should be added to the official documentation. It is very, very absent from the quickstart and the express-openid-connect doc.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.