Implement session-based authentication with Nancy

一个人想着一个人 提交于 2019-12-25 12:44:14

问题


This is a follow-up question to Is Forms Authentication as described in the Nancy docs susceptible to session hijacking?

I understand now how Nancy Form Authentication works and also the idea behind it, thanks to Steven Robbins' answer.

However, for my application that approach is not sufficient. It must not be possible to gain eternal access for an attacker if he manages to steal the auth cookie once. Thus, I'm currently investigating possibilities to switch to a session-based approach to authentication, so I can invalidate sessions when the user logs out and also after a fixed amount of time.

Nice thing about Nancy, such things can be customized!

My question is, does it make sense to reuse Nancy.FormsAuthentication for that purpose? One solution I have in mind is making the user identifier only temporarily valid. That way I would delete the GUID identifier from the user database when the user logs out, and create a new one everytime a user logs in.

I'm asking because the docs state:

It is also important to know that the identifier should be treated as permanent for the user that it was generated for and will be reused across requests and application sessions.

Are there any unwanted side-effects when I ignore that and make the identifier non-permanent?


回答1:


Yes and no.

If you change it each time the user logs in then you are effectively logging the user out.

You could create a Session / Identity table which allows the same user to login multiple times (assuming that the browser is different) which would allow you to manage the timeout / extending the timeout on each authentication.

That would require no changes to the Forms Auth, you would simply change the IUserMapper to authenticate against your Session / Identity table rather than the user directly.

(hope all that makes sense)



来源:https://stackoverflow.com/questions/21475731/implement-session-based-authentication-with-nancy

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