gpt4 book ai didi

oauth - 获取新访问 token 时不应替换 oauth2 中的刷新 token

转载 作者:行者123 更新时间:2023-12-04 15:10:57 24 4
gpt4 key购买 nike

标题中的说法正确吗?我的问题基于 Taiseer Joudeh 在 http://bitoftech.net/2014/07/16/enable-oauth-refresh-tokens-angularjs-app-using-asp-net-web-api-2-owin/ 上所做的工作(感谢您在这个主题上的工作,顺便说一句) .

如果我正确理解刷新 token 的行为,当访问 token 过期时,我们应该使用类似的东西调用我们的身份验证服务器的 token 端点

'grant_type=refresh_token&refresh_token=' + token

我们将取回一个新的访问 token 。该请求将有一个刷新 token 作为有效负载的一部分,但该刷新 token 不应该与我们刚刚使用的相同吗?或者至少,它应该有相同的到期时间?如果不是,那么真的,刷新生命周期是无限的。

以下是我希望通过的 frisby.js 测试,但使用 Taiser 的 Web Api 2 实现,最终预期失败。我们得到一个新的刷新 token ,该 token 具有新的到期时间。
'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: 'test2@test.com'
})
.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% 正确的,刷新 token 的当前实现有刷新 token 的滑动到期,因为每次使用 grant_type=refresh_token 我们都会发布新的访问 token 和刷新 token 标识符,这对我的情况来说是完美的,因为我想要用户只要他正在使用该应用程序,就永远登录,如果他没有使用该应用程序的时间大于刷新 token 的到期日期,那么当他尝试使用刷新获取新的访问 token 时,他将收到 401 token 。

要更改此行为,您只需发出单个刷新 token 标识符,并在用户使用刷新 token 请求新访问 token 时返回相同的标识符。您可以通过在此方法和此方法中自定义业务逻辑来实现此目的。

关于oauth - 获取新访问 token 时不应替换 oauth2 中的刷新 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27725304/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com