简体   繁体   English

Google PHP API(google-api-php-client)-总是提示离线访问

[英]Google PHP API (google-api-php-client) - Always prompting for Offline access access

I have a very basic PHP site that I want to use oauth2 authentication against Google Apps, using the example they provided (below is my version), The user on authentication keeps getting prompted to allow my app offline access to their account, Which I don't want. 我有一个非常基本的PHP网站,我想使用Google提供的示例(下面是我的版本)对Google Apps使用oauth2身份验证,身份验证的用户不断收到提示,要求我的应用程序脱机访问其帐户,我不这样做不想。

$this->gapps_api_client = new Google_Client();
// $this->gapps_api_client->setAccessType('online');
$this->gapps_api_client->setApplicationName( GAPPS_APPLICATION_NAME );
$this->gapps_api_client->setClientId( GAPPS_CLIENT_ID );
$this->gapps_api_client->setClientSecret( GAPPS_CLIENT_SECRET );
$this->gapps_api_client->setRedirectUri( GAPPS_REDIRECT_URI );

$this->oauth2 = new Google_Oauth2Service($this->gapps_api_client);

It's worth nothing I have been playing with "setAccessType" however no values seem to have an effect on this offline permission mode. 我一直在玩“ setAccessType”,这毫无价值,但是似乎没有任何值会影响此离线权限模式。 I've tried leaving it commented out, setting it to "online", "offline" nothing has made a difference. 我尝试将其注释掉,将其设置为“在线”,“离线”没有任何改变。

Anybody else been able to oauth2 authenticate without the user granting your app "Offline access"? 在没有用户授予您的应用“离线访问权限”的情况下,其他人也能够进行oauth2身份验证吗?

The offline access display is often flagged if you have previously granted an app access, but the app is asking for sign in again (if the consent dialog is being forced or similar). 如果您先前已授予应用程序访问权限,但该应用程序要求再次登录(如果强制同意对话框或类似操作),则通常会标记脱机访问显示。 This is due to incremental auth - its trying to hide previously granted scopes. 这是由于增量身份验证-它试图隐藏以前授予的范围。

To test this, try revoking all app access with https://security.google.com/settings/security/permissions and signing in again. 要对此进行测试,请尝试使用https://security.google.com/settings/security/permissions撤消所有应用程序访问权限,然后重新登录。 You should see the full scopes. 您应该看到完整的范围。

If that is the issue, then it is likely something your users wont see - when they sign in again they should not see a consent dialog unless you are using prompt=force or similar. 如果这是问题所在,则可能是用户看不到的东西-再次登录时,除非您使用的是quick = force或类似命令,否则他们不会看到同意对话框。

You might also want to look at retrieving profile using the Google+ API (this works for all account types): https://developers.google.com/+/api/latest/people/get , and upgrading to the latest version of the PHP library: https://github.com/google/google-api-php-client 您可能还想看看使用Google+ API(对所有帐户类型均适用)检索个人资料: https : //developers.google.com/+/api/latest/people/get ,并升级到最新版本的PHP库: https//github.com/google/google-api-php-client

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM