简体   繁体   English

如何无限期使用一个访问令牌/刷新令牌(oauth2-Spotify API)

[英]How to get one access token/refresh token for indefinite use (oauth2 - Spotify API)

I'm developing an application that will only use one Spotify account ever, and I don't quite understand the refresh token (using oauth2). 我正在开发一个仅会使用一个Spotify帐户的应用程序,而且我不太了解刷新令牌(使用oauth2)。 Ideally, I'd like to just use the Spotify API console to receive an access token and refresh token once that I can use forever and not have to worry about authorization again while the application is running. 理想情况下,我只想使用Spotify API控制台来接收访问令牌并刷新令牌,以便我可以永久使用它,而不必在应用程序运行时再次担心授权。 If I have a refresh token, can I just use that refresh token forever or do I need to constantly get a new token with that refresh token whenever I want to access the API? 如果我有刷新令牌,是否可以永久使用该刷新令牌,或者每当我想访问API时都需要不断获取带有该刷新令牌的新令牌吗?

TLDR: You don't need to refresh access keys for every call, but you do have to refresh the access key if it expires. TLDR:您不需要为每个呼叫刷新访问密钥,但是如果访问密钥到期,则必须刷新。

Refresh tokens are part of the OAuth2 flow. 刷新令牌是OAuth2流的一部分。 Access keys are short lived and expire, while refresh tokens are long lived. 访问密钥的寿命很短并且会过期,而刷新令牌的寿命很长。 You can use the refresh token with your client secret to get new access tokens when your access token expires. 您可以在客户端密钥中使用刷新令牌,以在访问令牌过期时获取新的访问令牌。 This is a security measure. 这是一种安全措施。 In the event your access token is leaked, it is only short lived without the refresh token and client secret. 如果您的访问令牌泄漏,则只有短暂的时间,而没有刷新令牌和客户端机密。 In the event your refresh token is leaked, you can have that blacklisted. 万一您的刷新令牌泄漏了,您可以将其列入黑名单。

There are some exceptions if you're not accessing private data. 如果您不访问私有数据,则有一些例外。 The Spotify authorization guide has a Client Credentials flow that does not require refreshes but is also limited in what type of data it can access. Spotify授权指南客户端凭据流不需要刷新,但可以访问的数据类型也受到限制。

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

相关问题 访问令牌过期时如何在带有 keycloak 的 Nuxt auth 模块(oauth2)中使用刷新令牌 - How to use refresh token in Nuxt auth module (oauth2) with keycloak when access token expired 用户登录并在Google OAuth2中同意后,如何获取访问令牌和刷新令牌? - How to get access token and refresh token after user login and consent in Google OAuth2? 如何在页面刷新时发送OAuth2访问令牌? - How to send OAuth2 access token on page refresh? 如何使用Google OAuth2 javascript获取刷新令牌? - How to get a refresh Token with Google OAuth2 javascript? 请求令牌时 Spotify API OAUTH2 服务器错误响应 - Spotify API OAUTH2 Server Error Response when requesting token 如何使用刷新令牌刷新 discord Oauth2 访问令牌? - How do I refresh discord Oauth2 access token using refresh token? 使用 google oauth2 节点库,无法使用刷新令牌获取新的访问令牌 - Using google oauth2 node library, can't get new access token with refresh token Passport.js / Google OAuth2 策略 - 如何在登录时使用令牌进行 API 访问 - Passport.js / Google OAuth2 strategy - How to use token on login for API access 如何获取访问令牌Spotify API? - How can I get an access token Spotify API? Nodejs - Spotify API 刷新令牌 - Nodejs - Spotify API Refresh Token
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM