During the training, Create a RESTful authenticated API using the Web API and Jwt . I had a problem compiling the CustomJwtFormat class:
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(); } } }
The build error I get is:
Unable to convert from 'Thinktecture.IdentityModel.Tokens.HmacSigningCredentials' to 'Microsoft.IdentityModel.Tokens.SigningCredentials'
Looking for this, I found this SO post:
ASP.NET v5 Multiple SigningCredentials
I tried the recommendation in the reply mail, but to no avail. I followed the link:
Ambiguous reference problem (Microsoft.AspNet.Identity and Microsoft.AspNet.Identity.Core)
But I still see the conflict. What combination of packages and namespace should I use?
source share