4、刷新令牌

https://docs.open.alipay.com/289/105656

3、access_token

有效期:
access_token取决于授权时指定的scope的有效期,如果授权时指定多个scope,最终的access_token的有效期取决于有效期最短的scope。
       access_token截止时间=(授权时间点)+(授权后调用alipay.system.oauth.token返回的expires_in)

令牌存储要求:

  • 确保access_token的安全保存;
  • 根据appId+uid+单个scope为索引保存access_token,否则会因为appid令牌混用和不同scope的令牌相互覆盖导致接口调用报错,若前后多次授权范围相同,仅保存授权截止时间最长的access_token即可。授权截止时间=授权时间点+alipay.system.oauth.token返回的expires_in。

注意:用户可以取消授权,取消后access_token即使在有效期也无法使用

4、刷新令牌

说明:
用auth_code调用alipay.system.oauth.token接口获取access_token时会返回一个refresh_token(刷新令牌),在refresh_token有效期内可以通过refresh_token同样调用alipay.system.oauth.token刷新一个新的access_token

有效期:
refresh_token取决于授权时指定的scope的有效期,如果授权时指定多个scope,最终的refresh_token的有效期取决于有效期最短的scope。
refresh_token截止时间=(调用alipay.system.oauth.token的时间+alipay.system.oauth.token返回的re_expires_in)

使用:
使用refresh_token调用alipay.system.oauth.token
刷新后可以得到一个新的access_token,access_token截止时间重新计算(对应可以看到expires_in不会变),原来的accesss_token会立即失效;同时会得到一个新的refresh_token,原来的refresh_token会失效,新refresh_token截止时间不会重新计算(对应可以看到re_expires_in会减少)

注意:用户可以取消授权,取消后refresh_token即使在有效期也无法使用

https://tools.ietf.org/html/rfc6749#section-1.4

 

https://tools.ietf.org/html/rfc6749#section-7

 https://stackoverflow.com/questions/38986005/what-is-the-purpose-of-a-refresh-token

https://docs.open.alipay.com/api_9/alipay.system.oauth.token

https://developers.weixin.qq.com/doc/offiaccount/Basic_Information/Get_access_token.html

原文地址:https://www.cnblogs.com/rsapaper/p/12103561.html