Windows authentication - programmatically sign user out? - c#

If I have an Asp.NET Core 2.1 Website set up using Windows Authentication how do I sign a user out who has signed in using Windows Authentication?
I saw this post but it was asked in 2009. Just wondering if signing out a windows user is now possible.

Short Answer: No.
You would need to use Forms Authentication. The Windows Authetication flow has not changed since that question was posted.
If you do not want to move to Form Authentication you could create your own form of "Logging Out" by mananging a logged on bool in the database for that user and then returning 401 Unauthorized. I strongly advise not doing that and you should implement Forms Authentication.

This still stands true:
No server-side logout button will work when using "Windows"
authentication. You must use "Forms" authentication if you want a
logout button, or close the user's browser.
Thus you would need to use a different form of authentication if you want to be able to logout the user

Related

ASP.NET MVC mixed mode authentication

I'm using Visual Studio 2015 with MVC 5 and need to enable both Windows and Forms Authentication for the same app. I read that one approach is to have two apps: one has Windows Auth enabled; the other has Forms Auth (main app that contains all the pages).
If the user is authenticated via the Windows Auth site, their credentials are passed to the Forms Auth site; otherwise, they'll have to enter their credentials.
I've been searching for a way to do this. Would the Windows Auth app somehow send the person's username only to the Forms Auth app, which would then assume if a name is provided the user is authenticated?
How would you do this? Thanks.
The solution I found, which is quite effective, is to use the OWIN Mixed-Auth library by Mohammad Younes. This will allow your users to log on via either Windows or Forms auth. In addition, for Windows, you can customize it so it passes through seamlessly -- the users don't have to provide their credentials; the app fetches that from their system.
I suggest you download a sample from the link above and get it working; then apply the changes to your app.

Authorise Windows Users without any authentication ASP.net MVC

I've just built my 1st asp.net mvc application and deployed it in remote IIS.I don't want to have any login option for the application but would like to authorise users based on their user-ids(eg:domainname\username) without any login.I tried using authorize attribute but it is working only when windows authentication type is enabled and is asking for windows login(windows login popsup) whenever the application is opened and doesnot work even after giving the login credentials.
Can someone please assist me on how to implement it without any authentication?
Please let me know if you would like me to add any other details.

.NET MVC Authentication - Forms + Windows Authentication

I am currently working on a project that has a requirement that is causing me some issues and I want to know the best way of handling it.
Essentially we would like internal users to be able to access the MVC application and be authenticated through AD, this we want to be pretty much like SSO, they sign on to their computer navigate to the site and they are in.
The second type of users are outside partners that do not exist in our AD and we want to manage through our SQL Server. For these users we want to display a login page and do forms authentication.
My thoughts at first were simple, let IIS try and authenticate with windows authentication and if it fails (401) redirect to a login page. I don't currently have an environment to test this in but from my understanding in IIS7 it is not that simple and requires a little bit of a "hack" to accomplish. I need to avoid anything like that I need a solution that works as the system was designed to work and not by tricking it.
I have looked into ADFS and WIF but ADFS only supports AD not SQL and from what I've seen there is no STS that supports SQL Server. I have contemplated hosting both an internal application that used windows authentication and external application that used forms authentication but I want to avoid this if possible.
Ideally the flow that we want is user navigates to the MVC application IIS tries to do windows authentication, if it fails (401) redirect them to the login page. From there the login page will authenticate the user credentials against the SQL Database. What is the best way of accomplishing this all within 1 MVC application?
Thank you!
I would just implement my own authentication on top of FormsAuthentication or OWIN if you are using ASP.NET MVC 5. It is really simple and you will have full control over where you go to authenticate users. Trust me it isn't as scary as it sounds. I've written a few posts about it that you might find interesting.
MVC 5
http://www.khalidabuhakmeh.com/asp-net-mvc-5-authentication-breakdown-part-deux
MVC 4
http://tech.pro/tutorial/1216/implementing-custom-authentication-for-aspnet
I currently use the MVC 4 method to authenticate against an Active Directory domain with great success. The only thing I would recommend is you Cache your calls to Active Directory as it can be unreliable at times.
There is the STS that supports sql server, it is the IdentityServer.
https://github.com/thinktecture/Thinktecture.IdentityServer.v2
It even supports custom membership providers which give you quite a lot of different possibilities. I am not sure however if it supports automatic fallback to forms when integrated authentication fails. If not, there are two options: a custom sts or two explicit stses and an explicit choice for users. We have implemented the latter scenario once with ADFS - there were two adfses, one with Forms, the other one with integrated auth, first one federated with the other. This gives an explicit choice on the home realm discovery page - ".would you like to log in with username/password or try the integrated authentication"
You could create a project that uses "On-Premises Authentication" which uses ADFS to authenticate users. The on-premises authority URI will be:
https://yourADFSservername/federationmetadata/2007-06/federationmetadata.xml
After your project is loaded, you can to goto your ADFS settings and create a new "Relying Party Trust" and pass on HTTPS URL that your MVC app will be using. Setup to used LDAP attributes as claims and that will sort out AD authentication easily as it will navigate users to organisational sign-in page just like Office 365. Then if authentication fails for certain users, take the user to send the user to normal sign-in/signup page that exists independently of AD and connected to SQL server. You could skip windows authentication altogether by using on-premises authentication.

