简体   繁体   English

如何在没有用户干预的情况下获得 OAuth2 身份验证

[英]How to get OAuth2 authentication without user intervention

I am making an API call that requires OAuth2.我正在进行一个需要 OAuth2 的 API 调用。 I initially make the call and authorize it with a login via the web.我最初拨打电话并通过网络登录进行授权。 I'm then taking the supplied Refresh Token and using it to make subsequent calls in my application.然后我使用提供的刷新令牌并使用它在我的应用程序中进行后续调用。

The issue is that in the subsequent calls the Refresh Token is used up and I get a new one.问题是在随后的调用中,刷新令牌用完了,我得到了一个新令牌。 I save this new one in the database and then use that saved one on the next call.我将这个新的保存在数据库中,然后在下次调用时使用保存的一个。 This works great for about xx number of calls and then for some reason the Refresh Token goes bad and I have to go and manually grab one through the web login again.这适用于大约 xx 次调用,然后由于某种原因刷新令牌变坏,我必须再次通过网络登录手动获取一个。

I have no way to tell, that I know of, when the token goes bad or why.我无法知道,我知道,令牌何时变坏或为什么变坏。

Is there a way to just send the login info or the OAuth2 info or something that'll get me a new valid Refresh Token without me having to "authorize" my own app?有没有一种方法可以只发送登录信息或 OAuth2 信息,或者可以让我获得新的有效刷新令牌而无需“授权”我自己的应用程序的方法?

The API that I am using is Constant Contact.我使用的 API 是 Constant Contact。

The OAuth standards are based on 2 forms of expiry: OAuth 标准基于两种形式的到期:

ACCESS TOKENS访问令牌

These are short lived API credentials and a common lifetime is 60 minutes.这些是短期 API 凭证,通常的生命周期为 60 分钟。 When they expire the API client receives an HTTP response with a 401 status code.当它们过期时,API 客户端会收到一个带有 401 状态代码的 HTTP 响应。 The client can then try to silently renew the access token.然后客户端可以尝试以静默方式更新访问令牌。

REFRESH TOKENS刷新令牌

These are long lived credentials that represent a user session, and a common lifetime is 8 or 12 hours.这些是代表用户会话的长期凭证,通常的生命周期为 8 或 12 小时。 During this time the access token can be renewed silently.在此期间,可以静默更新访问令牌。 Eventually however, the refresh token itself expires and the silent renewal request results in an error with an invalid_grant error code.然而,最终刷新令牌本身会过期,并且静默更新请求会导致一个带有invalid_grant错误代码的错误。

USER RE-AUTHENTICATION用户重新认证

There are very good reasons for making users re-authenticate and I would avoid trying to bypass this.让用户重新进行身份验证有很好的理由,我会避免尝试绕过这一点。 Tokens that last for a very long time are not recommended.不推荐使用时间很长的代币。 Usability can be pretty good with only an occasional re-authenticate operation, along with features such as password autofill.只需偶尔进行重新身份验证操作以及密码自动填充等功能,可用性就可以非常好。

FURTHER DETAILS更多细节

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

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