public async Task <CouchbaseUser> GetUser(string authServerUrl, string name) { using (var client = new HttpClient()) { var response = await client.GetAsync(authServerUrl + "_user/" + name); if (response.StatusCode != System.Net.HttpStatusCode.OK) { string content = await response.Content.ReadAsStringAsync(); Console.WriteLine(content); return(null); } string result = await response.Content.ReadAsStringAsync(); var dtoUser = Newtonsoft.Json.JsonConvert.DeserializeObject <User> (result); // flatten DTOs into application model var user = new CouchbaseUser() { Name = dtoUser.Name }; return(user); } }
private async Task IssueCookie( CouchbaseUser user, string idp, string amr) { var name = user.Claims.Where(x => x.Type == JwtClaimTypes.Name).Select(x => x.Value).FirstOrDefault() ?? user.Username; var claims = new Claim[] { new Claim(JwtClaimTypes.Subject, user.SubjectId), new Claim(JwtClaimTypes.Name, name), new Claim(JwtClaimTypes.IdentityProvider, idp), new Claim(JwtClaimTypes.AuthenticationTime, DateTime.UtcNow.ToEpochTime().ToString()), }; var ci = new ClaimsIdentity(claims, amr, JwtClaimTypes.Name, JwtClaimTypes.Role); var cp = new ClaimsPrincipal(ci); await HttpContext.Authentication.SignInAsync(Constants.DefaultCookieAuthenticationScheme, cp); }