Configure Authentication
Setup an OAuth client for GraphQL requests.
To make GraphQL requests to your Drupal site, we need to configure authentication.
We will use an OAuth Client for authenticating GraphQL requests.
Before we can create an OAuth consumer, we need to create a new role and a user for OAuth scopes.
1. Create Role
- Visit
/admin/people/roles
. - Click on + Add role.
- Fill in the Role name. Example: Next.js Site.
2. Assign Permissions
Next, assign the following permissions to the newly created role.
- GraphQL Compose - Server: Execute arbitrary requests
3. Create User
Add a new user at /admin/people/create
and assign them the role we created above.
4. Generate keys
Generate a pair of keys to encrypt the access tokens. Store them outside of your document root (web
directory) for security.
- Visit
/admin/config/people/simple_oauth
- Click Generate keys to generate encryption keys for tokens
- Fill in Directory for the keys. For example a relative path like
../
- Click Generate
- Click Save configuration
You can also use openssl
to generate keys in the directory you used above:
openssl genrsa -out private.key 2048
openssl rsa -in private.key -pubout > public.key
5. Create Consumer
- Visit /admin/config/services/consumer/add
- Fill in the following values:
- Label:
Next.js site
- User:
Select the user we created
- Secret:
Your secret
- Scopes:
Select the role we created
- Click Save
Important: note the client id (uuid) and the secret. These are going to be used as environment variables for the Next.js site.