Skip to main content


Authentication Providers in NextAuth.js are services that can be used to sign in (OAuth, Email, etc).

Sign in with OAuth#

NextAuth.js is designed to work with any OAuth service, it supports OAuth 1.0, 1.0A and 2.0 and has built-in support for many popular OAuth sign-in services.

Built-in OAuth providers#

Using a built-in OAuth provider#

  1. Register your application at the developer portal of your provider. There are links above to the developer docs for most supported providers with details on how to register your application.

  2. The redirect URI should follow this format:


    For example, Twitter on localhost this would be:

  3. Create a .env file at the root of your project and add the client ID and client secret. For Twitter this would be:

  4. Now you can add the provider settings to the NextAuth options object. You can add as many OAuth providers as you like, as you can see providers is an array.

    import Providers from `next-auth/providers`
    providers: [
    clientId: process.env.TWITTER_ID,
    clientSecret: process.env.TWITTER_SECRET
  5. Once a provider has been setup, you can sign in at the following URL: [origin]/api/auth/signin. This is an unbranded auto-generated page with all the configured providers.

Signin Screenshot

Using a custom provider#

You can use an OAuth provider that isn't built-in by using a custom object.

As an example of what this looks like, this is the provider object returned for the Google provider:

id: "google",
name: "Google",
type: "oauth",
version: "2.0",
scope: "",
params: { grant_type: "authorization_code" },
accessTokenUrl: "",
requestTokenUrl: "",
authorizationUrl: "",
profileUrl: "",
async profile(profile, tokens) {
// You can use the tokens, in case you want to fetch more profile information
// For example several OAuth provider does not return e-mail by default.
// Depending on your provider, will have tokens like `access_token`, `id_token` and or `refresh_token`
return {
image: profile.picture
clientId: "",
clientSecret: ""

You can replace all the options in this JSON object with the ones from your custom provider - be sure to give it a unique ID and specify the correct OAuth version - and add it to the providers option:

import Providers from `next-auth/providers`
providers: [
clientId: process.env.TWITTER_ID,
clientSecret: process.env.TWITTER_SECRET,
id: 'customProvider',
name: 'CustomProvider',
type: 'oauth',
version: '2.0',
scope: '' // Make sure to request the users email address

OAuth provider options#

idUnique ID for the providerstringYes
nameDescriptive name for the providerstringYes
typeType of provider, in this case it should be oauthoauth, email, credentialsYes
versionOAuth version (e.g. '1.0', '1.0a', '2.0')stringYes
accessTokenUrlEndpoint to retrieve an access tokenstringYes
authorizationUrlEndpoint to request authorization from the userstringYes
clientIdClient ID of the OAuth providerstringYes
clientSecretClient Secret of the OAuth providerstringNo
scopeOAuth access scopes (expects array or string)string or string[]No
paramsAdditional authorization URL parametersobjectNo
requestTokenUrlEndpoint to retrieve a request tokenstringNo
authorizationParamsAdditional params to be sent to the authorization endpointobjectNo
profileUrlEndpoint to retrieve the user's profilestringNo
profileAn callback returning an object with the user's infoobjectNo
idTokenSet to true for services that use ID Tokens (e.g. OpenID)booleanNo
headersAny headers that should be sent to the OAuth providerobjectNo
protectionAdditional security for OAuth login flows (defaults to state)[pkce],[state],[pkce,state]No
stateSame as protection: "state". Being deprecated, use protection.booleanNo

Sign in with Email#

The Email provider uses email to send "magic links" that can be used sign in, you will likely have seen them before if you have used software like Slack.

Adding support for signing in via email in addition to one or more OAuth services provides a way for users to sign in if they lose access to their OAuth account (e.g. if it is locked or deleted).

Configuration is similar to other providers, but the options are different:

import Providers from `next-auth/providers`
providers: [
server: process.env.EMAIL_SERVER,
from: process.env.EMAIL_FROM,
// maxAge: 24 * 60 * 60, // How long email links are valid for (default 24h)

See the Email provider documentation for more information on how to configure email sign in.


The email provider requires a database, it cannot be used without one.

Sign in with Credentials#

The Credentials provider allows you to handle signing in with arbitrary credentials, such as a username and password, two factor authentication or hardware device (e.g. YubiKey U2F / FIDO).

It is intended to support use cases where you have an existing system you need to authenticate users against.

import Providers from `next-auth/providers`
providers: [
// The name to display on the sign in form (e.g. 'Sign in with...')
name: 'Credentials',
// The credentials is used to generate a suitable form on the sign in page.
// You can specify whatever fields you are expecting to be submitted.
// e.g. domain, username, password, 2FA token, etc.
credentials: {
username: { label: "Username", type: "text", placeholder: "jsmith" },
password: { label: "Password", type: "password" }
async authorize(credentials) {
const user = (credentials) => {
// You need to provide your own logic here that takes the credentials
// submitted and returns either a object representing a user or value
// that is false/null if the credentials are invalid.
// e.g. return { id: 1, name: 'J Smith', email: '' }
return null
if (user) {
// Any user object returned here will be saved in the JSON Web Token
return user
} else {
return null

See the Credentials provider documentation for more information.


The Credentials provider can only be used if JSON Web Tokens are enabled for sessions. Users authenticated with the Credentials provider are not persisted in the database.

Adding a new built-in provider#

If you think your custom provider might be useful to others, we encourage you to open a PR and add it to the built-in list so others can discover it much more easily! You only need to add two changes:

  1. Add your config: src/providers/{provider}.js (Make sure you use a named default export, like export default function YourProvider!)
  2. Add provider documentation: www/docs/providers/{provider}.md

That's it! ๐ŸŽ‰ Others will be able to discover this provider much more easily now!

You can look at the existing built-in providers for inspiration.