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 adds token based authentication for core API modules such as JSON:API or RESTful Web Services module and the services contrib module. Access tokens expire after a given period of time and are invalidated automatically if a user changes her username or the password or if she gets blocked by an administrator. This mechanism is extendable and therefore allows for site specific policies. E.g., in some cases it is desirable to invalidate an access token whenever some permissions change.

A services action provided by this module allows clients to (re-)generate access tokens. Hence, client applications may renew their access tokens automatically.

The flexible invalidation scheme and automatic expiry makes this module an ideal candidate for distributing subscription based paid content.

Authentication protocol

In order to simplify integration with HTTP clients but also with intermediate proxies, the Authorization header is used to transmit the authentication token, i.e. the token can be used as the basic auth username and the password is left blank. This method is preferable to query parameter since proxies will automatically exclude requests if that header is present. Also query parameters are more likely to end up in server logs and the browser history, increasing the likelihood of leaking the token to third parties. Note that neither of those methods can be used safely over insecure connections, HTTPS is mandatory for both.

The token-generate action can be configured to accept username and password in addition to an existing valid token. As a result, a client application which is started for the first time may authenticate with user credentials in order to retrieve the authentication token, which is then stored client side and used for any subsequent requests.

Client examples

Generate a token

curl -XPOST http://my_username:[email protected]/api/services_token/generate
{"expires":"2015-12-07T20:39:47+0100","token":"1.5665e083.RJG0CdymRKqFQJKeIV8nflwIhrr8KVrmAy6kpWft5nU"}

Use the token to retrieve data

curl -XGET http://1.5665e083.RJG0CdymRKqFQJKeIV8nflwIhrr8KVrmAy6kpWft5nU:@example.com/api/user/1
{"uid":"1","name":"my_username",...}

Regenerate a token

curl -XPOST http://1.5665e083.RJG0CdymRKqFQJKeIV8nflwIhrr8KVrmAy6kpWft5nU:@example.com/api/services_token/generate
{"expires":"2015-12-07T20:47:05+0100","token":"1.5665e239._UgtElc0RKDfj0EemIUjnM-Q90QK65MVAPhEP3m8Lq8"}

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
4
Tracked since
Nov 2024
Latest release
1 year ago
Releases (12 mo)
0 ▼ from 4
Maintenance
Dormant

Release Timeline

Releases

Version Type Core Release date
2.1.2 Stable Dec 22, 2024
2.1.1 Stable Nov 30, 2024
2.1.0 Stable Nov 29, 2024
2.x-dev Dev Nov 29, 2024