-
I have an api, where some endpoints require "x-api-key" based auth, some require JWT based auth, some don't require any. I'm trying to figure out how I should structure them, any recommendation? |
Beta Was this translation helpful? Give feedback.
Answered by
Sammyjo20
Jun 7, 2023
Replies: 1 comment
-
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);
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
harryqt
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
You could also make your own custom authenticators if you have multiple routes that require JWT/X-API-KEY