标题中的陈述正确吗?我基于Taiseer Joudeh所做的工作提出问题(感谢您在这个问题上的工作,顺便说一句),网址为http://bitoftech.net/2014/07/16/enable-oauth-refresh-tokens-angularjs-app -using-asp-net-web-api-2-owin /。
如果我正确理解了刷新令牌的行为,那么当访问令牌过期时,我们应该使用以下方法调用身份验证服务器的令牌端点:
'grant_type=refresh_token&refresh_token=' + token
我们将取回新的访问令牌。该请求将有一个刷新令牌作为有效负载的一部分,但是该刷新令牌不应该与我们刚刚使用的令牌相同吗?或者至少,它应该具有相同的到期时间?如果不是,则刷新寿命实际上是无限的。
这是我希望通过的frisby.js测试,但是使用针对Web Api 2的Taiseer实现,最终的期望失败了。我们得到一个新的刷新令牌,该令牌具有新的到期时间。
'use strict';
var frisby = require('frisby');
var config = require('../test-config.json');
var args = config[process.env.test || 'local'];
var host = args.host,
clientId = args.clientId,
usr = args.user1,
pwd = args.password1;
frisby.create('Try and fail to get a protected resource')
.get(host + '/api/test')
.expectStatus(401)
.expectHeaderContains('WWW-Authenticate', 'bearer')
.toss();
frisby.create('Log in and get a protected resource')
.post(host + '/token', {
grant_type: 'password',
username: usr,
password: pwd,
client_id: clientId
})
.expectJSONTypes({
access_token: String,
token_type: String,
expires_in: Number,
userName: String,
refresh_token: String,
'as:client_id': String,
'.issued': String,
'.expires': String
})
.expectJSON({
token_type: 'bearer',
userName: '[email protected]'
})
.afterJSON(function (json) {
frisby.create('and now get protected resource with attached bearer token')
.get(host + '/api/test', {
headers: { 'Authorization': 'Bearer ' + json.access_token }
})
.expectStatus(200)
.toss();
frisby.create('and try to get a new access token with our refresh token')
.post(host + '/token', {
grant_type: 'refresh_token',
refresh_token: json.refresh_token,
client_id: clientId
})
.afterJSON(function (json2) {
//we should receive a new access token
expect(json.access_token).not.toEqual(json2.access_token);
//but shouldn't the refresh token remain the same until *it* expires?
expect(json.refresh_token).toEqual(json2.refresh_token);
})
.toss();
})
.toss();
您是100%正确的,当前刷新令牌的实现对于刷新令牌有滑动的到期时间,因为每次使用Grant_type = refresh_token时,我们都会发布新的访问令牌和刷新令牌标识符,这对于我的情况而言是完美的,因为我希望用户只要他正在使用该应用程序就可以永久登录,如果他不使用该应用程序的时间超过刷新令牌的到期日期,那么当他尝试使用刷新获取新的访问令牌时,他将收到401令牌。
要更改此行为,您只需要发布单个刷新令牌标识符,并在用户使用刷新令牌请求新的访问令牌时返回相同的标识符。您也可以通过使用此方法和此方法自定义业务逻辑来做到这一点。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句