Google Oauth IMAP asking for permission everytime

本小妞迷上赌 提交于 2019-12-24 12:04:00

问题


I'm currently working on a web-based mail-service (it's not quite a mail-client but it's a lot to explain). However I've never worked with oauth before this but it seems like the way to go, I've based my simple classes on the sampel code. However the sample code doesn't provide the solution on signing in several times, or I've missed it.

So basically my problem is that everytime I log in I need to authorize to gmail again while I've seen other services where you do that once and after that you just sign in and get instantly redirected back without accepting again.

Edit: To clarify, I'm using oauth both for logging in and for IMAP, is this stupid? I though that was the best way as it seem weird to have both an OpenID and oauth connected to the same user when all my app really do is centered around google apps imap via oauth. I think that tungle.me works this way as I only have to authorize once there and the next time google instantly redirects me back, I want my app to work that way.

Edit2: After further searching it seems like authorization is for the first time and then I should use Authentication, as English isn't my first language I though they meant the same thing. So the questions stands, how to I authenticate with google when a user who've already created an account logs in again so that I won't need to generate new tokens every time.


回答1:


require_once './oauth/apiClient.php';
require_once './oauth/contrib/apiPlusService.php';
$client = new apiClient();
$client->setApplicationName("Name");
$client->setScopes(array('https://www.googleapis.com/auth/plus.me'));
$client->setApprovalPrompt (auto);

... the last one solves the problem, since by default apiClient sets approval_prompt to "force"

Hope this helps someone




回答2:


Using the google API you can turn a 1 time auth cookie into a permanent auth cookie. If you store this new permanent auth cookie in a database or somewhere, you can use it for that specific user instead of generating a new auth cookie each time.

Something like this:

$client = new Zend_Gdata_HttpClient();
$client->setAuthSubPrivateKeyFile('key.pem', null,false);
$uri = Zend_Gdata_AuthSub::getAuthSubTokenUri($next, $scope, $secure, $session)
$gCalToken = Zend_Gdata_AuthSub::getAuthSubSessionToken(trim($uri),$client);


来源:https://stackoverflow.com/questions/5894660/google-oauth-imap-asking-for-permission-everytime

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!