Skip to main content
drupalreleases

Use direct release data with your AI assistant.

Learn more

Simple OAuth: Fallback Header

Security covered Maintenance fixes only 55 sites

This module allows you to use a custom HTTP header for sending OAuth Bearer access tokens, which can help avoid conflicts with other authentication methods. It also provides an option to accept access tokens via a GET query parameter. The module works automatically upon installation, but its behavior can be configured in settings.php.

This module allows the use of X-OAuth-Authorization HTTP header for sending Bearer access tokens to get authenticated via OAuth. The alternative header name may help using the basic HTTP authorization in combination with OAuth (to eliminate headers conflict).

Usage

The module has zero configuration and works as plug & play, so you have to simply install it.

Configuration

If by some reasons you don't like X-OAuth-Authorization HTTP header then use settings.php to rename it:

$settings['simple_oauth_fallback_header'] = 'X-My-Api-Auth';

Tune settings a little more if you want to allow sending an access token within the access_token GET query:

/**
 * Allow access token to be sent in a GET query "/api?access_token=XXX".
 * 
 * @link https://tools.ietf.org/html/rfc6750#section-2.3
 */
$settings['simple_oauth_allow_get_query'] = TRUE;

Server-side HTTP authorization

A service provider needs to be implemented in order to work seamlessly with server-side basic/digest HTTP authorization.

namespace Drupal\my_module;

use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\DependencyInjection\ServiceModifierInterface;

/**
 * Module's service provider.
 */
class MyModuleServiceProvider implements ServiceModifierInterface {

  /**
   * {@inheritdoc}
   */
  public function alter(ContainerBuilder $container) {
    // Remove "basic_auth_swap" HTTP middleware provided by the "simple_oauth".
    // It needed because a site may have server-based HTTP authentication
    // but that middleware converts "PHP_AUTH_USER" and "PHP_AUTH_PW" to
    // the request's "client_id" and "client_secret" and this breaks the
    // OAuth2 token creation.
    $container->removeDefinition('simple_oauth.http_middleware.basic_auth_swap');
  }

}

After that we're safe to use our custom header for OAuth authorization in combination with Authorization header for basic/digest HTTP authorization.

Under the hood

The description of a logic the module provides might be relevant for someone, especially because of a request object mutation. Let's have a look.

Prioritization

- The X-OAuth-Authorization header has a higher priority than Authorization header and GET query.
- The access_token GET query (if enabled) has a higher priority over standard Authorization header.

Request mutation

This module checks whether the X-OAuth-Authorization header or access_token GET query meets in a request and places the value from one of them (based on prioritization) to the Authorization header. This means that previously stored value in the Authorization header will be lost.

Drupal 9–11

Ask your assistant about Simple OAuth: Fallback Header

Check compatibility with your Drupal and PHP version, maintenance and security coverage, from current release data. How it works

Depends on

Dependencies of the latest stable release

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
2
Tracked since
May 2024
Latest release
1 year ago
Releases (12 mo)
0 ▼ from 1
Maintenance
Dormant

Releases

Version Type Core PHP Release date
8.x-1.4 Stable 9–11 Nov 13, 2024
8.x-1.3 Stable 8–10 May 30, 2024