NocturnalOne
NocturnalOne

Reputation: 69

nextauth with custom Okta provider

The next-auth npm package by default uses a Standard Okta Domain authorization server, of the form https://${yourOktaDomain}/oauth2. I have to connect to a Custom Okta Authorization server, of the form: https://${yourOktaDomain}/oauth2/${authServerId}. Question is: How do I configure nextauth to recognize that the Okta authorization server I need is a Custom server? Without this information, NextAuth does not form a proper URI. I could not find a config option on the NextAuth site 1

Upvotes: 1

Views: 2759

Answers (2)

MTT
MTT

Reputation: 318

Some issues that come up similar to this can be solved by using Next-Auth v4 beta. https://github.com/nextauthjs/next-auth/tree/beta

Upvotes: 0

Iain Collins
Iain Collins

Reputation: 6884

You can override any of the settings on a NextAuth.js provider by specifying them when using the provider, as 'providers' are really just JSON objects.

e.g. You can add an authorizationUrl property like this:

import Providers from `next-auth/providers`
/* ... */
providers: [
  Providers.Okta({
    clientId: process.env.OKTA_CLIENT_ID,
    clientSecret: process.env.OKTA_CLIENT_SECRET,
    domain: process.env.OKTA_DOMAIN,
    authorizationUrl: `https://${yourOktaDomain}/oauth2/${authServerId}?response_type=code`
  })
}
/* ... */

The default provider config options for Okta are here: https://github.com/nextauthjs/next-auth/blob/main/src/providers/okta.js

There is actually a Pull Request for this in flight which should address this out of the box. I think it has the changes you need so might be worth checking out what's been changed in it and specifying that in your app.

(Would be great if you could leave feedback on that PR if those options work for you!)

Upvotes: 2

Related Questions