按照教程
Create a RESTful API with authentication using Web API and Jwt我无法编译CustomJwtFormat类:
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(); } } }
我得到的构建错误是:
Cannot convert from
‘Thinktecture.IdentityModel.Tokens.HmacSigningCredentials’ to
‘Microsoft.IdentityModel.Tokens.SigningCredentials’
搜索到这个后,我发现了这个帖子:
ASP.NET v5 Multiple SigningCredentials
我在答案帖子中尝试过这个建议,但无济于事.我按照链接:
Ambiguous reference issue (Microsoft.AspNet.Identity & Microsoft.AspNet.Identity.Core)
但我仍然看到了冲突.我应该使用哪个包和命名空间组合?
解决方法
原文地址:https://www.jb51.cc/aspnet/248088.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。