Get Windows user credentials with windows authorization disabled in IIS

Is it possible to grab a users windows credentials (i.e. username) without having windows authentication enabled in IIS? With windows auth disabled the code below returns either NT AUTHORITY or IIS APPPOOL\ASP.NET v4.0 depending on if impersonation and anonymous authentication are enabled or not.
System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString();
I am converting an asp.net web application that is using forms authentication to custom authentication. Basically if a user is connecting from outside the network I force a credential check whereas if they are connecting from within the network I would like to be able to just grab their windows username. The internal portion works when I turn on windows authentication but I get the popup login box when testing outside of the network. I either need to disable windows authentication for non local connections or figure out how to get the windows username with windows authentication disabled. Any suggestions? (The other alternative i thought of was splitting the application in two and having separate authentication modes for each but I'd like to avoid this).
-I have also tried:
System.Web.HttpContext.Current.User.Identity.ToString();
System.Threading.Thread.CurrentPrincipal.ToString();
something like this is actually (kind of) possible using Active Directory Federated Services. In the event of a windows user from inside the network they can be configured to use their account details. For external users, they can be redirected to a page that will require them to log in.
However. This is very heavy-duty and an extreme pain in the..neck to implement and is really only applicable to enterprise solutions that have the resourses to use this kind of solution. Otherwise, I'd say go with the 2 site approach.
Simple answer is no.
Best solution is to create 2 sites. One for internal users that user windows authentication, one for external user that user forms authentication but authenticate against AD. You can make users always go to external site by default and then redirect based on their IP. That is redirect intranet users to internal user.

How to call windows authentication programmatically in sharepoint?

Here is my scenario.
When anonymous user visits site collection's default site, custom login form panel is shown. This form is a webUserControl(.ascx file) that is embeded into page as webpart.
Then user enters username and password.
When submit button has been clicked, authentication will be handled by code behind of custom login form panel.
Here is my question. How can I call SharePoint's authentication method with the username and password that is entered by user. Simply, I want users to login through my custom login form panel instead of windows authentication window.
The only way to do this is to have you SharePoint site use Forms Based Authentication. There is an LDAP Membership provider you can use that will authenticate against an LDAP store. Usually that is Active Directory (which is what windows authentication uses to authenticate.). There are other LDAP stores you could use too.
The only way to have a custom login form/web part is to use FBA with a custom membership provider.
Considering that you don't want to use the FBA, and want to stick to Windows authentication then your only option is to use LDAP, that will allow you to carry on with the Login Logic of WebPart and with the Windows Authentication.
Refer these links
Link 1
Link 2

Categories