这2个参数什么意思?

【Help】 2016-03-30 02:00:56
1、context.Ticket.Properties.IssuedUtc = DateTime.UtcNow;
2、context.Ticket.Properties.ExpiresUtc =ateTime.UtcNow.AddSeconds(36000);

这2个参数可能是Utc格式的时间,但是这里的2个到底什么意思呢,有什么作用,大牛帮相信解释下,这里添加也不是用来对refreshToken进行过期时间设置的,不知道具体作用。
...全文
299 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
【Help】 2016-03-31
  • 打赏
  • 举报
回复
我想知道,我这里context.Ticket.Properties.ExpiresUtc =ateTime.UtcNow.AddSeconds(1);他也并没有过期 。具体的是什么呢?
【Help】 2016-03-31
  • 打赏
  • 举报
回复
引用 8 楼 starfd 的回复:
这个应该是有最小时间间隔的吧,你拿一秒做测试是不是太短了,你设置成五分钟再试试呢
这个应该不是对refresh_token做过期时间设置的吧。
  • 打赏
  • 举报
回复
这个应该是有最小时间间隔的吧,你拿一秒做测试是不是太短了,你设置成五分钟再试试呢
【Help】 2016-03-30
  • 打赏
  • 举报
回复
引用 5 楼 shingoscar 的回复:
ExpiresUtc:Gets or sets the time at which the authentication ticket expires. IssuedUtc:Gets or sets the time at which the authentication ticket was issued. 一个过期时间,一个生效时间
我想知道,我这里context.Ticket.Properties.ExpiresUtc =ateTime.UtcNow.AddSeconds(1);他也并没有过期
Poopaye 2016-03-30
  • 打赏
  • 举报
回复
ExpiresUtc:Gets or sets the time at which the authentication ticket expires. IssuedUtc:Gets or sets the time at which the authentication ticket was issued. 一个过期时间,一个生效时间
kiss筱魔 2016-03-30
  • 打赏
  • 举报
回复
目测你这个是设置的过期时间,而标准就是按照世界时间。在10个小时token就过期了
【Help】 2016-03-30
  • 打赏
  • 举报
回复

 public override async Task CreateAsync(AuthenticationTokenCreateContext context)
        {
            var clietId = context.OwinContext.Get<string>("as:client_id");
            if (string.IsNullOrEmpty(clietId)) return;

            var refreshTokenLifeTime = context.OwinContext.Get<string>("as:clientRefreshTokenLifeTime");
            if (string.IsNullOrEmpty(refreshTokenLifeTime)) return;

            //generate access token
            RandomNumberGenerator cryptoRandomDataGenerator = new RNGCryptoServiceProvider();
            byte[] buffer = new byte[50];
            cryptoRandomDataGenerator.GetBytes(buffer);
            var refreshTokenId = Convert.ToBase64String(buffer).TrimEnd('=').Replace('+', '-').Replace('/', '_');

            var refreshToken = new RefreshToken()
            {
                Id = refreshTokenId,
                ClientId = new Guid(clietId),
                UserName = context.Ticket.Identity.Name,
                IssuedUtc = DateTime.UtcNow,
                ExpiresUtc = DateTime.UtcNow.AddSeconds(Convert.ToDouble(refreshTokenLifeTime)),
                ProtectedTicket = context.SerializeTicket()
            };

            context.Ticket.Properties.IssuedUtc = refreshToken.IssuedUtc;
            context.Ticket.Properties.ExpiresUtc = refreshToken.ExpiresUtc;

            if (await _refreshTokenService.Save(refreshToken))
            {
                context.SetToken(refreshTokenId);
            }
        
        }
完整源码
【Help】 2016-03-30
  • 打赏
  • 举报
回复
引用 1 楼 ailiku1988 的回复:
DateTime.UtcNow 是0时区的时间 DateTime.Now 是本地时区的时间 ,我们使用的是东八区的时间,所以这两个时间之间相差8个小时
这个我知道,我主要想知道一下这里放这2个参数的目的
kiss筱魔 2016-03-30
  • 打赏
  • 举报
回复
DateTime.UtcNow 是0时区的时间 DateTime.Now 是本地时区的时间 ,我们使用的是东八区的时间,所以这两个时间之间相差8个小时

62,244

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