forked from nextauthjs/next-auth
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f705034
commit 82e107c
Showing
3 changed files
with
139 additions
and
243 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,9 +47,5 @@ [email protected] | |
# MongoDB: DATABASE_URL=mongodb://nextauth:[email protected]:27017/nextauth?synchronize=true | ||
DATABASE_URL= | ||
|
||
BOXYHQSAML_ISSUER="https://jackson-demo.boxyhq.com" | ||
BOXYHQSAML_ID="tenant=boxyhq.com&product=saml-demo.boxyhq.com" | ||
BOXYHQSAML_SECRET="dummy" | ||
|
||
WIKIMEDIA_ID= | ||
WIKIMEDIA_SECRET= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,251 +1,142 @@ | ||
import NextAuth, { NextAuthOptions } from "next-auth" | ||
// import EmailProvider from "next-auth/providers/email" | ||
import GitHubProvider from "next-auth/providers/github" | ||
import Auth0Provider from "next-auth/providers/auth0" | ||
import KeycloakProvider from "next-auth/providers/keycloak" | ||
import TwitterProvider, { | ||
// TwitterLegacy as TwitterLegacyProvider, | ||
} from "next-auth/providers/twitter" | ||
import CredentialsProvider from "next-auth/providers/credentials" | ||
import IDS4Provider from "next-auth/providers/identity-server4" | ||
import DuendeIDS6Provider from "next-auth/providers/duende-identity-server6" | ||
import Twitch from "next-auth/providers/twitch" | ||
import GoogleProvider from "next-auth/providers/google" | ||
import FacebookProvider from "next-auth/providers/facebook" | ||
import FoursquareProvider from "next-auth/providers/foursquare" | ||
// import FreshbooksProvider from "next-auth/providers/freshbooks" | ||
import GitlabProvider from "next-auth/providers/gitlab" | ||
import InstagramProvider from "next-auth/providers/instagram" | ||
import LineProvider from "next-auth/providers/line" | ||
import LinkedInProvider from "next-auth/providers/linkedin" | ||
import MailchimpProvider from "next-auth/providers/mailchimp" | ||
import DiscordProvider from "next-auth/providers/discord" | ||
import AzureADProvider from "next-auth/providers/azure-ad" | ||
import SpotifyProvider from "next-auth/providers/spotify" | ||
import CognitoProvider from "next-auth/providers/cognito" | ||
import SlackProvider from "next-auth/providers/slack" | ||
import Okta from "next-auth/providers/okta" | ||
import AzureB2C from "next-auth/providers/azure-ad-b2c" | ||
import OsuProvider from "next-auth/providers/osu" | ||
import AppleProvider from "next-auth/providers/apple" | ||
import PatreonProvider from "next-auth/providers/patreon" | ||
import TraktProvider from "next-auth/providers/trakt" | ||
import WorkOSProvider from "next-auth/providers/workos" | ||
import BoxyHQSAMLProvider from "next-auth/providers/boxyhq-saml" | ||
import WikimediaProvider from "next-auth/providers/wikimedia" | ||
import VkProvider from "next-auth/providers/vk" | ||
|
||
// TypeORM | ||
// import { TypeORMLegacyAdapter } from "@next-auth/typeorm-legacy-adapter" | ||
// const adapter = TypeORMLegacyAdapter({ | ||
// type: "sqlite", | ||
// name: "next-auth-test-memory", | ||
// database: "./typeorm/dev.db", | ||
// synchronize: true, | ||
// }) | ||
import NextAuth from "next-auth" | ||
import type { NextAuthOptions } from "next-auth" | ||
|
||
// // Prisma | ||
// import { PrismaAdapter } from "@next-auth/prisma-adapter" | ||
// import { PrismaClient } from "@prisma/client" | ||
// const prisma = new PrismaClient() | ||
// const adapter = PrismaAdapter(prisma) | ||
// Providers | ||
import Apple from "next-auth/providers/apple" | ||
import Auth0 from "next-auth/providers/auth0" | ||
import AzureAD from "next-auth/providers/azure-ad" | ||
import AzureB2C from "next-auth/providers/azure-ad-b2c" | ||
import BoxyHQSAML from "next-auth/providers/boxyhq-saml" | ||
import Cognito from "next-auth/providers/cognito" | ||
import Credentials from "next-auth/providers/credentials" | ||
import Discord from "next-auth/providers/discord" | ||
import DuendeIDS6 from "next-auth/providers/duende-identity-server6" | ||
import Email from "next-auth/providers/email" | ||
import Facebook from "next-auth/providers/facebook" | ||
import Foursquare from "next-auth/providers/foursquare" | ||
import Freshbooks from "next-auth/providers/freshbooks" | ||
import GitHub from "next-auth/providers/github" | ||
import Gitlab from "next-auth/providers/gitlab" | ||
import Google from "next-auth/providers/google" | ||
import IDS4 from "next-auth/providers/identity-server4" | ||
import Instagram from "next-auth/providers/instagram" | ||
import Keycloak from "next-auth/providers/keycloak" | ||
import Line from "next-auth/providers/line" | ||
import LinkedIn from "next-auth/providers/linkedin" | ||
import Mailchimp from "next-auth/providers/mailchimp" | ||
import Okta from "next-auth/providers/okta" | ||
import Osu from "next-auth/providers/osu" | ||
import Patreon from "next-auth/providers/patreon" | ||
import Slack from "next-auth/providers/slack" | ||
import Spotify from "next-auth/providers/spotify" | ||
import Trakt from "next-auth/providers/trakt" | ||
import Twitch from "next-auth/providers/twitch" | ||
import Twitter, { TwitterLegacy } from "next-auth/providers/twitter" | ||
import Vk from "next-auth/providers/vk" | ||
import Wikimedia from "next-auth/providers/wikimedia" | ||
import WorkOS from "next-auth/providers/workos" | ||
|
||
// // Fauna | ||
// import { Client as FaunaClient } from "faunadb" | ||
// import { FaunaAdapter } from "@next-auth/fauna-adapter" | ||
// const client = new FaunaClient({ | ||
// secret: process.env.FAUNA_SECRET, | ||
// domain: process.env.FAUNA_DOMAIN, | ||
// }) | ||
// const adapter = FaunaAdapter(client) | ||
// Adapters | ||
import { PrismaClient } from "@prisma/client" | ||
import { PrismaAdapter } from "@next-auth/prisma-adapter" | ||
import { Client as FaunaClient } from "faunadb" | ||
import { FaunaAdapter } from "@next-auth/fauna-adapter" | ||
import { TypeORMLegacyAdapter } from "@next-auth/typeorm-legacy-adapter" | ||
|
||
// // Dummy | ||
// const adapter: any = { | ||
// getUserByEmail: (email) => ({ id: "1", email, emailVerified: null }), | ||
// createVerificationToken: (token) => token, | ||
// } | ||
// Add an adapter you want to test here. | ||
const adapters = { | ||
prisma() { | ||
const client = globalThis.prisma || new PrismaClient() | ||
if (process.env.NODE_ENV !== "production") global.prisma = client | ||
return PrismaAdapter(client) | ||
}, | ||
typeorm() { | ||
return TypeORMLegacyAdapter({ | ||
type: "sqlite", | ||
name: "next-auth-test-memory", | ||
database: "./typeorm/dev.db", | ||
synchronize: true, | ||
}) | ||
}, | ||
fauna() { | ||
const client = | ||
globalThis.fauna || | ||
new FaunaClient({ | ||
secret: process.env.FAUNA_SECRET, | ||
domain: process.env.FAUNA_DOMAIN, | ||
}) | ||
if (process.env.NODE_ENV !== "production") global.fauna = client | ||
return FaunaAdapter(client) | ||
}, | ||
noop() { | ||
return undefined | ||
}, | ||
} | ||
|
||
export const authOptions: NextAuthOptions = { | ||
// adapter, | ||
providers: [ | ||
// Start fake e-mail server with `npm run start:email` | ||
// EmailProvider({ | ||
// server: { | ||
// host: "127.0.0.1", | ||
// auth: null, | ||
// secure: false, | ||
// port: 1025, | ||
// tls: { rejectUnauthorized: false }, | ||
// }, | ||
// }), | ||
// Credentials | ||
CredentialsProvider({ | ||
name: "Credentials", | ||
credentials: { | ||
password: { label: "Password", type: "password" }, | ||
}, | ||
async authorize(credentials) { | ||
if (credentials.password === "pw") { | ||
return { | ||
name: "Fill Murray", | ||
email: "[email protected]", | ||
image: "https://www.fillmurray.com/64/64", | ||
} | ||
} | ||
return null | ||
}, | ||
}), | ||
// OAuth 1 | ||
// TwitterLegacyProvider({ | ||
// clientId: process.env.TWITTER_LEGACY_ID, | ||
// clientSecret: process.env.TWITTER_LEGACY_SECRET, | ||
// }), | ||
// OAuth 2 / OIDC | ||
TwitterProvider({ | ||
// Opt-in to the new Twitter API for now. Should be default in the future. | ||
version: "2.0", | ||
clientId: process.env.TWITTER_ID, | ||
clientSecret: process.env.TWITTER_SECRET, | ||
}), | ||
GitHubProvider({ | ||
clientId: process.env.GITHUB_ID, | ||
clientSecret: process.env.GITHUB_SECRET, | ||
}), | ||
Auth0Provider({ | ||
clientId: process.env.AUTH0_ID, | ||
clientSecret: process.env.AUTH0_SECRET, | ||
issuer: process.env.AUTH0_ISSUER, | ||
}), | ||
KeycloakProvider({ | ||
clientId: process.env.KEYCLOAK_ID, | ||
clientSecret: process.env.KEYCLOAK_SECRET, | ||
issuer: process.env.KEYCLOAK_ISSUER, | ||
}), | ||
Twitch({ | ||
clientId: process.env.TWITCH_ID, | ||
clientSecret: process.env.TWITCH_SECRET, | ||
}), | ||
GoogleProvider({ | ||
clientId: process.env.GOOGLE_ID, | ||
clientSecret: process.env.GOOGLE_SECRET, | ||
}), | ||
FacebookProvider({ | ||
clientId: process.env.FACEBOOK_ID, | ||
clientSecret: process.env.FACEBOOK_SECRET, | ||
}), | ||
FoursquareProvider({ | ||
clientId: process.env.FOURSQUARE_ID, | ||
clientSecret: process.env.FOURSQUARE_SECRET, | ||
}), | ||
// FreshbooksProvider({ | ||
// clientId: process.env.FRESHBOOKS_ID, | ||
// clientSecret: process.env.FRESHBOOKS_SECRET, | ||
// }), | ||
GitlabProvider({ | ||
clientId: process.env.GITLAB_ID, | ||
clientSecret: process.env.GITLAB_SECRET, | ||
}), | ||
InstagramProvider({ | ||
clientId: process.env.INSTAGRAM_ID, | ||
clientSecret: process.env.INSTAGRAM_SECRET, | ||
}), | ||
LineProvider({ | ||
clientId: process.env.LINE_ID, | ||
clientSecret: process.env.LINE_SECRET, | ||
}), | ||
LinkedInProvider({ | ||
clientId: process.env.LINKEDIN_ID, | ||
clientSecret: process.env.LINKEDIN_SECRET, | ||
}), | ||
MailchimpProvider({ | ||
clientId: process.env.MAILCHIMP_ID, | ||
clientSecret: process.env.MAILCHIMP_SECRET, | ||
}), | ||
IDS4Provider({ | ||
clientId: process.env.IDS4_ID, | ||
clientSecret: process.env.IDS4_SECRET, | ||
issuer: process.env.IDS4_ISSUER, | ||
}), | ||
DuendeIDS6Provider({ | ||
clientId: "interactive.confidential", | ||
clientSecret: "secret", | ||
issuer: "https://demo.duendesoftware.com", | ||
}), | ||
DiscordProvider({ | ||
clientId: process.env.DISCORD_ID, | ||
clientSecret: process.env.DISCORD_SECRET, | ||
}), | ||
AzureADProvider({ | ||
clientId: process.env.AZURE_AD_CLIENT_ID, | ||
clientSecret: process.env.AZURE_AD_CLIENT_SECRET, | ||
tenantId: process.env.AZURE_AD_TENANT_ID, | ||
profilePhotoSize: 48, | ||
}), | ||
SpotifyProvider({ | ||
clientId: process.env.SPOTIFY_ID, | ||
clientSecret: process.env.SPOTIFY_SECRET, | ||
}), | ||
CognitoProvider({ | ||
clientId: process.env.COGNITO_ID, | ||
clientSecret: process.env.COGNITO_SECRET, | ||
issuer: process.env.COGNITO_ISSUER, | ||
}), | ||
Okta({ | ||
clientId: process.env.OKTA_ID, | ||
clientSecret: process.env.OKTA_SECRET, | ||
issuer: process.env.OKTA_ISSUER, | ||
}), | ||
SlackProvider({ | ||
clientId: process.env.SLACK_ID, | ||
clientSecret: process.env.SLACK_SECRET, | ||
}), | ||
AzureB2C({ | ||
clientId: process.env.AZURE_B2C_ID, | ||
clientSecret: process.env.AZURE_B2C_SECRET, | ||
tenantId: process.env.AZURE_B2C_TENANT_ID, | ||
primaryUserFlow: process.env.AZURE_B2C_PRIMARY_USER_FLOW, | ||
}), | ||
OsuProvider({ | ||
clientId: process.env.OSU_CLIENT_ID, | ||
clientSecret: process.env.OSU_CLIENT_SECRET, | ||
}), | ||
AppleProvider({ | ||
clientId: process.env.APPLE_ID, | ||
clientSecret: process.env.APPLE_SECRET, | ||
}), | ||
PatreonProvider({ | ||
clientId: process.env.PATREON_ID, | ||
clientSecret: process.env.PATREON_SECRET, | ||
}), | ||
TraktProvider({ | ||
clientId: process.env.TRAKT_ID, | ||
clientSecret: process.env.TRAKT_SECRET, | ||
}), | ||
WorkOSProvider({ | ||
clientId: process.env.WORKOS_ID, | ||
clientSecret: process.env.WORKOS_SECRET, | ||
}), | ||
BoxyHQSAMLProvider({ | ||
issuer: process.env.BOXYHQSAML_ISSUER ?? "https://example.com", | ||
clientId: process.env.BOXYHQSAML_ID, | ||
clientSecret: process.env.BOXYHQSAML_SECRET, | ||
}), | ||
WikimediaProvider({ | ||
clientId: process.env.WIKIMEDIA_ID, | ||
clientSecret: process.env.WIKIMEDIA_SECRET, | ||
}), | ||
VkProvider({ | ||
clientId: process.env.VK_ID, | ||
clientSecret: process.env.VK_SECRET | ||
}), | ||
], | ||
adapter: adapters.noop(), | ||
debug: true, | ||
theme: { | ||
colorScheme: "auto", | ||
logo: "https://next-auth.js.org/img/logo/logo-sm.png", | ||
brandColor: "#1786fb", | ||
}, | ||
providers: [ | ||
Credentials({ | ||
credentials: { password: { label: "Password", type: "password" } }, | ||
async authorize(credentials) { | ||
if (credentials.password !== "pw") return null | ||
return { name: "Fill Murray", email: "[email protected]", image: "https://www.fillmurray.com/64/64" } | ||
}, | ||
}), | ||
Apple({ clientId: process.env.APPLE_ID, clientSecret: process.env.APPLE_SECRET }), | ||
Auth0({ clientId: process.env.AUTH0_ID, clientSecret: process.env.AUTH0_SECRET, issuer: process.env.AUTH0_ISSUER }), | ||
AzureAD({ clientId: process.env.AZURE_AD_CLIENT_ID, clientSecret: process.env.AZURE_AD_CLIENT_SECRET, tenantId: process.env.AZURE_AD_TENANT_ID }), | ||
AzureB2C({ clientId: process.env.AZURE_B2C_ID, clientSecret: process.env.AZURE_B2C_SECRET, issuer: process.env.AZURE_B2C_ISSUER }), | ||
BoxyHQSAML({ issuer: "https://jackson-demo.boxyhq.com", clientId: "tenant=boxyhq.com&product=saml-demo.boxyhq.com", clientSecret: "dummy" }), | ||
Cognito({ clientId: process.env.COGNITO_ID, clientSecret: process.env.COGNITO_SECRET, issuer: process.env.COGNITO_ISSUER }), | ||
Discord({ clientId: process.env.DISCORD_ID, clientSecret: process.env.DISCORD_SECRET }), | ||
DuendeIDS6({ clientId: "interactive.confidential", clientSecret: "secret", issuer: "https://demo.duendesoftware.com" }), | ||
Facebook({ clientId: process.env.FACEBOOK_ID, clientSecret: process.env.FACEBOOK_SECRET }), | ||
Foursquare({ clientId: process.env.FOURSQUARE_ID, clientSecret: process.env.FOURSQUARE_SECRET }), | ||
Freshbooks({ clientId: process.env.FRESHBOOKS_ID, clientSecret: process.env.FRESHBOOKS_SECRET }), | ||
GitHub({ clientId: process.env.GITHUB_ID, clientSecret: process.env.GITHUB_SECRET }), | ||
Gitlab({ clientId: process.env.GITLAB_ID, clientSecret: process.env.GITLAB_SECRET }), | ||
Google({ clientId: process.env.GOOGLE_ID, clientSecret: process.env.GOOGLE_SECRET }), | ||
IDS4({ clientId: process.env.IDS4_ID, clientSecret: process.env.IDS4_SECRET, issuer: process.env.IDS4_ISSUER }), | ||
Instagram({ clientId: process.env.INSTAGRAM_ID, clientSecret: process.env.INSTAGRAM_SECRET }), | ||
Keycloak({ clientId: process.env.KEYCLOAK_ID, clientSecret: process.env.KEYCLOAK_SECRET, issuer: process.env.KEYCLOAK_ISSUER }), | ||
Line({ clientId: process.env.LINE_ID, clientSecret: process.env.LINE_SECRET }), | ||
LinkedIn({ clientId: process.env.LINKEDIN_ID, clientSecret: process.env.LINKEDIN_SECRET }), | ||
Mailchimp({ clientId: process.env.MAILCHIMP_ID, clientSecret: process.env.MAILCHIMP_SECRET }), | ||
Okta({ clientId: process.env.OKTA_ID, clientSecret: process.env.OKTA_SECRET, issuer: process.env.OKTA_ISSUER }), | ||
Osu({ clientId: process.env.OSU_CLIENT_ID, clientSecret: process.env.OSU_CLIENT_SECRET }), | ||
Patreon({ clientId: process.env.PATREON_ID, clientSecret: process.env.PATREON_SECRET }), | ||
Slack({ clientId: process.env.SLACK_ID, clientSecret: process.env.SLACK_SECRET }), | ||
Spotify({ clientId: process.env.SPOTIFY_ID, clientSecret: process.env.SPOTIFY_SECRET }), | ||
Trakt({ clientId: process.env.TRAKT_ID, clientSecret: process.env.TRAKT_SECRET }), | ||
Twitch({ clientId: process.env.TWITCH_ID, clientSecret: process.env.TWITCH_SECRET }), | ||
Twitter({ version: "2.0", clientId: process.env.TWITTER_ID, clientSecret: process.env.TWITTER_SECRET }), | ||
TwitterLegacy({ clientId: process.env.TWITTER_LEGACY_ID, clientSecret: process.env.TWITTER_LEGACY_SECRET }), | ||
Vk({ clientId: process.env.VK_ID, clientSecret: process.env.VK_SECRET }), | ||
Wikimedia({ clientId: process.env.WIKIMEDIA_ID, clientSecret: process.env.WIKIMEDIA_SECRET }), | ||
WorkOS({ clientId: process.env.WORKOS_ID, clientSecret: process.env.WORKOS_SECRET }), | ||
], | ||
} | ||
|
||
if (authOptions.adapter) { | ||
authOptions.providers.unshift( | ||
// NOTE: You can start a fake e-mail server with `pnpm email` | ||
// and then go to `http://localhost:1080` in the browser | ||
Email({ | ||
server: { | ||
host: "127.0.0.1", | ||
auth: null, | ||
secure: false, | ||
port: 1025, | ||
tls: { rejectUnauthorized: false }, | ||
}, | ||
}) | ||
) | ||
} | ||
|
||
export default NextAuth(authOptions) |
Oops, something went wrong.