Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use active Directory for ASP.Net 5 (MVC6) Intranet application

I am developing an intranet application and would like to use the existing organisations Active Directory for user authentication and policy based role authorisation.

Can someone point me in the right direction? I am getting a bit confused (well actually a lot confused).

Thankyou

like image 635
cramar Avatar asked Dec 30 '15 23:12

cramar


People also ask

How use Kerberos Authentication in ASP NET?

The Kerberos stuff isn't configured via MVC, it is handled on IIS. From IIS (Authentication), make sure "Windows Authentication" is enabled (anonymous is disabled) and (select "Windows Authentication", click "Providers" (right)) "Negotiate", means [Try Kerberos and if that doesn't work, fall-back-to NTLM].

How do I use Azure AD Authentication in MVC?

How to Create an MVC App for Azure AD Authentication. Once the Visual Studio solution is created, select your project under Solution Explorer. Then, you will see the Project Properties window – if not, press the F4 key to open it. You can also install the above packages using the NuGet Package Manager UI.

How do I use Windows Authentication on a Web application?

Goto Control Panel -> Programs and Features -> select Turn Windows Features On or Off from the Left cornor. Select Internet Information Services -> World Wide Web select all the types from it. then click Ok. once it is applied please restart your Computer to make sure IIS has been installed in your Computer.


1 Answers

Per Authentication and Autorization resources under http://docs.asp.net/en/latest/security/index.html

First start a new ASP.Net Web Application project, Pick the Web Application template then on the right pane press the "Change Authentication" button and pick "Windows Authentication".

You can now use [Authorize] on a class or method to check basic authentication vs active directory as of RC2 you can simply use the group names ala [Authorize(Roles=@"DOMAIN\GROUP")]

The now obsolete and cumbersome alternative (still works):

If you look at User.Claims you can see the groupsid keys exist for each of the user's groups. Building off that you can do something like [Authorize(Policy="FOOBAR")] and define it in your Startup.ConfigureServices method via

        services.AddAuthorization(
            o => o.AddPolicy(
                "FOOBAR",
                p => p.RequireClaim("http://schemas.microsoft.com/ws/2008/06/identity/claims/groupsid",
                    "ENTER GROUP SID")
                ));

Note that the second param to RequireClaim is a string array to allow for multiple groups.

Also note to figure out group ids via this command line magic dsquery group -name “ENTER GROUP NAME” | dsget group -sid

like image 191
Rick Avatar answered Nov 15 '22 08:11

Rick