use*_*712 6 authentication session oauth asp.net-web-api google-signin
我已经使用本页中概述的步骤为我的网站实现了谷歌登录按钮:
https://developers.google.com/identity/sign-in/web/sign-in
然后,该页面提取 id_token 并将其发送到我的后端服务器,该服务器根据 Google 验证端点对其进行验证。然后,我使用 id_token 中编码的 Google ID 来检索与其关联的应用程序特定数据(存储在我的数据库中)。
我只是有点困惑接下来需要做什么来让用户“登录”到我的应用程序并继续安全地从我的后端 API 检索数据。
我打算做以下事情:
我只是想知道这听起来是否合理,这是最佳实践还是有更好的方法?是否有安全的方法来生成会话 ID,或者是否有 API 可以帮助解决此问题(我目前正在使用 ASP.Net Web Api 2 作为我的后端服务)
非常感谢,
我认为您混淆了身份验证和授权。您应该在服务器应用程序中拥有自己的用户记录,并且密钥是 Google,而不是“名称”。以下是我在 Django (Python) 应用程序中执行的操作:
def auth_id_token(request):
# This is called by the AJAX code that triggers when
# the user has successfully signed in
id_token = request.POST.get('id_token')
# Using the google-api-python-client library
idinfo = client.verify_id_token(
id_token,
settings.OAUTH2_CLIENT_ID
)
# Use the Django ORM to talk to my user database
user = User.objects.get(email=idinfo['email'])
# Using a Django primitive that makes sure the user
# gets a session cookie and asserts that the user is now signed in
auth.login(request, user)
return http.HttpResponse('User is now signed in on the server')
Run Code Online (Sandbox Code Playgroud)
笔记。Django 处理从此时起的所有授权。谷歌只是负责处理身份验证,向我证明他/她拥有该电子邮件地址。
| 归档时间: |
|
| 查看次数: |
1327 次 |
| 最近记录: |