Skip to content

Added API key authentication alternative.#12

Open
gassan wants to merge 1 commit intoPeterBooker:mainfrom
TeDo-Verlag:api-key-auth
Open

Added API key authentication alternative.#12
gassan wants to merge 1 commit intoPeterBooker:mainfrom
TeDo-Verlag:api-key-auth

Conversation

@gassan
Copy link
Copy Markdown
Contributor

@gassan gassan commented Nov 7, 2025

For those who have wpackagist-plugin/jwt-authentication-for-wp-rest-api installed, Bearer token authentication is problematic, because the plugin intercepts the token and tries to authenticate the user automatically.

To make it work, you need to:

  1. Create an unprivileged user.
  2. add_filter to increase the token TTL.
  3. Login them.
  4. Store a long-lived token for this user.

Authentication via a specific header simplifies things a lot.

In this same commit, I pass the settings into a <script> before the settings page <div>. This saves a request. If, for some reason, the data is missing, an AJAX request will be sent (old method).

Added a dynamic Prometheus job-config example to the bottom of the settings page.

@gassan
Copy link
Copy Markdown
Contributor Author

gassan commented Nov 7, 2025

Added "Copy config" ClipbardButton.

@gassan gassan force-pushed the api-key-auth branch 2 times, most recently from d11e7b4 to 8623949 Compare November 7, 2025 11:11
@gassan
Copy link
Copy Markdown
Contributor Author

gassan commented Nov 7, 2025

Added 'permission_callback's to avoid 'doing_wrong' notice:
The REST API route definition for %1$s is missing the required %2$s argument. For REST API routes that are intended to be public, use %3$s as the permission callback.

@PeterBooker
Copy link
Copy Markdown
Owner

There is a lot of good work here @gassan, thank you.

Ideally I would like to keep the auth simple, so I think perhaps I would like to make a breaking change to the plugin which changes the authentication to avoid standard auth methods (like bearer tokens) and uses a fixed header like X-PromPress, however I need some time to think about this as it might be safer to stick with standard WordPress REST API authentication.

I need a little time to consider this change and work out the best route.

@gassan
Copy link
Copy Markdown
Contributor Author

gassan commented Nov 25, 2025

Just to be clear, this method is not a replacement for the old one with the bearer token — it’s an addition. Everything old will continue to work as before.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants