saloon
saloon copied to clipboard
Remove authentication on a specific request
I would like to remove the authentication on a specific request while the connector is using OAuth
The request to the API is the following:
- OAuth request to get the Bearer
- Create a Job -> we are receiving an URL (Using Bearer)
- PUT a file to the URL (No Auth should be used)
The last step is actually sending an error when we push to AWS "Only one auth mechanism allowed;" since we are using an API key on that step
Is there a way to remove from the connector the Authentication?
$api = new APIConnector(config('services.api.client_id'), config('services.api.client_secret'));
$authenticator = $api->getAccessToken([
"connect/read:jobs",
"connect/submit:jobs",
"connect/read:sending-events"
]);
$api->authenticate($authenticator);
$data = $api->send(new CreateJobSingleFile('01HT2RK56ETAD2GGNRGA4Z03BK', 'test', 'test.pdf'));
$jobFile = $data->dtoOrFail();
// We should now post file to $jobFile->fileUploadUrl
$file = \Storage::disk('local')->path('test.pdf');
// We should remove the Auth
$result = $api->send(new AttachFileToJob('01HT2RK56ETAD2GGNRGA4Z03BK', 'test.pdf', $file, $jobFile->fileUploadUrl));
Maybe you could do it with a NullAuthenticator
, something like this:
class NullAuthenticator implements Authenticator
{
public function set(PendingRequest $pendingRequest): void
{
}
}
And then when you want to make the auth-free call:
$api->authenticate(new NullAuthenticator());
Hey @labomatik I have just released v3.9.0 which includes the above PR made by @patrickcarlohickman. Would you be able to try the NullAuthenticator
and see if this fixes your issue?
Hello,
Sorry for being late on this... I just validated and it seems that the nullAuthenticator doesn't erase all previous auth mechanism, the API we are using is still pinpointing an issue with a mixed auth... I added a debug just after the NullAuthenticator and i do see the oauthConfig object part of the connector
@labomatik ,
Changing the authenticator won't affect the oauthConfig
property that is already set on the connector. However, the NullAuthenticator
doesn't use this config data at all, so I think the issue is somewhere else.
Would you be able to provide the implementation for your APIConnector
connector, AttachFileToJob
request, and possibly a dump of the request actually made (with any sensitive data/ids/secrets/keys redacted).
Thanks, Patrick
Thanks @patrickcarlohickman after a review on the AttachFileToJob i just found this:
protected function defaultHeaders(): array
{
return [
'x-api-key' => config('services.api.api_key'),
//'Authorization' => null. ---> I removed this...
];
}
And now it's working :-) Thanks for the support