Skip to content

Add filter for alternative authorization header#76

Open
abhishek-kaushik wants to merge 3 commits into
WP-API:mainfrom
abhishek-kaushik:custom-auth-heaer
Open

Add filter for alternative authorization header#76
abhishek-kaushik wants to merge 3 commits into
WP-API:mainfrom
abhishek-kaushik:custom-auth-heaer

Conversation

@abhishek-kaushik
Copy link
Copy Markdown
Collaborator

@abhishek-kaushik abhishek-kaushik commented May 12, 2026

Summary

Replaces the hardcoded `Authorization` header lookup with a filterable header name, allowing projects to redirect token extraction to a different header when the standard one is consumed by a proxy or server layer (e.g. Imperva HTTP Basic Auth).

A `get_header( $name )` helper is extracted so the same `$_SERVER` + `getallheaders()` fallback logic applies regardless of which header name is used.

Usage

```php
add_filter( 'oauth2.authentication.authorization_header', function() {
return 'x-authorization';
} );
```

Why

Hardcoding `X-Authorization` as a fallback in the plugin is too opinionated — the header name is environment-specific and belongs at the project level, not the library level.

@abhishek-kaushik abhishek-kaushik changed the title Custom auth heaer Add filter for alternative authorization header May 12, 2026
@abhishek-kaushik abhishek-kaushik marked this pull request as ready for review May 12, 2026 09:43
* @return string|null Authorization header if set, null otherwise
*/
function get_authorization_header() {
if ( ! empty( $_SERVER['HTTP_AUTHORIZATION'] ) ) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be better to just pass the header name through a filter at this point? $header = apply_filters( 'oauth2.authentication.authorization_header', 'authorization' ) for example

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