public async Task GetProfileDataAsync(ProfileDataRequestContext context) { if (context.Caller == IdentityServerConstants.ProfileDataCallers.UserInfoEndpoint) { var accessToken = _protector.Unprotect(context.Subject.FindFirstValue("discord")); var user = await _discord.GetUserAsync(accessToken); var userGuilds = await _discord.GetUserGuildsAsync(accessToken); var mutualGuilds = userGuilds.Where(userGuild => _bot.GetGuildAsync(ulong.Parse(userGuild.Id, CultureInfo.InvariantCulture)).Result != null); var mutualGuildsMap = new Dictionary <string, string>(); foreach (var guild in mutualGuilds) { mutualGuildsMap.Add(guild.Name, $"{guild.Id}:{guild.Permissions}:{guild.Owner}:{guild.Icon}"); } var serializerOptions = new JsonSerializerOptions() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase, IgnoreNullValues = true }; context.IssuedClaims.Add(new Claim("user", JsonSerializer.Serialize(user, serializerOptions), "json")); context.IssuedClaims.Add(new Claim("user_guilds", JsonSerializer.Serialize(mutualGuildsMap, serializerOptions), "json")); } else if (context.Caller == IdentityServerConstants.ProfileDataCallers.ClaimsProviderAccessToken) { var accessToken = context.Subject.FindFirstValue("discord"); context.IssuedClaims.Add(new Claim("discord", _protector.Protect(accessToken))); } }
public async Task <ActionResult <IEnumerable <DiscordApiGuild> > > GetMyGuildsAsync() { var userGuilds = await _discord.GetUserGuildsAsync(_protector.Unprotect(User.FindFirstValue("discord"))); return(userGuilds.Where(userGuild => _bot.GetGuildAsync(ulong.Parse(userGuild.Id, CultureInfo.InvariantCulture)).Result != null).ToList()); }