在使用Identity Framework的.net项目中,我不能续订令牌,即使我可以生成一个令牌。例外情况如下:
[ArgumentNullException: Value cannot be null.
Parameter name: token]
Microsoft.Owin.Security.Infrastructure.AuthenticationTokenReceiveContext..ctor(IOwinContext context, ISecureDataFormat`1 secureDataFormat, String token) +136
Microsoft.Owin.Security.OAuth.<InvokeTokenEndpointRefreshTokenGrantAsync>d__44.MoveNext() +158
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) +25
Microsoft.Owin.Security.OAuth.<InvokeTokenEndpointAsync>d__1e.MoveNext() +2159由于此异常,调试器甚至不会进入令牌刷新函数:
public async Task ReceiveAsync(AuthenticationTokenReceiveContext context)
{
var allowedOrigin = context.OwinContext.Get<string>("as:clientAllowedOrigin");
context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { allowedOrigin });
string hashedTokenId = Helper.GetHash(context.Token);
using (AuthRepository _repo = new AuthRepository())
{
var refreshToken = await _repo.FindRefreshToken(hashedTokenId);
if (refreshToken != null )
{
//Get protectedTicket from refreshToken class
context.DeserializeTicket(refreshToken.ProtectedTicket);
var result = await _repo.RemoveRefreshToken(hashedTokenId);
}
}
}我正在使用Postman进行调试,发布的请求包含正确的令牌,这在请求正文中没有检测到,在请求头部中也没有检测到。
Katana开发团队已经将其标记为错误:http://katanaproject.codeplex.com/workitem/480,但也声明不会有更新。
相同的代码库在远程服务器上运行:http://ngauthenticationweb.azurewebsites.net/
完整的项目可以在以下位置重现:https://github.com/tjoudeh/AngularJSAuthentication
如何在上下文中强制令牌,以防止异常?
发布于 2017-04-25 01:22:15
你能检查一下邮递员里的grant_type和client_id吗?密码应为‘grant_type’。
示例: username=abcd&password=abc@123&grant_type=password&client_id=c4b2f91dbe014b558d7fa00ca54ed33d
发布于 2021-03-17 18:42:01
您需要在postman中包含authorization标头,以便系统知道用户有权刷新令牌。
示例:

https://stackoverflow.com/questions/43283989
复制相似问题