Skip to content

Permission denied, wrong credentials when using sendgrid-php 6.0.0 on PHP 7.2.3 #584

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

Closed
fterrag opened this issue Mar 10, 2018 · 10 comments
Closed
Labels
difficulty: easy fix is easy in difficulty status: work in progress Twilio or the community is in the process of implementing type: bug bug in the library

Comments

@fterrag
Copy link

fterrag commented Mar 10, 2018

Issue Summary

When attempting to call $sg->client->mail()->send()->post($mail); per the Quick Start in README.md, I'm receiving the error "Permission denied, wrong credentials". I have verified that the API key I am using is correct and also have tried creating new API keys.

Where it gets interesting is that if I downgrade the sendgrid-php library to version 5.0.0, I'm able to successfully send an email.

Any thoughts here would be helpful! Thanks

Steps to Reproduce

Run the code from the Quick Start in README.md.

Technical details

  • sendgrid-php Version: master 8db454e (6.0.0) and 9fb94f6 (5.0.0)
  • PHP Version: 7.2.3 on macOS 10.13.3 installed via Homebrew
@fterrag fterrag changed the title 6.0.0 - Permission denied, wrong credentials Permission denied, wrong credentials when using sendgrid-php 6.0.0 on PHP 7.2.3 Mar 10, 2018
@thedotedge
Copy link

thedotedge commented Mar 10, 2018

Looks like downstream dependency is properly broken — 2 last patches have introduced different regressions, see sendgrid/php-http-client@46dcffa.

Workaround is to pin "sendgrid/php-http-client": "3.9.0"

@fterrag
Copy link
Author

fterrag commented Mar 10, 2018

@thedotedge makes sense. Thanks!

@thedotedge
Copy link

thedotedge commented Mar 10, 2018

Correction: it's actually 3.8.0 that works, all subsequent versions are broken. I wonder if it even makes sense to depend on "sendgrid/php-http-client": "~3.7" in sendgrid/sendgrid-php if downstream is so unstable.

In fact, even API is broken after sendgrid/php-http-client update: sample code sendgrid()->client->mail()->send()->post($mail); that is supposed to return response object silently start returning itself 😞

@fterrag
Copy link
Author

fterrag commented Mar 10, 2018

@thedotedge Pinning to 3.9.0 introduced a notice (seen below), but 3.8.0 seems to do the trick. Thanks!

Notice: Object of class SendGrid\Client could not be converted to int in /Users/frank/<removed>/vendor/sendgrid/php-http-client/lib/Client.php on line 269

@thinkingserious
Copy link
Contributor

@thedotedge @fterrag

Please try php-http-client 3.9.2, that version should be good to go. Thanks!

@thedotedge
Copy link

@thinkingserious does it work for you? For me every request was returning 401.

@fterrag
Copy link
Author

fterrag commented Mar 11, 2018

@thinkingserious I also receive a 401 when using php-http-client 3.9.2. It appears the problem might lie in Client.php around lines 192-196:

if (isset($headers)) {
    $headers = array_merge($this->headers, $headers);
} else {
    $headers = []; // If $headers is null, $this->headers never gets used in the request.
}

Should probably be changed to:

if (isset($headers)) {
    $headers = array_merge($this->headers, $headers);
} else {
    $headers = $this->headers; // If $headers is null, $this->headers will still be used in the request.
}

When this change is made, I'm able to successfully send email. I'm not too familiar with the library, so this might not be the best/correct place to solve the issue.

@thinkingserious thinkingserious added type: bug bug in the library status: work in progress Twilio or the community is in the process of implementing difficulty: easy fix is easy in difficulty labels Mar 11, 2018
@thinkingserious
Copy link
Contributor

@thedotedge,

It was working for me when using php-http-client directly. I believe @fterrag found the fix though. When we set $headers = [] we are overwriting the values coming from sendgrid-php. I'm fixing now with 3.9.3.

With Best Regards,

Elmer

@thinkingserious
Copy link
Contributor

Thanks again to everyone on this thread for helping get a fix pushed out quickly.

I have verified that this bug is fixed using 3.9.3 in sendgrid-php.

Thanks again!

@phansys
Copy link

phansys commented Mar 12, 2018

Related to #585.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difficulty: easy fix is easy in difficulty status: work in progress Twilio or the community is in the process of implementing type: bug bug in the library
Projects
None yet
Development

No branches or pull requests

4 participants