Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Single-Sign-On ASP.NET MVC

We are trying to build a cross-domain single-sign on solution using ASP.NET MVC.

Any existing solutions or tutorials available ?

like image 420
Mike Avatar asked May 09 '10 11:05

Mike


People also ask

What is SSO in MVC?

Single Sign-On (SSO) makes this process easier by using the same authentication ID and authorizing the user across multiple services. Because of SSO, as the name suggests, the user is required to sign in only once in a certain time window before the authentication token expires.

What is single sign-on in asp net?

Single Sign-On (SSO) into Multiple applications: Once the user will be logged into one of the applications, he/she will be logged into to asp.net application automatically that is no need to enter login credentials for other applications again.

How does SSO work C#?

The flow exists as follows: User logs into their school's main portal system using a student id/password provided to him/her by the school. User clicks the link to my company's product. User is automatically taken to the dashboard page as if they had just logged in through the login form on our site.


1 Answers

If you web applications are on the same server and same domain then all you need to do is insure that the Validationkey and encryption key are the same in the web config (machineKey).

In your example you will need to append the authentication ticket to the query string, to transport it back to the other domain, for example:

public void Login(string userName, string password)
{
    if(AuthenticateUser(userName,password))
    {
        Response.Redirect(String.format("{0}?{1}={2}"), 
            Request.QueryString["ReturnUrl"],
            FormsAuthentication.FormsCookieName,
            FormsAuthentication.GetAuthCookie(userName, false).Value));
    }
}

On the local application you have to enable cookieless forms authentication, and allow authenticated users to come from external applications by setting enableCrossAppRedirect.

<authentication mode="Forms">
    <forms enableCrossAppRedirect="true" cookieless="useUri" />
</authentication>

Notes:

  1. See also FormsAuthentication.RedirectFromLoginPage - http://msdn.microsoft.com/en-us/library/ka5ffkce.aspx.

  2. In my case ReturnUrl lost domain part of url :(

like image 144
AJ. Avatar answered Sep 25 '22 18:09

AJ.