Google Oauth IMAP 每次都请求许可

发布于 2024-11-04 21:25:36 字数 619 浏览 4 评论 0原文

我目前正在开发一个基于网络的邮件服务(它不完全是一个邮件客户端,但有很多需要解释)。不过,我之前从未使用过 oauth,但这似乎是可行的方法,我的简单课程基于 示例代码。但是示例代码没有提供多次登录的解决方案,或者我错过了。

所以基本上我的问题是,每次登录时我都需要再次授权 gmail,而我见过其他服务,您只需这样做一次,然后您只需登录并立即重定向回来,而无需再次接受。

编辑:澄清一下,我使用 oauth 来登录和 IMAP,这很愚蠢吗?我认为这是最好的方法,因为当我的所有应用程序真正做的都是通过 oauth 围绕 google apps imap 时,将 OpenID 和 oauth 连接到同一用户似乎很奇怪。我认为 tungle.me 是这样工作的,因为我只需要在那里授权一次,下次谷歌立即将我重定向回来时,我希望我的应用程序也能这样工作。

Edit2:进一步搜索后,似乎授权是第一次,然后我应该使用身份验证,因为英语不是我的母语,但我认为它们的意思是相同的。所以问题是,当已经创建帐户的用户再次登录时,如何通过谷歌进行身份验证,这样我就不需要每次都生成新的令牌。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

流心雨 2024-11-11 21:25:36
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);

...最后一个解决了问题,因为默认情况下 apiClient 将approval_prompt设置为“force”

希望这对某人有帮助

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

¢蛋碎的人ぎ生 2024-11-11 21:25:36

使用 google API,您可以将 1 次身份验证 cookie 转变为永久身份验证 cookie。如果您将此新的永久身份验证 cookie 存储在数据库或其他位置,则可以将其用于该特定用户,而不是每次都生成新的身份验证 cookie。

像这样的东西:

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

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文