DateTime.UtcNow.ToString("o")
格式化它们以符合ISO 8601标准? { "access_token": "xxx","token_type": "bearer","expires_in": 1199,"username": "[email protected]","ID": "55ab2c33-6c44-4181-a24f-2b1ce044d981",".issued": "Thu,13 Aug 2015 23:08:11 GMT",".expires": "Thu,13 Aug 2015 23:28:11 GMT"}
该模板使用自定义OAuthAuthorizationServerProvIDer并提供一个钩子来向传出令牌添加其他属性(‘ID’和’username’是我的道具),但我没有看到任何方法来更改现有属性.
我注意到在覆盖TokenEndpoint
时,我得到一个OAuthTokenEndpointContext,它有一个带有.issued和.expired键的属性字典.但是,尝试更改这些值无效.
非常感谢提前.
解决方法 AuthenticationPropertIEs类在Microsoft.Owin.dll中的Microsoft.Owin.Security命名空间中定义.IssuedUtc属性的setter执行以下 *** 作(对于ExpiresUtc类似):
this._dictionary[".issued"] = value.Value.ToString("r",(IFormatProvIDer) CultureInfo.InvariantCulture);
如您所见,在设置IssuedUtc时,也设置了字典的.issued字段,并设置了“r” format.
您可以尝试在TokenEndPoint方法中执行以下 *** 作:
foreach (keyvaluePair<string,string> property in context.PropertIEs.Dictionary){ if (property.Key == ".issued") { context.AdditionalResponseParameters.Add(property.Key,context.PropertIEs.IssuedUtc.Value.ToString("o",(IFormatProvIDer) CultureInfo.InvariantCulture)); } else if (property.Key == ".expires") { context.AdditionalResponseParameters.Add(property.Key,context.PropertIEs.ExpiresUtc.Value.ToString("o",(IFormatProvIDer) CultureInfo.InvariantCulture)); } else { context.AdditionalResponseParameters.Add(property.Key,property.Value); }}
我希望它有所帮助.
总结以上是内存溢出为你收集整理的c# – 更改OWIN .expiration和.issued日期的DateTime格式全部内容,希望文章能够帮你解决c# – 更改OWIN .expiration和.issued日期的DateTime格式所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)