How can I acquire the token in the users_jwt submodule?

Created on 2 June 2023, over 1 year ago

Problem/Motivation

I'm testing the module to use drupal as api and make requests from a React application. The module works correctly when I use the token that is generated in the url "/jwt/token" and send the "Authorization: Bearer [token]" header, but there is no documentation of how I should acquire the token to use with the "Authorization: UsersJwt [token]" header.

Steps to reproduce

Starting from an environment prepared to serve content through rest api, which already shows json content for example in the path "/node/1"

Installs the JSON Web Token Authentication (JWT), JWT Authentication Consumer, JWT Authentication Issuer, Users' JWT Authentication, and HTTP Basic Authentication modules.

Configure the JSON Web Token Authentication module.

In "/admin/people/permissions" remove the "View published content" permission for the anonymous user.

From Postman make a get query to "/jwt/token?_format=json" with Authorization Basic and a valid username and password.

You get a token.

With this token, make a query to "/node/1?_format=json" and the header "Authorization: Bearer [token]"

Works correctly.

Now do the same query with the header "Authorization: UsersJwt [token]"

It does not work.

The question is: how can I get a token to use with the header "Authorization: UsersJwt [token]"

Proposed resolution

The solution that I propose is to add in the documentation, instructions to generate a valid token for each user, although the really ideal would be that when making a request to a route such as "/jwt/user-token?_format=json" with Authorization Basic and a valid username and password, obtain a valid token and most importantly, that this token can be invalidated by removing the key ID with which it has been signed.

💬 Support request
Status

Active

Version

2.0

Component

Documentation

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024