CookieAuthenticationProvider OnValidateIdentity Extension

im trying to log out of my users when they are installed or denied. my approver had to extend CookieAuthenticationOptins in Startup.Auth.vb. According to many examples, I found that my Privider looks like this

app.UseCookieAuthentication(New CookieAuthenticationOptions() With { .AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, .LoginPath = New PathString("/Account/Login"), .Provider = New CookieAuthenticationProvider() With { _ .OnValidateIdentity = Function(ctx) Dim ret = Task.Run(Function() Dim userManager As UserManager(Of ApplicationUser) = New UserManager(Of ApplicationUser)(New UserStore(Of ApplicationUser)(New DatabaseContext())) Dim currentUser = userManager.FindById(ctx.Identity.GetUserId()) If Not IsNothing(currentUser) Then If currentUser.isBanned Or currentUser.isDeleted Then ctx.RejectIdentity() End If End If Return Task.FromResult(0) End Function) Return ret End Function }}) 

Unfortunately, this leads to endless page loading without errors.

EDIT: I added Return Task.FromResult (0), but my user is still registered

+2
source share

Source: https://habr.com/ru/post/1234137/


All Articles