We are trying to build a cross-domain single-sign on solution using ASP.NET MVC.
Any existing solutions or tutorials available ?
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.
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.
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.
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:
See also FormsAuthentication.RedirectFromLoginPage - http://msdn.microsoft.com/en-us/library/ka5ffkce.aspx.
In my case ReturnUrl lost domain part of url :(
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With