How to allow multiple authentication methods in ASP.NET?

前端 未结 3 1807
甜味超标
甜味超标 2020-12-23 12:11

I\'m building a new ASP.NET MVC application (in C#) and one of the requirements is to create a new database of members. For this, we\'d need roles to manage the different ty

相关标签:
3条回答
  • 2020-12-23 12:26

    Use standard framework stuff. See http://blogs.teamb.com/craigstuntz/2009/09/09/38390/

    You can have an unlimited number of authentication methods attached to one account, the magic is in the FormsAuthentication.SetAuthCookie(userName, createPersistentCookie); statement

    0 讨论(0)
  • 2020-12-23 12:32

    In my opinion, the "real way" of doing this is to use federation with WIF (Windows Identity Foundation, formerly Geneva framework).

    The idea is that you separate authentication from authorization. The authentication is performed by a so-called STS (Security Token Service) and it manages all the possible login mechanism that you want to support. When a user has been authenticated the STS issues a token containing a set of claims and the user's identity. This token is sent to the web site (called a relying party in this lingo), and the website determines which parts of the site the user has access to based on the claims in the token. WIF supplies both membership and role providers that extract information from token.

    You can read about creating a claims aware website here.

    One of the pros of this approach is the separation of concerns between authentication and authorization. You do not need any complex membership and roleproviders in your website. Furthermore the STS can be reused to authenticate users to other applications you might have without them having to register more than once (effectively achieving single sign-on)

    The downside is that you will have to spend some time studying these concepts and coding your STS. Mind you, it is not hard to code an STS with WIF, but it is not a 100% trivial task either.

    If I have managed to tickle your interest I would recommend that you start out by reading this whitepaper.

    Kind regards,

    Klaus

    0 讨论(0)
  • 2020-12-23 12:50

    One idea we've followed is to create a custom Membership / Role / Profile provider. We customised the login / authentication methods significantly and have an additional table of logins. This table basically just contained:

    LoginID (Auto-Incremental ID, PK)
    UserID (FK)
    LoginSystemID (FK)
    ...blah blah
    

    Within the above, the LoginSystemID was a link to a foreign lookup table which helped the system to determine which authentication service to use (e.g. Standard, AD, OpenID, FacebookConnect - etc).

    The problem we ran into was that the Username field in the MembershipProvider couldn't be empty and while in our schema everyone had a UserID (it was their account name), they didn't have a Username that was unique. We had to get around this by generating a GUID and using that. This of course is hidden from the user and a DisplayName attribute from our Users table can be displayed instead.

    This was all done via FormsAuthenication (the AD checks were done via LDAP checks). However, an additional layer (a webform) was added with appropriate settings within IIS that provided a means for automatic WindowsAuthentication - we redirect to there in the instance that we feel the user is likely to be internal (based on IP address).

    0 讨论(0)
提交回复
热议问题