OAuth2授权码放在Cookie中,好还是不好?

huangapple go评论67阅读模式
英文:

OAuth2 Authorization Code in Cookie, good or bad?

问题

我似乎找不到一个简单的答案来解决如何持久化OAuth2身份验证的问题...让我们以Google+ OAuth2 API为例。

  1. 用户访问页面。
  2. 用户未经身份验证,被重定向到身份验证页面进行登录。
  3. 用户成功登录并授权我的应用程序。
  4. 用户被重定向到由我指定的URI,并获得授权码。
  5. 我使用授权码获取令牌,以便以用户的名义提交查询。

一切都很好。我的问题是:在第2步中,如何安全地知道访问页面的用户已经登录,而不必经过将他重定向到所有这些页面的整个过程。

我认为将在第4步中获取的授权码存储在cookie中不是一个选项。

所有这些将在服务器端(使用Go语言,如果有关系的话)应用程序中发生。
非常感谢任何帮助...我需要一个简单的解决方案。

谢谢!

英文:

I can not seem to find a SIMPLE answer to the question on how to persist OAuth2 authentication... Let's take Google+ OAuth2 API as an example.

  1. User goes to page
  2. User is not authenticated, and gets redirected to authentication page where he logs in
  3. User logs in successfully and authorises my app
  4. User gets redirect to specified (by me) URI with Authorisation Code
  5. I use authorisation code to obtain a token in order to submit queries in the name of the user

All is good and well. My question is: how do you SECURELY know at step 2 that the user visiting the page is already logged in, without having to go through the whole process of redirecting him to all these pages.

I assume storing the Authorisation Code retrieved at step 4 in a cookie is not an option.

All of this will happen in a server-side (Go - if that matters) application.
Any help is much appreciated... I need a simple solution.

Thank you!

答案1

得分: 2

使用服务器端会话来存储任何身份验证状态,甚至是访问令牌(如果需要)。

一种解决方案是使用数据库作为会话存储(加密的 cookie 保存会话 ID),
另一种解决方案是使用 cookie 会话(加密的 cookie 保存会话数据)。
使用只有服务器能够解密的加密 cookie 应该足够安全。

英文:

use server-side sessions to store any authentication state or even access tokens if you need them.

one solution is to use a database for session store (an encrypted cookie holds the session id)
and another is to use cookie sessions (encrypted cookies that hold the session data).
using encrypted cookies that only the server is able to decrypt should be safe enough.

huangapple
  • 本文由 发表于 2014年8月22日 19:14:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/25445704.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定