Extending CookieAuthenticationProvider OnValidateIdentity

独自空忆成欢 提交于 2019-12-24 03:46:20

问题


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

来源:https://stackoverflow.com/questions/25780551/extending-cookieauthenticationprovider-onvalidateidentity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!