Accessing Gatsby endpoints via api-key auth returns 403 error

Created on 3 September 2024, 4 months ago

Problem/Motivation

Accessing a Gatsby endpoint via an api token returns a 403 error, as authenticated access is only permitted via basic_auth or cookies:

gatsby_endpoints.gatsby_endpoints_controller_sync:
  path: '/gatsby/{endpoint_id}'
  defaults:
    _controller: '\Drupal\gatsby_endpoints\Controller\GatsbyEndpointController::sync'
    _title: 'Gatsby Endpoint'
  options:
    _auth: ['basic_auth', 'cookie']

Steps to reproduce

1. Install the gatsby_endpoints module and configure permissions on a fresh Drupal website
2. Install the key_auth module
3. In your Gatsby project, install the gatsby-source-drupal plugin
4. In gatsby-config.js file, add the options.params.api-key value of your Drupal user's API key
5. Create a Gatsby endpoint
6. Attempt to access it using your API token e.g. mysite.com/gatsby/my-endpoint?api-key=123

Proposed resolution

Add support for key_auth in gatsby_endpoints.routing.yml:

_auth: ['basic_auth', 'cookie', 'key_auth']

🐛 Bug report
Status

Active

Component

Code

Created by

🇦🇺Australia timfletcher

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024