private static void InsertClaims(IpbUserInfo userInfo, ClaimsIdentity identity, string claimsIssuer) { if (!string.IsNullOrEmpty(userInfo.Id)) { identity.AddClaim( new Claim(ClaimTypes.NameIdentifier, userInfo.Id, ClaimValueTypes.String, claimsIssuer)); } if (!string.IsNullOrEmpty(userInfo.UserName)) { identity.AddClaim(new Claim(ClaimsIdentity.DefaultNameClaimType, userInfo.UserName, ClaimValueTypes.String, claimsIssuer)); } if (!string.IsNullOrEmpty(userInfo.ProfileUrl)) { identity.AddClaim(new Claim(ClaimTypes.Webpage, userInfo.ProfileUrl, ClaimValueTypes.String, claimsIssuer)); } if (!string.IsNullOrEmpty(userInfo.AvatarUrl)) { identity.AddClaim(new Claim("avatarUrl", userInfo.AvatarUrl, ClaimValueTypes.String, claimsIssuer)); } }
private async Task <IpbUserInfo> GetUserInformationAsync(string token) { var userInformationEndpoint = Options.UserInformationEndpointUrl; var client = new HttpClient(); client.DefaultRequestHeaders.Add("Authorization", "Bearer " + token); var stringTask = client.GetStringAsync(userInformationEndpoint); string msg = null; try { msg = await stringTask; } catch (HttpRequestException e) { Logger.LogError($"Error while request user information: {e.Message}"); } var userInformation = new IpbUserInfo(msg, Logger); return(userInformation); }
private static bool GetClaims(string response, ClaimsIdentity identity, string claimsIssuer, ILogger ipbLogger) { var userInfo = new IpbUserInfo(response, ipbLogger); if (!userInfo.IsParsed) { return(false); } InsertClaims(userInfo, identity, claimsIssuer); return(true); }