/// <summary> /// Finds the user by subject identifier. /// </summary> /// <param name="subjectId">The subject identifier.</param> /// <returns></returns> public Customer FindBySubjectId(string subjectId) { Customer customer = null; Clients cl = _context.Clients.FirstOrDefault(c => c.Id.ToString() == subjectId); if (cl != null) { ClientsPublic pub = _context.ClientsPublic.FirstOrDefault(c => c.ClientsId == cl.Id); customer = ConstructCustomer(cl, pub); } return(customer); }
/// <summary> /// Finds the user by username. /// </summary> /// <param name="username">The username.</param> /// <returns></returns> public Customer FindByUsername(string username) { // // actually will find by mail // Customer customer = null; ClientsPublic pub = _context.ClientsPublic.FirstOrDefault(c => c.Email == username); if (pub != null) { Clients cl = _context.Clients.FirstOrDefault(c => c.Id == pub.ClientsId); customer = ConstructCustomer(cl, pub); } return(customer); }
private Customer ConstructCustomer(Clients cl, ClientsPublic pub) { var customer = new Customer(); customer.SubjectId = cl.Id.ToString(); customer.Username = cl.Fname; customer.IsActive = true; customer.PwdHash = pub.PwdHash; customer.Claims = new Claim[] { new Claim(JwtClaimTypes.Name, string.Format("{0} {1}", cl.Fname, cl.Lname)), new Claim(JwtClaimTypes.GivenName, cl.Fname), new Claim(JwtClaimTypes.FamilyName, cl.Lname ?? "null"), new Claim(JwtClaimTypes.Email, pub.Email), new Claim(JwtClaimTypes.EmailVerified, pub.IsEmailVerified?"1":"0", ClaimValueTypes.Boolean), //new Claim(JwtClaimTypes.WebSite, "http://alice.com"), //new Claim(JwtClaimTypes.Address, @"{ 'street_address': 'One Hacker Way', 'locality': 'Heidelberg', 'postal_code': 69118, 'country': 'Germany' }", IdentityServer4.IdentityServerConstants.ClaimValueTypes.Json) }; return(customer); }