1

在带有 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

我怎样才能强制令牌进入上下文,以防止异常?

4

2 回答 2

0

你能检查一下邮递员的grant_type和client_id吗?grant_type 应该是“密码”。

示例:username=abcd&password=abc@123&grant_type=password&client_id=c4b2f91dbe014b558d7fa00ca54ed33d

于 2017-04-24T17:22:15.397 回答
0

您需要在邮递员中包含授权标头,以便系统知道用户有权刷新令牌。

例子:

例子

于 2021-03-17T10:42:01.457 回答