Skip to content
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

Remove authentication on a specific request #402

Closed
labomatik opened this issue Apr 17, 2024 · 5 comments
Closed

Remove authentication on a specific request #402

labomatik opened this issue Apr 17, 2024 · 5 comments

Comments

@labomatik
Copy link

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));

@jlevers
Copy link

jlevers commented Apr 17, 2024

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());

@Sammyjo20
Copy link
Member

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?

@labomatik
Copy link
Author

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

image

@patrickcarlohickman
Copy link
Contributor

@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

@labomatik
Copy link
Author

labomatik commented Jun 12, 2024

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

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

No branches or pull requests

4 participants