Skip to content

Proper way handle different auth #232

Closed Answered by Sammyjo20
harryqt asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @Dibbyo456

You could pass in the requirements on a per-request basis into the constructor of the request and then setting the headers based on the request.

class SomeRequest extends Request
{
     public function __construct(string $apiKey)
     {
            $this->headers()->add('X-API-KEY', $apiKey);
     }
}

You could also make your own custom authenticators if you have multiple routes that require JWT/X-API-KEY

class SomeRequest extends Request
{
     protected function defaultAuth()
     {
           return new JwtAuthenticator($this->token);
     }
}

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by harryqt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants