Authentication

How to authenticate users in Next.js for Drupal.


To authenticate Drupal users in our Next.js type we can implement one of two grants.

A grant is a method of acquiring an access token.

The two grants we can use are:

  1. Password Grant
  2. Authorization Code Grant

Which Grant?

Deciding which grants to implement depends on the type of client the end user will be using, and the experience you want for your users.

The Password Credentials Grant allows users to authenticate with a username and password while the Authorization Code Grant takes the user off-site to the authorization server (the Drupal site) for authentication.

Use the Password Grant for first party clients only i.e. you own the Next.js sites.

Dependencies

To implement authentication we are going to use NextAuth.js on the Next.js side and Simple OAuth module on the Drupal side.

Demo

See https://example-auth.next-drupal.org/.

Example

See https://github.com/chapter-three/next-drupal/tree/main/examples/example-auth