asp.net-web-api – 无法从’Microsoft.IdentityModel.Tokens.Sy
发布时间:2020-12-16 04:22:41 所属栏目:asp.Net 来源:网络整理
导读:按照教程 Create a RESTful API with authentication using Web API and Jwt我无法编译CustomJwtFormat类: using System.IdentityModel.Tokens;using Microsoft.Owin.Security;using Microsoft.Owin.Security.DataHandler.Encoder;using Thinktecture.Ident
按照教程
Create a RESTful API with authentication using Web API and Jwt我无法编译CustomJwtFormat类: using System.IdentityModel.Tokens; using Microsoft.Owin.Security; using Microsoft.Owin.Security.DataHandler.Encoder; using Thinktecture.IdentityModel.Tokens; namespace BooksAPI.Identity { public class CustomJwtFormat : ISecureDataFormat<AuthenticationTicket> { private static readonly byte[] _secret = TextEncodings.Base64Url.Decode(ConfigurationManager.AppSettings["secret"]); private readonly string _issuer; public CustomJwtFormat(string issuer) { _issuer = issuer; } public string Protect(AuthenticationTicket data) { if (data == null) throw new ArgumentNullException(nameof(data)); var signingKey = new HmacSigningCredentials(_secret); var issued = data.Properties.IssuedUtc; var expires = data.Properties.ExpiresUtc; return new JwtSecurityTokenHandler().WriteToken( new JwtSecurityToken( _issuer,null,data.Identity.Claims,issued.Value.UtcDateTime,expires.Value.UtcDateTime,signingKey)); } public AuthenticationTicket Unprotect(string protectedText) { throw new NotImplementedException(); } } } 我得到的构建错误是:
搜索到这个后,我发现了这个帖子: ASP.NET v5 Multiple SigningCredentials 我在答案帖子中尝试过这个建议,但无济于事.我按照链接: Ambiguous reference issue (Microsoft.AspNet.Identity & Microsoft.AspNet.Identity.Core) 但我仍然看到了冲突.我应该使用哪个包和命名空间组合? 解决方法
我遇到了同样的问题.
您必须使用较旧版本的System.IdentityModel.Tokens.Jwt. 打开nuget包管理器控制台并运行: Install-Package System.IdentityModel.Tokens.Jwt -Version 4.0.2.206221351 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- ASP.Net – App_Data&App_Code文件夹?
- asp.net核心中的Request.CreateResponse
- .NET Core采用的全新配置系统[2]: 配置模型设计详解
- asp.net – 单元测试操作过滤器 – 如何模拟ViewResult
- .net – 什么是会话和会话变量?
- asp.net-core – app.UseErrorHandler()可以访问错误详细信
- asp.net-mvc-4 – 使用基本HTTP身份验证的MVC4 app WebApi中
- asp.net – 获取隐藏字段的值
- asp.net – 基于用户更改主题/ CSS
- asp.net – 如果在Application_Start中抛出未处理的异常会发