2

I have created a custom token authentication class by extending the AbstractGuardAuthenticator class as explained here. My requirement was to accept a jwt, extract it and identify the user by check it's id against the database which is working completely fine.

Now I need to override underlying methods of it to use in php unit tests. In simple words, bypass it and set a default user. So I can test API end points without passing user tokens everytime when I do a functional test.

What I tried

I tried to defined a separate security.yaml in test folder and call customized class using it to override but still app calls the default class.

Path: config/packages/test/security.yaml

security:

  firewalls:

    main:
      anonymous: lazy
      logout: ~

      guard:
        authenticators:
          - Otrium\Infrastructure\Security\TestTokenAuthenticator
        entry_point: Otrium\Infrastructure\Security\TestTokenAuthenticator

      stateless: true

The only solution I found so far is to keep a matching jwt and pass it as a header value on each test.

Symfony version - 5 / Php version - 7.4

1 Answer 1

4

You don't need to override Authenticator.

You can find solution here

I used it in my project and I don't need to pass token in every request.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.