Drupal is a registered trademark of Dries Buytaert
Release: Drupal 10.3.6 Update released for Drupal core (10.3.6)! Release: Drupal 11.0.5 Update released for Drupal core (11.0.5)! Release: Drupal 10.2.9 Update released for Drupal core (10.2.9)! Release: Drupal 10.2.10 Update released for Drupal core (10.2.10)! Release: Drupal 10.3.7 Update released for Drupal core (10.3.7)! Release: Drupal 11.0.6 Update released for Drupal core (11.0.6)! Release: Drupal 10.3.8 Update released for Drupal core (10.3.8)! Release: Drupal 11.0.7 Update released for Drupal core (11.0.7)! Module Revived: Translation Management Tool 8.x-1.19 Module tmgmt updated after 7 months of inactivity (8.x-1.19). Usage Milestone: Account field split Module account_field_split crossed 10,000 active installs.

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.

Depends on

Dependencies of the latest stable release

No dependencies recorded for this project.

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

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

Releases

Version Type Core Release date
8.x-1.4 Stable Nov 13, 2024