Skip to content

Add JWT authentication support #140

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open

Conversation

heddn
Copy link

@heddn heddn commented Feb 26, 2025

@heddn
Copy link
Author

heddn commented Feb 27, 2025

This allows usages like:

  Scenario: Creating a node via the API triggers creation
    Given I am authenticating with JWT
    And the JWT will have claim "drupal[uid]" with value 2
    And the JWT will have claim "exp" with value "now + 10 minutes"
    And the "Accept" request header is "application/vnd.api+json"
    And the "Content-type" request header is "application/vnd.api+json"
    Given the request body is:
    """
{
  "data": {
    "type": "node--page",
    "attributes": {
      "title": "My title",
    },
  }
}
    """
    When I request "/jsonapi/node/page" using HTTP "POST"
    Then the response code is 200

@heddn
Copy link
Author

heddn commented Feb 27, 2025

The reason we need to have that "toggle" for JWT in the scenario is that we have JWT and Basic Auth and Cookie authentication options. We can't just brute force everything via a configured guzzle client to use JWT.

@christeredvartsen
Copy link
Member

There seems to be failures in your fork: https://github.com/pwolanin/behat-api-extension/actions/runs/13721448790

@heddn
Copy link
Author

heddn commented Mar 7, 2025

By using this extension we no longer have to ignore an error related to
the service container.
@christeredvartsen
Copy link
Member

I just pushed a minor change to this branch, installing the Symfony extension for PHPStan instead of ignoring an error.

Would you be able to provide some tests that showcase the feature added in this branch? Perhaps adding a scenario in the features/jwt-matcher.feature file, or just adding a new feature file?

@pwolanin
Copy link
Contributor

Yes, we will have to look at the test setup - it needs a secret for the JWT in the behat.yml file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants