首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >令牌刷新时,AuthenticationTokenReceiveContext无法访问Owin.Security /身份框架中的令牌值

令牌刷新时,AuthenticationTokenReceiveContext无法访问Owin.Security /身份框架中的令牌值
EN

Stack Overflow用户
提问于 2017-04-08 01:31:31
回答 2查看 1.2K关注 0票数 1

在使用Identity Framework的.net项目中,我不能续订令牌,即使我可以生成一个令牌。例外情况如下:

代码语言:javascript
复制
[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

由于此异常,调试器甚至不会进入令牌刷新函数:

代码语言:javascript
复制
 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

如何在上下文中强制令牌,以防止异常?

EN

回答 2

Stack Overflow用户

发布于 2017-04-25 01:22:15

你能检查一下邮递员里的grant_type和client_id吗?密码应为‘grant_type’。

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

票数 0
EN

Stack Overflow用户

发布于 2021-03-17 18:42:01

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

示例:

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43283989

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档