简体   繁体   English

Google 助理帐户关联 - 使用后端进行身份验证

[英]Google Assistant Account linking - Authentication with backends

I am a Moodle administrator and I would like to connect the Dialogflow chatbot – Google Assistant – Moodle site (Moodle site = backend server = mysite).我是 Moodle 管理员,我想连接 Dialogflow 聊天机器人 – Google Assistant – Moodle 站点(Moodle 站点 = 后端服务器 = mysite)。 When a Dialogflow intent asks for private user data from Moodle via a webhook, the intent requires sign in, and the user must be identified on the server.当 Dialogflow 意图通过 webhook 从 Moodle 请求私人用户数据时,该意图需要登录,并且必须在服务器上识别用户。 I would like to use the OAuth-based Google Sign-in linking concept.我想使用基于 OAuth 的 Google 登录链接概念。

The implemented services:实施的服务:

  1. The Dialogflow and Moodle are connected via a webhook. Dialogflow 和 Moodle 通过 webhook 连接。 Fulfillment – Webhook URL: mysite/client.php.履行 - Webhook URL:mysite/client.php。 The client.php file is on the Moodle server (backend server). client.php 文件位于 Moodle 服务器(后端服务器)上。 The intent uses webhook and Moodle sends the answer in JSON format.意图使用 webhook,Moodle 以 JSON 格式发送答案。

  2. Google Oauth 2 client was created. Google Oauth 2 客户端已创建。 URIs: mysite Authorized redirect URIs mysite/callback.php (Google APIs Client Library for PHP - Sign In requires) oauth-redirect.googleusercontent.com/r/DialogflowBotID (DialogflowBot requires) mysite/moodle37/admin/oauth2callback.php (Moodle requires) URIs: mysite Authorized redirect URIs mysite/callback.php (Google APIs Client Library for PHP - Sign In requires) oauth-redirect.googleusercontent.com/r/DialogflowBotID (DialogflowBot requires) mysite/moodle37/admin/oauth2callback.php (Moodle requires )

  3. The Google Oauth 2 and the Moodle are connected ( https://docs.moodle.org/39/en/OAuth_2_Google_service ). Google Oauth 2 和 Moodle 已连接( https://docs.moodle.org/39/en/OAuth_2_Google_service )。 The OAuth2 Google Cloud service is set in the Moodle, for enabling users to log in to Moodle with Google account.在 Moodle 中设置了 OAuth2 Google Cloud 服务,使用户能够使用 Google 帐户登录 Moodle。 At first, before the chats, the user logs in: the Google authenticates the user, sends user data to the Moodle and the Moodle stores the user's gmail address in the 'mdl_auth_oauth2_linked_login' mysql table.首先,在聊天之前,用户登录:Google 对用户进行身份验证,将用户数据发送到 Moodle,Moodle 将用户的 gmail 地址存储在 'mdl_auth_oauth2_linked_login' mysql 表中。 In Google terminology: users's information exists in the backend server.在谷歌术语中:用户的信息存在于后端服务器中。

  4. The Dialogflow and Google Assistant are connected via Account linking (developers.google.com/assistant/identity/google-sign-in-oauth). Dialogflow 和 Google 助理通过帐户链接 (developers.google.com/assistant/identity/google-sign-in-oauth) 连接。 Linking type: OAuth & Google Sign In – Implicit Authorization URL: mysite/login.php Token URL: oauth2.googleapis.com/token Google OAuth Client Client ID issued by your Actions to Google help outline: 169222114038 … Client secret: RPF … Client ID issued by Google to your Actions help outline: 169222114038 … Scopes: profile, email [ x] Google to transmit clientID and secret via HTTP basic auth header Linking type: OAuth & Google Sign In – Implicit Authorization URL: mysite/login.php Token URL: oauth2.googleapis.com/token Google OAuth Client Client ID issued by your Actions to Google help outline: 169222114038 … Client secret: RPF … Client Google 向您的操作帮助大纲颁发的 ID:169222114038 ... 范围:配置文件、email [x] Google 将通过 HTTP 基本身份验证 Z099FB995346F33E7430

The intent invokes the Google Sign In window, the user logs in, the redirect URI: oauth-redirect.googleusercontent.com/r/DialogflowBotID (Before you can use chat, I need to link your chat account to Google. Is that okay? Great, Tamás. Your learning chat account is now linked to Google.) Intent 调用 Google 登录 window,用户登录,重定向 URI:oauth-redirect.googleusercontent.com/r/DialogflowBotID(在您可以使用聊天之前,我需要将您的聊天帐户链接到 Google。可以吗?太好了,Tamás。您的学习聊天帐户现已与 Google 关联。)

  1. Google Sign-In for Websites - Authenticate with a backend server (developers.google.com/identity/sign-in/web/backend-auth) The Google API Client Library (github.com/googleapis/google-api-php-client) was installed on the Moodle server.用于网站的 Google 登录 - 使用后端服务器进行身份验证 (developers.google.com/identity/sign-in/web/backend-auth) Google API 客户端库 (github.com/googleapis/google-api-php-client ) 安装在 Moodle 服务器上。 The login.php and callback.php files are in the same directory as the client.php. login.php和callback.php文件与client.php在同一目录下。 The mysite/login.php invokes the Google Sign In window (accounts.google.com/signin/oauth... ) and will be redirected to the mysite/callback.php The callback.php handles the OAuth server response verify the token and contains: user data, email address (same as the email address in Moodle) access_token: ya29.a0 … refresh_token = 1//09M8- … id_token = eyJhbGciOi … The callback.php select the user email address from the backend server database and if (stored backend email = = received token email) establish an authenticated session for the user. The mysite/login.php invokes the Google Sign In window (accounts.google.com/signin/oauth... ) and will be redirected to the mysite/callback.php The callback.php handles the OAuth server response verify the token and contains: user data, email address (same as the email address in Moodle) access_token: ya29.a0 … refresh_token = 1//09M8- … id_token = eyJhbGciOi … The callback.php select the user email address from the backend server database and if (存储的后端 email = = 收到的令牌电子邮件)为用户建立一个经过身份验证的 session。

The callback.php file will be redirected to DialogflowBot: callback.php 文件将被重定向到 DialogflowBot:

$redirect_url = 'https://oauth-redirect.googleusercontent.com/r/DialogflowBotID#access_token=' . $access_token . '&token_type=bearer&state=' . $STATE_STRING;
header('Location: ' . filter_var($redirect_url, FILTER_SANITIZE_URL));

Actions Console – Test in Simulator: Before you can use learning chat, I need to link your learning chat account to Google. Actions Console – 在模拟器中测试:在您可以使用学习聊天之前,我需要将您的学习聊天帐户链接到 Google。 Is that okay?可以吗? Yes Linked: Great, Tamás.是链接:太好了,塔马斯。 Your learning chat account is now linked to Google.您的学习聊天帐户现已与 Google 相关联。

The 1 2 3 4 5 services work separately. 1 2 3 4 5 服务分开工作。

My questions are:我的问题是:

  1. developers.google.com/assistant/identity/oauth-concept-guide says: After the user logs in and credentials are verified, your service creates a long-lived access token and returns it to Google. developers.google.com/assistant/identity/oauth-concept-guide 说:用户登录并验证凭据后,您的服务会创建一个长期存在的访问令牌并将其返回给 Google。 How I can create a long-lived access token on my backend server?如何在后端服务器上创建长期访问令牌?

  2. After the user verification, how I can redirect the callback.php to the Dialogflow bot?用户验证后,如何将 callback.php 重定向到 Dialogflow 机器人? I used this:我用这个:

    $redirect_url = 'https://oauth-redirect.googleusercontent.com/r/DialogflowBotID#access_token='. $redirect_url = 'https://oauth-redirect.googleusercontent.com/r/DialogflowBotID#access_token='。 $access_token. $access_token。 '&token_type=bearer&state='. '&token_type=bearer&state='。 $STATE_STRING; $STATE_STRING; header('Location: '. filter_var($redirect_url, FILTER_SANITIZE_URL)); header('位置:'.filter_var($redirect_url, FILTER_SANITIZE_URL));

Is this proper?这合适吗?

  1. The client.php provides the JSON webhook response, but does not contain the token and state. client.php 提供 JSON webhook 响应,但不包含令牌和 state。 The callback.php includes the token and state, but can not answer the webhook. callback.php包含token和state,但无法应答webhook。 How can I connect the client.php, login.php, callback.php files?如何连接client.php、login.php、callback.php文件?

  2. I tried to sign out the user and unlink the account.我试图注销用户并取消关联该帐户。

    unset($_SESSION["auto"]);未设置($_SESSION["auto"]); unset($_SESSION['accesToken']);未设置($_SESSION['accesToken']); $client->revokeToken(accessToken); $client->revokeToken(accessToken); $client->revokeToken(); $client->revokeToken();

How a user unlink the linked account?用户如何取消关联的帐户? on phone?在电话上? or on website?还是在网站上?

enter image description here在此处输入图像描述

  1. Implementation of long-lived tokens is your implementation.长期令牌的实施是您的实施。 Please be aware of some of these considerations .请注意其中的一些注意事项

  2. Correct.正确的。 More info, see Handle authorization requests更多信息,请参阅处理授权请求

  3. Not familiar with your implementation.不熟悉你的实现。 Each request to the server-side will contain the access token.对服务器端的每个请求都将包含访问令牌。 So, this is your implementation.所以,这是你的实现。

  4. Also, this your implementation.另外,这是您的实现。 But essentially, you need a way to track long-lived tokens.但本质上,您需要一种方法来跟踪长期存在的令牌。

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

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