[英]Can not authenticate with UserInfo service with google-api-php-client library
[英]Google API: Can I authenticate a specific user with PHP Client?
我的應用程序中的用戶正在連接他們的 Gmail 帳戶。 我有一個功能,允許他們斷開連接,然后在完全刪除集成和所有與之相關的數據之前,他們可以重新連接。 我正在使用 OAuth 2 身份驗證方法。
目前,當我向 Google 進行身份驗證時,會顯示登錄屏幕,如果該用戶有多個 Gmail 登錄名,那么它們都會顯示給用戶以供選擇。
如果用戶選擇的電子郵件與他們之前選擇的不同,這會在我的系統中產生沖突。 對於此特定場景,我需要為他們選擇該電子郵件。 這可能嗎?
沒有辦法 100% 確保他們將使用相同的電子郵件地址登錄,但是您可以添加
$client->setLoginHint('[Users email here]');
這將鼓勵他們使用該電子郵件登錄,因為他們必須選擇一個谷歌帳戶的彈出窗口只會顯示該帳戶。 這將要求您保存上次的電子郵件。
function buildClient(){
$client = new Google_Client();
$client->setAccessType("offline"); // offline access. Will result in a refresh token
$client->setIncludeGrantedScopes(true); // incremental auth
$client->setAuthConfig(__DIR__ . '/client_secrets.json');
$client->addScope([YOUR SCOPES HERE]);
$client->setLoginHint('[Users email here]');
$client->setRedirectUri(getRedirectUri());
return $client;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.