authentication - oAuth 2.0 - 代表用户行事

标签 authentication oauth oauth-2.0

我是 oAUth2 的新手,我想弄清楚一些事情。

我了解 oAuth2 涉及的基本原则,但我不确定如何在我的情况下实现它。

我正在编写一个应用程序,代表用户自动执行手动流程并执行一些任务(更新/请求状态...等)。我们要连接的 API 使用 oAuth2 来授予我们的应用程序权限。我们计划让用户在我们创建新帐户时授予我们的应用程序权限。

我了解用户将请求提供给我们应用程序的身份验证代码。然后我们的应用程序将使用身份验证代码生成访问 token 。

我们只想做一次。然后充当用户发送和接收通知,而无需让用户使用其凭据登录服务。

我不确定如何在无需存储用户凭据以获取授权代码的情况下实现此功能,因为授权代码和授权 token 已过期。我猜这是一个常见的场景。

我需要做什么才能完成我想要的事情?

最佳答案

您可以使用 RefreshToken 获取新的 AccessToken,如果它由 Authorization Server 提供。

如果未提供,我会联系 Api 提供商,您永远不应存储用户凭据。事实上,如果 OAuth 协议(protocol)作为客户端得到很好的实现,你应该永远无法获得客户端凭据。当用户必须登录时,您应该将用户重定向到授权服务器,用户应该在那里登录,然后授权服务器应该将授权 token 重定向到您的应用程序。

另请参阅 OAuth 2.0 规范中关于刷新 token 的解释:

Refresh tokens are credentials used to obtain access tokens. Refresh tokens are issued to the client by the authorization server and are used to obtain a new access token when the current access token becomes invalid or expires, or to obtain additional access tokens with identical or narrower scope (access tokens may have a shorter lifetime and fewer permissions than authorized by the resource owner). Issuing a refresh token is optional at the discretion of the authorization server. If the authorization server issues a refresh token, it is included when issuing an access token

注意

如果您使用您的 RefreshToken 请求一个新的 AccessToken,并且响应包括一个新的 RefreshToken,您应该覆盖您当前保存的 RefreshToken。换句话说,您应该始终使用收到的最新 RefresthToken。

关于authentication - oAuth 2.0 - 代表用户行事,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22512794/

相关文章:

asp.net - 仅在登录 MVC .net 站点时显示 <li> 项目

python - 启动具有多个独立项目的 TRAC 服务器

javascript - 无法通过 LinkedIn 授权

oauth - 强制跳过 Stripe 连接帐户申请表

go - ebay API 客户端凭据授权

c# - 是否可以使用外部 AD 从 Azure 托管的 Web 应用程序进行身份验证?

spring - 对多个 URL 使用 AbstractAuthenticationProcessingFilter

twitter - 为什么 Twitter 需要 API key key 和访问 token key ?

azure - Azure AD 上的企业应用程序可以分配不同范围的权限吗?

oauth-2.0 - 使用 Slack 登录 - 无效范围 : identity. 基本,identity.avatar