Next.js with OpenID Connect

R
Renaudil y a 2 jours
0

Description

Authenticate using OpenID Connect Protocol via Auth.js

npx boilerapp openid-connect

文档

Next.js App using Authorization Code Flow with PKCE

This project demonstrates how to implement the Authorization Code Flow with PKCE for a Next.js App.

Disclaimer: This project is for educational purposes only and should not be used in production without proper security review and testing.

Demo

This project is deployed on Cloudflare Pages and on Vercel.

Deploy your own

Deploy the project using Vercel:

Deploy with Vercel

Deploy the project using Cloudflare:

Deploy to Cloudflare Pages

Prerequisites

Before getting started, make sure you have the following:

  • Node.js installed on your machine
  • An OpenID Connect provider that supports the Authorization Code Flow with PKCE

Getting Started

  1. Clone the repository:
git clone https://github.com/cerberauth/openid-connect-examples.git
  1. Install the dependencies:
cd openid-connect-examples/nextjs-app
npm ci
  1. Configure the OpenID Connect provider (see the Configuration section below).

  2. Start the development server:

npm run dev
  1. Open your browser and navigate to http://localhost:5173/.

  2. Click on the "Login" button to initiate the authorization code flow.

  3. After successful authentication, you will be redirected back to the application and the user information will be displayed.

Configuration

Configure the OpenID Connect provider:

If you don't have an OpenID Connect provider, you can create a Test Client on the TestID OpenID Connect Provider.

  • Obtain the client ID and client secret from your OpenID Connect provider.
  • Register the redirect URI for your Next.js App in the provider's developer console.

Update the configuration:

  • Create a .env.local file in the root directory of your project or copy .env.example file.
  • Add the necessary environment variables to the .env.local file. For example:
AUTH_SECRET=secret
AUTH_CLIENT_ID=your-client-id
AUTH_CLIENT_SECRET=your-client-secret

Generate a random secret using the following command:

openssl rand -base64 33

Replace secret with the generated secret.

Replace your-client-id and your-client-secret with the actual values provided by your OpenID Connect provider.

Save the .env.local file.

Additional Resources

Prix

Gratuit

FREE

评论 (0)

常见问题

常见问题解答 (FAQ)

有问题?我们有答案。如果您找不到想要的答案,请随时联络我们。

Boilerapp 是一个专门用于分享 Boilerplates、入门套件(Starter Kits)和项目模版的开发者社区平台。我们的目标很简单:为您节省初始配置(Setup)的时间,让您可以专注于真正重要的代码。无论您是在寻找简单的代码库还是完整的 SaaS 项目,都能在这里找到。

还有其他问题?

我们的团队随时为您提供帮助。联络我们,我们将尽快回复。

Next.js with OpenID Connect | BoilerApp