Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Descope Example #101

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .env.local.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ AUTH_AUTH0_ID=
AUTH_AUTH0_SECRET=
AUTH_AUTH0_ISSUER=

AUTH_DESCOPE_ID=
AUTH_DESCOPE_SECRET=

AUTH_FACEBOOK_ID=
AUTH_FACEBOOK_SECRET=

Expand Down
102 changes: 54 additions & 48 deletions auth.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,40 @@
import NextAuth from "next-auth"
import "next-auth/jwt"
import NextAuth from "next-auth";
import "next-auth/jwt";

import Apple from "next-auth/providers/apple"
import Auth0 from "next-auth/providers/auth0"
import AzureB2C from "next-auth/providers/azure-ad-b2c"
import BankIDNorway from "next-auth/providers/bankid-no"
import BoxyHQSAML from "next-auth/providers/boxyhq-saml"
import Cognito from "next-auth/providers/cognito"
import Coinbase from "next-auth/providers/coinbase"
import Discord from "next-auth/providers/discord"
import Dropbox from "next-auth/providers/dropbox"
import Facebook from "next-auth/providers/facebook"
import GitHub from "next-auth/providers/github"
import GitLab from "next-auth/providers/gitlab"
import Google from "next-auth/providers/google"
import Hubspot from "next-auth/providers/hubspot"
import Keycloak from "next-auth/providers/keycloak"
import LinkedIn from "next-auth/providers/linkedin"
import Netlify from "next-auth/providers/netlify"
import Okta from "next-auth/providers/okta"
import Passage from "next-auth/providers/passage"
import Passkey from "next-auth/providers/passkey"
import Pinterest from "next-auth/providers/pinterest"
import Reddit from "next-auth/providers/reddit"
import Slack from "next-auth/providers/slack"
import Spotify from "next-auth/providers/spotify"
import Twitch from "next-auth/providers/twitch"
import Twitter from "next-auth/providers/twitter"
import WorkOS from "next-auth/providers/workos"
import Zoom from "next-auth/providers/zoom"
import { createStorage } from "unstorage"
import memoryDriver from "unstorage/drivers/memory"
import vercelKVDriver from "unstorage/drivers/vercel-kv"
import { UnstorageAdapter } from "@auth/unstorage-adapter"
import type { NextAuthConfig } from "next-auth"
import Apple from "next-auth/providers/apple";
import Auth0 from "next-auth/providers/auth0";
import AzureB2C from "next-auth/providers/azure-ad-b2c";
import BankIDNorway from "next-auth/providers/bankid-no";
import BoxyHQSAML from "next-auth/providers/boxyhq-saml";
import Cognito from "next-auth/providers/cognito";
import Coinbase from "next-auth/providers/coinbase";
import Descope from "next-auth/providers/descope";
import Discord from "next-auth/providers/discord";
import Dropbox from "next-auth/providers/dropbox";
import Facebook from "next-auth/providers/facebook";
import GitHub from "next-auth/providers/github";
import GitLab from "next-auth/providers/gitlab";
import Google from "next-auth/providers/google";
import Hubspot from "next-auth/providers/hubspot";
import Keycloak from "next-auth/providers/keycloak";
import LinkedIn from "next-auth/providers/linkedin";
import Netlify from "next-auth/providers/netlify";
import Okta from "next-auth/providers/okta";
import Passage from "next-auth/providers/passage";
import Passkey from "next-auth/providers/passkey";
import Pinterest from "next-auth/providers/pinterest";
import Reddit from "next-auth/providers/reddit";
import Slack from "next-auth/providers/slack";
import Spotify from "next-auth/providers/spotify";
import Twitch from "next-auth/providers/twitch";
import Twitter from "next-auth/providers/twitter";
import WorkOS from "next-auth/providers/workos";
import Zoom from "next-auth/providers/zoom";
import { createStorage } from "unstorage";
import memoryDriver from "unstorage/drivers/memory";
import vercelKVDriver from "unstorage/drivers/vercel-kv";
import { UnstorageAdapter } from "@auth/unstorage-adapter";
import type { NextAuthConfig } from "next-auth";

const storage = createStorage({
driver: process.env.VERCEL
Expand All @@ -43,7 +44,7 @@ const storage = createStorage({
env: false,
})
: memoryDriver(),
})
});

const config = {
theme: { logo: "https://authjs.dev/img/logo-sm.png" },
Expand All @@ -64,6 +65,11 @@ const config = {
}),
Cognito,
Coinbase,
Descope({
clientId: process.env.AUTH_DESCOPE_ID,
clientSecret: process.env.AUTH_DESCOPE_SECRET,
checks: ["pkce", "state"],
}),
Discord,
Dropbox,
Facebook,
Expand Down Expand Up @@ -99,40 +105,40 @@ const config = {
basePath: "/auth",
callbacks: {
authorized({ request, auth }) {
const { pathname } = request.nextUrl
if (pathname === "/middleware-example") return !!auth
return true
const { pathname } = request.nextUrl;
if (pathname === "/middleware-example") return !!auth;
return true;
},
jwt({ token, trigger, session, account }) {
if (trigger === "update") token.name = session.user.name
if (trigger === "update") token.name = session.user.name;
if (account?.provider === "keycloak") {
return { ...token, accessToken: account.access_token }
return { ...token, accessToken: account.access_token };
}
return token
return token;
},
async session({ session, token }) {
if (token?.accessToken) {
session.accessToken = token.accessToken
session.accessToken = token.accessToken;
}
return session
return session;
},
},
experimental: {
enableWebAuthn: true,
},
debug: process.env.NODE_ENV !== "production" ? true : false,
} satisfies NextAuthConfig
} satisfies NextAuthConfig;

export const { handlers, auth, signIn, signOut } = NextAuth(config)
export const { handlers, auth, signIn, signOut } = NextAuth(config);

declare module "next-auth" {
interface Session {
accessToken?: string
accessToken?: string;
}
}

declare module "next-auth/jwt" {
interface JWT {
accessToken?: string
accessToken?: string;
}
}