public override async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) { if (HttpContext.User != null) { DiscordUser = DiscordUser.FromClaimsPrincipal(HttpContext.User); if (SocketUser == null) { context.Result = new RedirectResult("/api/logout"); } DiscordUser.UserRole = (IsStaff ? UserRole.Staff : UserRole.Member); } await next(); }
protected override async Task <AuthenticationTicket> CreateTicketAsync(ClaimsIdentity identity, AuthenticationProperties properties, OAuthTokenResponse tokens) { var baseResult = await base.CreateTicketAsync(identity, properties, tokens); var result = DiscordUser.FromClaimsPrincipal(baseResult.Principal); var guild = _client.Guilds.FirstOrDefault(); await guild?.DownloadUsersAsync(); //TODO: Un-hardcode this if (guild?.GetUser(result.UserId) == null) { throw new UnauthorizedAccessException("You must be a member of the Discord C# server to log in."); } return(baseResult); }