如何取消 Google 上的操作与 Auth0 之间的帐户关联
How can I unlink account between Actions on Google and Auth0
我正在使用 Actions on Google
(在移动设备上 phone Google Assistant
)并通过使用其 Account Linking
我已登录 Auth0
(登录window:
image).
但是,我想随时从 Auth0
注销,这样我就可以从头开始测试整个过程。
我在 Python
和 Flask
中按照 Auth0
文档 (https://auth0.com/docs/logout) 编写了以下源代码。
from flask import Flask, render_template, request, jsonify
import requests
app = Flask(__name__)
@app.route("/", methods=['GET', 'POST'])
def index():
session['user'] = 'Poete_Maudit'
data = request.get_json()
if data is not None:
action = data["queryResult"]["action"]
else:
return 'HERE'
# Triggers actions.intent.SIGN_IN which leads to Auth0
if (action == 'sign'):
return jsonify({"payload": {
"google": {
"expectUserResponse": True,
"isSsml": False,
"noInputPrompts": [],
"systemIntent": {
"data": {
"@type": "type.googleapis.com/google.actions.v2.SignInValueSpec"
},
"intent": "actions.intent.SIGN_IN"
}
}
}
})
# I have other if statements below which retrieve the access token
# and do in general other stuff on Actions on Google app
# but it is too long to include it here
@app.route('/logout')
def logout():
session.clear()
return redirect('https://project_id.eu.auth0.com/v2/logout?returnTo=http://127.0.0.1:5000')
if __name__== "__main__":
app.secret_key = os.urandom(24)
app.run(debug=True)
在我执行了整个登录过程一次后,我手动转到(从浏览器)到 http://127.0.0.1:5000/logout
,这成功地将我重定向到 http://127.0.0.1:5000
。在 python 控制台,我得到:
127.0.0.1 - - [06/Jun/2018 14:09:04] "GET /logout HTTP/1.1" 302 -
127.0.0.1 - - [12/Jun/2018 11:03:16] "GET / HTTP/1.1" 200 -
在 Auth0
日志部分我得到 Success Logout
(image).
但是,当我再次在手机上重新启动整个过程时phone Google助手登录window 没有出现,我已经用相同的 accessToken
.
再次登录 Auth0
如何通过清除 http://127.0.0.1:5000
上的会话 and/or cookie 正确注销,从而使 Auth0
登录window要再次出现?
P.S。
1) 请记住,目前我正在使用 Python
和 ngrok
完成所有这些工作。如果我重新启动 ngrok
会话然后登录 window 重新出现但显然我想以编程方式执行此操作。
2) 请不要想当然。我可能在我所做的事情中遗漏了一些非常基本的东西,所以请随时问我关于这个的非常基本的问题。
Auth0 中的 /v2/logout
端点旨在从前端通道(即浏览器)使用,因此您的后端应用程序应该 return 一个 302
重定向响应指向/v2/logout
端点(如果你想在清除会话后将用户重定向回特定的 URL,你可以使用文档中解释的 returnTo
参数)。
通过像您现在所做的那样发出反向通道请求(服务器到服务器),会话 cookie 丢失,因此 Auth0 不知道要终止哪个会话。
另请注意,/v2/logout
端点会清除 Auth0 中的会话 ,但您还必须清除应用程序中的会话。如果使用 Flask,请查看这些 Flask session.clear examples.
我已将相关消息发送给 Google 支持人员,我得到了以下答复:
To unlink your account you can use this link
(https://gala-demo.appspot.com), in the field Service ID enter the
project ID and add "_dev" at the end (in your case it will be
"Dnipro-Chatbot_dev"), then click Unlink My Accounts.
此外,我问他们我是否可以通过编程方式执行此操作(而不是像上面那样手动执行),我得到了以下答案:
I'm not sure if this is possible to do in Python, but you can try
following: If you can send back a 401 status code from your oauth
token exchange endpoint. The 401 will tell AoG that the access token
is invalid and force AoG to initiate the account linking flow again.
Hope this can help you.
总之,您当然可以使用上面的 link 取消 link 帐户,因为我测试过它并且它工作正常。关于第二个答案,我不确定这是否完全有可能,至少在陈述的方式上是这样。您不能真正以编程方式从 Auth0 发送 401 状态代码。您可以在 Auth0 上做的是将 Auth0 应用程序的 JWT 过期时间设置得非常低(例如 60 秒),并以这种方式强制撤销访问令牌。但这又不是真正的程序化解决方案,我还没有测试过。
我正在使用 Actions on Google
(在移动设备上 phone Google Assistant
)并通过使用其 Account Linking
我已登录 Auth0
(登录window:
image).
但是,我想随时从 Auth0
注销,这样我就可以从头开始测试整个过程。
我在 Python
和 Flask
中按照 Auth0
文档 (https://auth0.com/docs/logout) 编写了以下源代码。
from flask import Flask, render_template, request, jsonify
import requests
app = Flask(__name__)
@app.route("/", methods=['GET', 'POST'])
def index():
session['user'] = 'Poete_Maudit'
data = request.get_json()
if data is not None:
action = data["queryResult"]["action"]
else:
return 'HERE'
# Triggers actions.intent.SIGN_IN which leads to Auth0
if (action == 'sign'):
return jsonify({"payload": {
"google": {
"expectUserResponse": True,
"isSsml": False,
"noInputPrompts": [],
"systemIntent": {
"data": {
"@type": "type.googleapis.com/google.actions.v2.SignInValueSpec"
},
"intent": "actions.intent.SIGN_IN"
}
}
}
})
# I have other if statements below which retrieve the access token
# and do in general other stuff on Actions on Google app
# but it is too long to include it here
@app.route('/logout')
def logout():
session.clear()
return redirect('https://project_id.eu.auth0.com/v2/logout?returnTo=http://127.0.0.1:5000')
if __name__== "__main__":
app.secret_key = os.urandom(24)
app.run(debug=True)
在我执行了整个登录过程一次后,我手动转到(从浏览器)到 http://127.0.0.1:5000/logout
,这成功地将我重定向到 http://127.0.0.1:5000
。在 python 控制台,我得到:
127.0.0.1 - - [06/Jun/2018 14:09:04] "GET /logout HTTP/1.1" 302 -
127.0.0.1 - - [12/Jun/2018 11:03:16] "GET / HTTP/1.1" 200 -
在 Auth0
日志部分我得到 Success Logout
(image).
但是,当我再次在手机上重新启动整个过程时phone Google助手登录window 没有出现,我已经用相同的 accessToken
.
Auth0
如何通过清除 http://127.0.0.1:5000
上的会话 and/or cookie 正确注销,从而使 Auth0
登录window要再次出现?
P.S。
1) 请记住,目前我正在使用 Python
和 ngrok
完成所有这些工作。如果我重新启动 ngrok
会话然后登录 window 重新出现但显然我想以编程方式执行此操作。
2) 请不要想当然。我可能在我所做的事情中遗漏了一些非常基本的东西,所以请随时问我关于这个的非常基本的问题。
Auth0 中的 /v2/logout
端点旨在从前端通道(即浏览器)使用,因此您的后端应用程序应该 return 一个 302
重定向响应指向/v2/logout
端点(如果你想在清除会话后将用户重定向回特定的 URL,你可以使用文档中解释的 returnTo
参数)。
通过像您现在所做的那样发出反向通道请求(服务器到服务器),会话 cookie 丢失,因此 Auth0 不知道要终止哪个会话。
另请注意,/v2/logout
端点会清除 Auth0 中的会话 ,但您还必须清除应用程序中的会话。如果使用 Flask,请查看这些 Flask session.clear examples.
我已将相关消息发送给 Google 支持人员,我得到了以下答复:
To unlink your account you can use this link (https://gala-demo.appspot.com), in the field Service ID enter the project ID and add "_dev" at the end (in your case it will be "Dnipro-Chatbot_dev"), then click Unlink My Accounts.
此外,我问他们我是否可以通过编程方式执行此操作(而不是像上面那样手动执行),我得到了以下答案:
I'm not sure if this is possible to do in Python, but you can try following: If you can send back a 401 status code from your oauth token exchange endpoint. The 401 will tell AoG that the access token is invalid and force AoG to initiate the account linking flow again. Hope this can help you.
总之,您当然可以使用上面的 link 取消 link 帐户,因为我测试过它并且它工作正常。关于第二个答案,我不确定这是否完全有可能,至少在陈述的方式上是这样。您不能真正以编程方式从 Auth0 发送 401 状态代码。您可以在 Auth0 上做的是将 Auth0 应用程序的 JWT 过期时间设置得非常低(例如 60 秒),并以这种方式强制撤销访问令牌。但这又不是真正的程序化解决方案,我还没有测试过。