diff --git a/.github/ISSUE_TEMPLATE/2_bug_provider.yml b/.github/ISSUE_TEMPLATE/2_bug_provider.yml index fa87b24a59..406084ea8d 100644 --- a/.github/ISSUE_TEMPLATE/2_bug_provider.yml +++ b/.github/ISSUE_TEMPLATE/2_bug_provider.yml @@ -57,6 +57,7 @@ body: - "Identity Server 4" - "Instagram" - "Kakao" + - "Frontegg" - "Keycloak" - "Kinde" - "Line" diff --git a/apps/dev/nextjs/.env.local.example b/apps/dev/nextjs/.env.local.example index cb34099406..18f1f2945f 100644 --- a/apps/dev/nextjs/.env.local.example +++ b/apps/dev/nextjs/.env.local.example @@ -58,6 +58,10 @@ AUTH_TWITTER_SECRET= AUTH_WIKIMEDIA_ID= AUTH_WIKIMEDIA_SECRET= +AUTH_FRONTEGG_ID= +AUTH_FRONTEGG_SECRET= +AUTH_FRONTEGG_ISSUER= + # Yandex OAuth. new app -> https://oauth.yandex.com/client/new/id AUTH_YANDEX_ID= AUTH_YANDEX_SECRET= diff --git a/docs/pages/getting-started/providers/frontegg.mdx b/docs/pages/getting-started/providers/frontegg.mdx new file mode 100644 index 0000000000..d731d7124b --- /dev/null +++ b/docs/pages/getting-started/providers/frontegg.mdx @@ -0,0 +1,90 @@ +import { Callout } from "nextra/components" +import { Code } from "@/components/Code" + + + +# Frontegg Provider + +## Resources + +- [Frontegg documentation](https://docs.frontegg.com/docs/how-to-use-our-docs) + +## Setup + +### Callback URL + + + + + ```bash + https://example.com/api/auth/callback/frontegg + ``` + + + + + ```bash + https://example.com/auth/callback/frontegg + ``` + + + + +### Environment Variables + +``` +AUTH_FRONTEGG_ID +AUTH_FRONTEGG_SECRET +AUTH_FRONTEGG_ISSUER +``` + +### Configuration + +Follow these steps: + +Log into the [Frontegg portal](https://portal.frontegg.com) + +Get the following from the Frontegg's portal: + +AUTH_FRONTEGG_ID="" # Environments > Your environment > Env settings +AUTH_FRONTEGG_SECRET="" # Environments > Your environment > Env settings +AUTH_FRONTEGG_ISSUER="" # Environments > Your environment > Env settings > Domains > Domain name + +Add the required environment variables from above to your `.env.local` file. + + + + + ```ts filename="/auth.ts" + import NextAuth from "next-auth" + import Frontegg from "next-auth/providers/frontegg" + + export const { handlers, auth, signIn, signOut } = NextAuth({ + providers: [Frontegg], + }) + ``` + + + + + ```ts filename="/src/auth.ts" + import { SvelteKitAuth } from "@auth/sveltekit" + import Frontegg from "@auth/sveltekit/providers/frontegg" + + export const { handle, signIn, signOut } = SvelteKitAuth({ + providers: [Frontegg], + }) + ``` + + + + + ```ts filename="/src/app.ts" + import { ExpressAuth } from "@auth/express" + import Frontegg from "@auth/express/providers/frontegg" + + app.use("/auth/*", ExpressAuth({ providers: [Frontegg] })) + ``` + + + diff --git a/docs/public/img/providers/frontegg.svg b/docs/public/img/providers/frontegg.svg new file mode 100644 index 0000000000..bbe054debb --- /dev/null +++ b/docs/public/img/providers/frontegg.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/packages/core/src/providers/frontegg.ts b/packages/core/src/providers/frontegg.ts new file mode 100644 index 0000000000..15890c5c8d --- /dev/null +++ b/packages/core/src/providers/frontegg.ts @@ -0,0 +1,111 @@ +/** + *
+ * + * Built-in sign in with Frontegg integration. + * + * + * + * + *
+ * + * @module providers/frontegg + */ + +import type { OIDCConfig, OIDCUserConfig } from "./index.js" + +/** The returned user profile from Frontegg when using the profile callback. [Reference](https://docs.frontegg.com/docs/admin-portal-profile). */ +export interface FronteggProfile { + /** The user's unique Frontegg ID */ + sub: string + /** The user's name */ + name: string + /** The user's email */ + email: string + /** A boolean indicating if the user's email is verified */ + email_verified: boolean + /** The user's picture */ + profilePictureUrl: string + /** The user's roles */ + roles: string[] + /** The user's custom attributes */ + [claim: string]: unknown +} + +/** + * + * ### Setup + * + * #### Callback URL + * ``` + * https://example.com/api/auth/callback/frontegg + * ``` + * + * #### Configuration + * ```ts + * import { Auth } from "@auth/core" + * import Frontegg from "@auth/core/providers/frontegg" + * + * const request = new Request(origin) + * const response = await Auth(request, { + * providers: [ + * Frontegg({ + * clientId: AUTH_FRONTEGG_ID, + * clientSecret: AUTH_FRONTEGG_SECRET, + * issuer: AUTH_FRONTEGG_ISSUER + * }), + * ], + * }) + * ``` + * + * ### Configuring Frontegg + * + * Follow these steps: + * + * Log into the [Frontegg portal](https://portal.frontegg.com) + * + * Authentication > Login method > Hosted login > Add your callback url here <{{APP_URL}}/api/auth/callback/frontegg> + * + * Then, create a `.env.local` file in the project root add the following entries: + * + * Get the following from the Frontegg's portal: + * ``` + * AUTH_FRONTEGG_ID="" # Environments > Your environment > Env settings + * AUTH_FRONTEGG_SECRET="" # Environments > Your environment > Env settings + * AUTH_FRONTEGG_ISSUER="" # Environments > Your environment > Env settings > Domains > Domain name + * ``` + * + * ### Resources + * + * - [Frontegg Docs](https://docs.frontegg.com/docs/how-to-use-our-docs) + * + * ### Notes + * + * The Frontegg provider comes with a [default configuration](https://github.com/nextauthjs/next-auth/blob/main/packages/core/src/providers/frontegg.ts). To override the defaults for your use case, check out [customizing a built-in OAuth provider](https://authjs.dev/guides/configuring-oauth-providers). + * + * :::info + * By default, Auth.js assumes that the Frontegg provider is based on the [OIDC](https://openid.net/specs/openid-connect-core-1_0.html) spec + * ::: + * + * ## Help + * + * If you think you found a bug in the default configuration, you can [open an issue](https://authjs.dev/new/provider-issue). + * + * Auth.js strictly adheres to the specification and it cannot take responsibility for any deviation from + * the spec by the provider. You can open an issue, but if the problem is non-compliance with the spec, + * we might not pursue a resolution. You can ask for more help in [Discussions](https://authjs.dev/new/github-discussions). + */ +export default function Frontegg( + options: OIDCUserConfig +): OIDCConfig { + return { + id: "frontegg", + name: "Frontegg", + type: "oidc", + authorization: `${options.issuer}/oauth/authorize`, + token: `${options.issuer}/oauth/token`, + userinfo: `${options.issuer}/identity/resources/users/v2/me`, + wellKnown: `${options.issuer}/oauth/.well-known/openid-configuration`, + issuer: options.issuer, + options, + } +}