Extending CookieAuthenticationProvider OnValidateI

2019-07-16 01:23发布

im trying to logout my users when they are dasabled or banned. my approarch was to extend CookieAuthenticationOptins in Startup.Auth.vb. According to many examples i found 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 results in an endless loading of the page without an error.

EDIT: i added Return Task.FromResult(0), but my user is still logged in

0条回答
登录 后发表回答