php - Gmail IMAP using OAuth 2.0 and Service Account fails with status 400 -
php - Gmail IMAP using OAuth 2.0 and Service Account fails with status 400 -
when seek connect gmail imap server using xoauth2 mechanism , service account, next response:
{"status":"400","schemes":"bearer","scope":"https://mail.google.com/"}
the code utilize in php is:
$email = "an_user@of_a_domain.com"; require_once 'googleapiclient/google_client.php'; $client = new google_client(); $client->setuseobjects(true); $gac = new google_assertioncredentials( "xxxxxxxxxxx@developer.gserviceaccount.com", 'https://mail.google.com/', file_get_contents("path/to/private/key"), 'notasecret', 'http://oauth.net/grant_type/jwt/1.0/bearer', $email ); $client->setapplicationname("test app"); $client->setassertioncredentials($gac); $client::$auth->refreshtokenwithassertion(); $token = $client::$auth->getaccesstoken(); $authstr = base64_encode("user=" . $email . "\1auth=bearer " . $token . "\1\1"); $response = send_command_to_imap("tag1 authenticate xoauth2 " . $authstr);
following instructions @ http://www.limilabs.com/blog/oauth2-gmail-imap-service-account authorized access mail. (and reinstalled app in test domain, of course) still failed.
i can token okay, not authenticate imap.
i've tried access gmail imap non-domain google users (access token includes "offline_token") w/o using service business relationship - , worked fine me!
does know i'm doing wrong?
since lastly io2014 there much easier way integrate gmail :
https://developers.google.com/gmail/api/overview
php oauth-2.0 gmail-imap google-apps-marketplace service-accounts
Comments
Post a Comment