{"id":1544,"date":"2013-07-03T02:22:00","date_gmt":"2013-07-03T02:22:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/webdev\/2013\/07\/03\/understanding-owin-forms-authentication-in-mvc-5\/"},"modified":"2022-08-09T07:14:30","modified_gmt":"2022-08-09T14:14:30","slug":"understanding-owin-forms-authentication-in-mvc-5","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/dotnet\/understanding-owin-forms-authentication-in-mvc-5\/","title":{"rendered":"Understanding OWIN Forms authentication in MVC 5"},"content":{"rendered":"<h2>Overview<\/h2>\n<p>The new security feature design for MVC 5 is based on <a href=\"http:\/\/owin.org\/\">OWIN<\/a> authentication middleware. The benefit for it is that security feature can be shared by other components that can be hosted on OWIN. Since the <a href=\"http:\/\/www.asp.net\/aspnet\/overview\/owin-and-katana\/an-overview-of-project-katana\">Katana<\/a> team did a great effort to support the OWIN integrated pipeline in ASP.NET, it can also secure apps hosted on IIS, including ASP.NET MVC, Web API, Web Form.<\/p>\n<p>Forms authentication uses an application ticket that represents user&#8217;s identity and keeps it inside user agent&#8217;s cookie. When user first accesses a resource requiring authorization, it will redirect user to login page. After the user provides credentials, your application code will validate the user name and password and build user claims including user&#8217;s name, roles, etc. After passing claims to the Forms authentication middleware, it will convert it to an application ticket and serialize, encrypt and encode it into a ticket token. Then, send it out as a cookie. When the next time user sends request with the cookie, the middleware will validate it and convert the ticket token back to claims principal and save it in HttpContext.User, which will shared across ASP.NET pipeline.<\/p>\n<p>ASP.NET also has a forms authentication support through the <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/system.web.security.formsauthenticationmodule.aspx\">FormsAuthenticationModule<\/a>, which, however, can only support applications hosted on ASP.NET and <a>doesn&#8217;t have claim support<\/a> . Here is a rough feature comparison list:<\/p>\n<table border=\"1\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td valign=\"top\" width=\"175\">\n<p><strong>Features<\/strong><\/p>\n<\/td>\n<td valign=\"top\" width=\"224\">\n<p><strong>Asp.Net Forms Authentication <\/strong><\/p>\n<\/td>\n<td valign=\"top\" width=\"197\">\n<p><strong>OWIN Forms Authentication<\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"175\">\n<p>Cookie Authentication<\/p>\n<\/td>\n<td valign=\"top\" width=\"224\">\n<p>Yes<\/p>\n<\/td>\n<td valign=\"top\" width=\"197\">\n<p>Yes<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"175\">\n<p>Cookieless Authentication<\/p>\n<\/td>\n<td valign=\"top\" width=\"224\">\n<p>Yes<\/p>\n<\/td>\n<td valign=\"top\" width=\"197\">\n<p><span style=\"background-color: #ff0000\">No<\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"175\">\n<p>Expiration<\/p>\n<\/td>\n<td valign=\"top\" width=\"224\">\n<p>Yes<\/p>\n<\/td>\n<td valign=\"top\" width=\"197\">\n<p>Yes<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"175\">\n<p>Sliding Expiration<\/p>\n<\/td>\n<td valign=\"top\" width=\"224\">\n<p>Yes<\/p>\n<\/td>\n<td valign=\"top\" width=\"197\">\n<p>Yes<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"175\">\n<p>Token Protection<\/p>\n<\/td>\n<td valign=\"top\" width=\"224\">\n<p>Yes<\/p>\n<\/td>\n<td valign=\"top\" width=\"197\">\n<p>Yes<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"175\">\n<p>Claims Support<\/p>\n<\/td>\n<td valign=\"top\" width=\"224\">\n<p><span style=\"background-color: #ff0000\">No<\/span><\/p>\n<\/td>\n<td valign=\"top\" width=\"197\">\n<p>Yes<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"175\">\n<p>Web Farm Support<\/p>\n<\/td>\n<td valign=\"top\" width=\"224\">\n<p>Yes<\/p>\n<\/td>\n<td valign=\"top\" width=\"197\">\n<p>Yes<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"175\">\n<p>Unauthorized Redirection<\/p>\n<\/td>\n<td valign=\"top\" width=\"224\">\n<p>Yes<\/p>\n<\/td>\n<td valign=\"top\" width=\"197\">\n<p>Yes<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>In this blog, you will learn:<\/p>\n<p>&middot; <a href=\"http:\/\/blogs.msdn.com\/b\/webdev\/archive\/2013\/07\/03\/understanding-owin-forms-authentication-in-mvc-5.aspx#_Creating_MVC_project\">Creating an MVC project with OWIN Forms authentication enabled.<\/a><\/p>\n<p>&middot; <a href=\"http:\/\/blogs.msdn.com\/b\/webdev\/archive\/2013\/07\/03\/understanding-owin-forms-authentication-in-mvc-5.aspx#_Understanding_OWIN_Forms\">Understanding OWIN Forms authentication options.<\/a><\/p>\n<p>&middot; <a href=\"http:\/\/blogs.msdn.com\/b\/webdev\/archive\/2013\/07\/03\/understanding-owin-forms-authentication-in-mvc-5.aspx#_Understanding_Application_Sign\">Understanding Application Sign In Cookie flow.<\/a><\/p>\n<p>&middot; <a href=\"http:\/\/blogs.msdn.com\/b\/webdev\/archive\/2013\/07\/03\/understanding-owin-forms-authentication-in-mvc-5.aspx#_Understanding_External_Sign\">Understanding External Sign In Cookie flow.<\/a><\/p>\n<p>&middot; <a href=\"http:\/\/blogs.msdn.com\/b\/webdev\/archive\/2013\/07\/03\/understanding-owin-forms-authentication-in-mvc-5.aspx#_Working_with_new\">Working with new Identity API<\/a><\/p>\n<h3><a name=\"_Creating_MVC_project\"><\/a>Creating MVC project with OWIN Forms authentication enabled<\/h3>\n<p>To get started, you need to create new MVC .<\/p>\n<p>&middot; Make sure you have installed:<\/p>\n<ul>\n<ul>\n<li><a href=\"http:\/\/www.microsoft.com\/visualstudio\/eng\/2013-downloads\">Visual Studio 2013 Preview<\/a><\/li>\n<li><a href=\"http:\/\/go.microsoft.com\/fwlink\/?LinkID=309552\">ASP.NET and Web Tools 2013 Preview Refresh<\/a><\/li>\n<\/ul>\n<\/ul>\n<p>&middot; In Visual Studio 2013, select <strong>New Project<\/strong> from <strong>File<\/strong> menu<\/p>\n<p>&middot; In <strong>New Project<\/strong> dialog, select <strong>Installed Template <\/strong>\/ <strong>Visual C#<\/strong> \/ <strong>Web<\/strong> \/ <strong>ASP.NET Web Application<\/strong><\/p>\n<p>&middot; In <strong>New ASP.NET Project<\/strong> dialog, select <strong>MVC<\/strong> project template<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2013\/07\/1425.clip_image002_0A5A1CC7.jpg\"><img decoding=\"async\" title=\"clip_image002\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2013\/07\/1425.clip_image002_0A5A1CC7.jpg\" alt=\"clip_image002\" width=\"576\" height=\"361\" \/><\/a><\/p>\n<p><strong>Optional<\/strong>: On the right panel of the dialog, you can select <strong>Configure Authentication<\/strong>, to choose <strong>No Authentication<\/strong>, <strong>Individual User Accounts, Organization Authentication<\/strong> and <strong>Windows Authentication<\/strong>. In this tutorial, we use <strong>Individual User Accounts<\/strong>, which is the default setting.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2013\/07\/7384.clip_image004_110D264A.jpg\"><img decoding=\"async\" title=\"clip_image004\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2013\/07\/7384.clip_image004_110D264A.jpg\" alt=\"clip_image004\" width=\"624\" height=\"282\" \/><\/a><\/p>\n<p>&middot; Click <strong>Create Project<\/strong> button<\/p>\n<p>In the new project, open the <em>App_Start\/Startup.Auth.cs<\/em> file. It has the following code:<\/p>\n<div id=\"scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:4e21d11b-6de8-4fc5-8383-bf927619e29a\" class=\"wlWriterEditableSmartContent\" style=\"margin: 0px;padding: 0px;float: none\">\n<div style=\"border: #000080 1px solid;color: #000;font-family: 'Courier New', Courier, Monospace;font-size: 10pt\">\n<div style=\"background: #000080;color: #fff;font-family: Verdana, Tahoma, Arial, sans-serif;font-weight: bold;padding: 2px 5px\">Code Snippet<\/div>\n<div style=\"background: #ddd;max-height: 300px;overflow: auto\">\n<ol style=\"background: #ffffff;margin: 0 0 0 2.5em;padding: 0 0 0 5px\" start=\"1\">\n<li><span style=\"background: #ffffff;color: #0000ff\">public<\/span><span style=\"background: #ffffff;color: #0000ff\">partial<\/span><span style=\"background: #ffffff;color: #0000ff\">class<\/span><span style=\"background: #ffffff;color: #2b91af\">Startup<\/span><\/li>\n<li style=\"background: #f3f3f3\"><span style=\"background: #ffffff;color: #000000\">{<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #008000\">\/\/ For more information on configuring authentication, please visit http:\/\/go.microsoft.com\/fwlink\/?LinkId=301864<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">public<\/span><span style=\"background: #ffffff;color: #0000ff\">void<\/span><span style=\"background: #ffffff;color: #000000\"> ConfigureAuth(<\/span><span style=\"background: #ffffff;color: #2b91af\">IAppBuilder<\/span><span style=\"background: #ffffff;color: #000000\"> app)<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">{<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #008000\">\/\/ Enable the application to use a cookie to store information for the signed in user<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #008000\">\/\/ and to use a cookie to temporarily store information about a user logging in with a third party login provider<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">app.UseSignInCookies();<\/span><\/li>\n<li>&nbsp;<\/li>\n<li style=\"background: #f3f3f3\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #008000\">\/\/ Uncomment the following lines to enable logging in with third party login providers<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #008000\">\/\/app.UseMicrosoftAccountAuthentication(<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #008000\">\/\/&nbsp;&nbsp;&nbsp;&nbsp;clientId: &#8220;&#8221;,<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #008000\">\/\/&nbsp;&nbsp;&nbsp;&nbsp;clientSecret: &#8220;&#8221;);<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;<\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #008000\">\/\/app.UseTwitterAuthentication(<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #008000\">\/\/&nbsp;&nbsp;&nbsp;consumerKey: &#8220;&#8221;,<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #008000\">\/\/&nbsp;&nbsp;&nbsp;consumerSecret: &#8220;&#8221;);<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;<\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #008000\">\/\/app.UseFacebookAuthentication(<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #008000\">\/\/&nbsp;&nbsp;&nbsp;appId: &#8220;&#8221;,<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #008000\">\/\/&nbsp;&nbsp;&nbsp;appSecret: &#8220;&#8221;);<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;<\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #008000\">\/\/app.UseGoogleAuthentication();<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">}<\/span><\/li>\n<li><span style=\"background: #ffffff;color: #000000\">}<\/span><\/li>\n<\/ol>\n<\/div>\n<\/div>\n<\/div>\n<h3>&nbsp;<\/h3>\n<p><strong>Note that UseSignInCookies must be called before any external login providers.<\/strong><\/p>\n<p>&nbsp;<\/p>\n<h3><a name=\"_Understanding_OWIN_Forms\"><\/a>Understanding OWIN Forms authentication options<\/h3>\n<p>The<strong> UseSignInCookies <\/strong>extension method actually registers two cookie authentications. (You can see the source for the methods below at at: <a href=\"http:\/\/katanaproject.codeplex.com\/SourceControl\/latest#src\/Microsoft.Owin.Security.Forms\/FormsAuthenticationExtensions.cs\">http:\/\/katanaproject.codeplex.com\/SourceControl\/latest#src\/Microsoft.Owin.Security.Forms\/FormsAuthenticationExtensions.cs<\/a> )<\/p>\n<div id=\"scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:f027d39c-ccc3-4f3c-bcfe-6e604cc66208\" class=\"wlWriterEditableSmartContent\" style=\"margin: 0px;padding: 0px;float: none\">\n<div style=\"border: #000080 1px solid;color: #000;font-family: 'Courier New', Courier, Monospace;font-size: 10pt\">\n<div style=\"background: #000080;color: #fff;font-family: Verdana, Tahoma, Arial, sans-serif;font-weight: bold;padding: 2px 5px\">Code Snippet<\/div>\n<div style=\"background: #ddd;max-height: 300px;overflow: auto\">\n<ol style=\"background: #ffffff;margin: 0 0 0 2em;padding: 0 0 0 5px\" start=\"1\">\n<li><span style=\"background: #ffffff;color: #0000ff\">public<\/span><span style=\"background: #ffffff;color: #0000ff\">static<\/span><span style=\"background: #ffffff;color: #0000ff\">void<\/span><span style=\"background: #ffffff;color: #000000\"> UseSignInCookies(<\/span><span style=\"background: #ffffff;color: #0000ff\">this<\/span><span style=\"background: #ffffff;color: #2b91af\">IAppBuilder<\/span><span style=\"background: #ffffff;color: #000000\"> app)<\/span><\/li>\n<li style=\"background: #f3f3f3\"><span style=\"background: #ffffff;color: #000000\">{<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">app.UseApplicationSignInCookie();<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">app.UseExternalSignInCookie();<\/span><\/li>\n<li><span style=\"background: #ffffff;color: #000000\">}<\/span><\/li>\n<\/ol>\n<\/div>\n<\/div>\n<\/div>\n<p>Both the <strong>UseApplicationSignInCookie<\/strong> and the <strong>UseExternalSignInCookie<\/strong> extension methods call <strong>UseFormsAuthentication,<\/strong> but with different settings.<\/p>\n<div id=\"scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:d7a788b7-f7fe-4455-a74a-62ed89471061\" class=\"wlWriterEditableSmartContent\" style=\"margin: 0px;padding: 0px;float: none\">\n<div style=\"border: #000080 1px solid;color: #000;font-family: 'Courier New', Courier, Monospace;font-size: 10pt\">\n<div style=\"background: #000080;color: #fff;font-family: Verdana, Tahoma, Arial, sans-serif;font-weight: bold;padding: 2px 5px\">Code Snippet<\/div>\n<div style=\"background: #ddd;max-height: 300px;overflow: auto\">\n<ol style=\"background: #ffffff;margin: 0 0 0 2.5em;padding: 0 0 0 5px\" start=\"1\">\n<li><span style=\"background: #ffffff;color: #0000ff\">public<\/span><span style=\"background: #ffffff;color: #0000ff\">static<\/span><span style=\"background: #ffffff;color: #2b91af\">IAppBuilder<\/span><span style=\"background: #ffffff;color: #000000\"> UseApplicationSignInCookie(<\/span><span style=\"background: #ffffff;color: #0000ff\">this<\/span><span style=\"background: #ffffff;color: #2b91af\">IAppBuilder<\/span><span style=\"background: #ffffff;color: #000000\"> app)<\/span><\/li>\n<li style=\"background: #f3f3f3\"><span style=\"background: #ffffff;color: #000000\">{<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">return<\/span><span style=\"background: #ffffff;color: #000000\"> UseFormsAuthentication(app, <\/span><span style=\"background: #ffffff;color: #0000ff\">new<\/span><span style=\"background: #ffffff;color: #000000\"> FormsAuthenticationOptions<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">{<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">AuthenticationType = FormsAuthenticationDefaults.ApplicationAuthenticationType,<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">AuthenticationMode = AuthenticationMode.Active,<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">CookieName = FormsAuthenticationDefaults.CookiePrefix + FormsAuthenticationDefaults.ApplicationAuthenticationType,<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">LoginPath = FormsAuthenticationDefaults.LoginPath,<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">LogoutPath = FormsAuthenticationDefaults.LogoutPath,<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">});<\/span><\/li>\n<li><span style=\"background: #ffffff;color: #000000\">}<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;<\/li>\n<li><span style=\"background: #ffffff;color: #0000ff\">public<\/span><span style=\"background: #ffffff;color: #0000ff\">static<\/span><span style=\"background: #ffffff;color: #2b91af\">IAppBuilder<\/span><span style=\"background: #ffffff;color: #000000\"> UseExternalSignInCookie(<\/span><span style=\"background: #ffffff;color: #0000ff\">this<\/span><span style=\"background: #ffffff;color: #2b91af\">IAppBuilder<\/span><span style=\"background: #ffffff;color: #000000\"> app)<\/span><\/li>\n<li style=\"background: #f3f3f3\"><span style=\"background: #ffffff;color: #000000\">{<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">app.SetDefaultSignInAsAuthenticationType(FormsAuthenticationDefaults.ExternalAuthenticationType);<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;<\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">return<\/span><span style=\"background: #ffffff;color: #000000\"> UseFormsAuthentication(app, <\/span><span style=\"background: #ffffff;color: #0000ff\">new<\/span><span style=\"background: #ffffff;color: #000000\"> FormsAuthenticationOptions<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">{<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">AuthenticationType = FormsAuthenticationDefaults.ExternalAuthenticationType,<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">AuthenticationMode = AuthenticationMode.Passive,<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">CookieName = FormsAuthenticationDefaults.CookiePrefix + FormsAuthenticationDefaults.ExternalAuthenticationType,<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">ExpireTimeSpan = TimeSpan.FromMinutes(5),<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">});<\/span><\/li>\n<li style=\"background: #f3f3f3\"><span style=\"background: #ffffff;color: #000000\">}<\/span><\/li>\n<\/ol>\n<\/div>\n<\/div>\n<\/div>\n<p>The Application sign in cookie is used to authenticate users for the current application, while external sign in cookie is used to authenticate users from external providers, like Facebook, Google, Twitter and Microsoft account. If you want to change the default authentication options, you can use <strong>UseFormsAuthentication<\/strong> extension method to change them.<\/p>\n<p>Here are list of options that you can change in <strong>UseFormsAuthentication<\/strong>:<\/p>\n<div id=\"scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:1dbc1b84-e8ad-4dc2-9aa0-82fe81486e2c\" class=\"wlWriterEditableSmartContent\" style=\"margin: 0px;padding: 0px;float: none\">\n<div style=\"border: #000080 1px solid;color: #000;font-family: 'Courier New', Courier, Monospace;font-size: 10pt\">\n<div style=\"background: #000080;color: #fff;font-family: Verdana, Tahoma, Arial, sans-serif;font-weight: bold;padding: 2px 5px\">Code Snippet<\/div>\n<div style=\"background: #ddd;max-height: 300px;overflow: auto\">\n<ol style=\"background: #ffffff;margin: 0 0 0 2.5em;padding: 0 0 0 5px\" start=\"1\">\n<li><span style=\"background: #ffffff;color: #000000\">app.UseFormsAuthentication(<\/span><span style=\"background: #ffffff;color: #0000ff\">new<\/span><span style=\"background: #ffffff;color: #000000\"> FormsAuthenticationOptions()<\/span><\/li>\n<li style=\"background: #f3f3f3\"><span style=\"background: #ffffff;color: #000000\">{<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">AuthenticationMode = Microsoft.Owin.Security.<\/span><span style=\"background: #ffffff;color: #2b91af\">AuthenticationMode<\/span><span style=\"background: #ffffff;color: #000000\">.Active,<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">AuthenticationType = <\/span><span style=\"background: #ffffff;color: #a31515\">&#8220;MyApplication&#8221;<\/span><span style=\"background: #ffffff;color: #000000\">,<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">CookieDomain = <\/span><span style=\"background: #ffffff;color: #a31515\">&#8220;.myapp.com&#8221;<\/span><span style=\"background: #ffffff;color: #000000\">,<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">CookieHttpOnly = <\/span><span style=\"background: #ffffff;color: #0000ff\">true<\/span><span style=\"background: #ffffff;color: #000000\">,<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">CookieName = <\/span><span style=\"background: #ffffff;color: #a31515\">&#8220;.AspNet.MyApplication&#8221;<\/span><span style=\"background: #ffffff;color: #000000\">,<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">CookiePath = <\/span><span style=\"background: #ffffff;color: #a31515\">&#8220;\/Account&#8221;<\/span><span style=\"background: #ffffff;color: #000000\">,<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">CookieSecure = CookieSecureOption.Always,<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">ExpireTimeSpan = TimeSpan.FromDays(1),<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">LoginPath = <\/span><span style=\"background: #ffffff;color: #a31515\">&#8220;\/Account\/Login&#8221;<\/span><span style=\"background: #ffffff;color: #000000\">,<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">ReturnUrlParameter = <\/span><span style=\"background: #ffffff;color: #a31515\">&#8220;return_url&#8221;<\/span><span style=\"background: #ffffff;color: #000000\">,<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">SlidingExpiration = <\/span><span style=\"background: #ffffff;color: #0000ff\">true<\/span><span style=\"background: #ffffff;color: #000000\">,<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">Provider = <\/span><span style=\"background: #ffffff;color: #0000ff\">new<\/span><span style=\"background: #ffffff;color: #000000\"> FormsAuthenticationProvider()<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">{<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">OnResponseSignin = <\/span><span style=\"background: #ffffff;color: #0000ff\">async<\/span><span style=\"background: #ffffff;color: #000000\"> ctx =&gt;<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">{<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">Console.WriteLine(<\/span><span style=\"background: #ffffff;color: #a31515\">&#8220;OnResponseSignin&#8221;<\/span><span style=\"background: #ffffff;color: #000000\">);<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">PrintClaimsIdentity(ctx.Identity);<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">},<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">OnValidateIdentity = <\/span><span style=\"background: #ffffff;color: #0000ff\">async<\/span><span style=\"background: #ffffff;color: #000000\"> ctx =&gt;<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">{<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">Console.WriteLine(<\/span><span style=\"background: #ffffff;color: #a31515\">&#8220;OnValidateIdentity&#8221;<\/span><span style=\"background: #ffffff;color: #000000\">);<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">PrintClaimsIdentity(ctx.Identity);<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">}<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">}<\/span><\/li>\n<li><span style=\"background: #ffffff;color: #000000\">});<\/span><\/li>\n<\/ol>\n<\/div>\n<\/div>\n<\/div>\n<table border=\"1\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td valign=\"top\" width=\"143\">\n<p><strong>Options<\/strong><\/p>\n<\/td>\n<td valign=\"top\" width=\"600\">\n<p><strong>Description<\/strong><\/p>\n<\/td>\n<td valign=\"top\" width=\"179\">\n<p><strong>ApplicaitonSignInCookie Default Values<\/strong><\/p>\n<\/td>\n<td valign=\"top\" width=\"179\">\n<p><strong>ExternalSignInCookie Default Values<\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"143\">\n<p>AuthenticationMode<\/p>\n<\/td>\n<td valign=\"top\" width=\"600\">\n<p>If Active the authentication middleware alters the requested user coming in and returns 401 Unauthorized responses going out.<\/p>\n<p>If Passive the authentication middleware will only provide identity and alter responses when explicitly indicated by the AuthenticationType.<\/p>\n<\/td>\n<td valign=\"top\" width=\"179\">\n<p>Active<\/p>\n<\/td>\n<td valign=\"top\" width=\"179\">\n<p>Passive<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"143\">\n<p>AuthenticationType<\/p>\n<\/td>\n<td valign=\"top\" width=\"600\">\n<p>The AuthenticationType in the options corresponds to the IIdentity.AuthenticationType property. A different value may be assigned in order to use the same authentication middleware type more than once in a pipeline.<\/p>\n<\/td>\n<td valign=\"top\" width=\"179\">\n<p>&ldquo;Application&rdquo;<\/p>\n<\/td>\n<td valign=\"top\" width=\"179\">\n<p>&ldquo;External&rdquo;<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"143\">\n<p>CookieDomain<\/p>\n<\/td>\n<td valign=\"top\" width=\"600\">\n<p>Defines the domain that cookie is under<\/p>\n<\/td>\n<td valign=\"top\" width=\"179\">\n<p>&lt;null&gt;<\/p>\n<\/td>\n<td valign=\"top\" width=\"179\">\n<p>&lt;null&gt;<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"143\">\n<p>CookieHttpOnly<\/p>\n<\/td>\n<td valign=\"top\" width=\"600\">\n<p>Defines if the cookie is http only. It&#8217;s true by default.<\/p>\n<\/td>\n<td valign=\"top\" width=\"179\">\n<p>True<\/p>\n<\/td>\n<td valign=\"top\" width=\"179\">\n<p>True<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"143\">\n<p>CookieName<\/p>\n<\/td>\n<td valign=\"top\" width=\"600\">\n<p>Defines the name of the cookie<\/p>\n<\/td>\n<td valign=\"top\" width=\"179\">\n<p>&ldquo;.AspNet.Application&rdquo;<\/p>\n<\/td>\n<td valign=\"top\" width=\"179\">\n<p>&ldquo;.AspNet.External&rdquo;<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"143\">\n<p>CookiePath<\/p>\n<\/td>\n<td valign=\"top\" width=\"600\">\n<p>Defines the path that cookie is under. By default, it&#8217;s \/.<\/p>\n<\/td>\n<td valign=\"top\" width=\"179\">\n<p>&ldquo;\/&rdquo;<\/p>\n<\/td>\n<td valign=\"top\" width=\"179\">\n<p>&ldquo;\/&rdquo;<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"143\">\n<p>CookieSecure<\/p>\n<\/td>\n<td valign=\"top\" width=\"600\">\n<p>Defines if the cookie will only be sent back to HTTPS URL. By default, it is SameAsRequest, which means If the URI that provides the cookie is HTTPS, then the cookie will only be returned to the server on subsequent HTTPS requests. Otherwise if the URI that provides the cookie is HTTP, then the cookie will be returned to the server on all HTTP and HTTPS requests.<\/p>\n<\/td>\n<td valign=\"top\" width=\"179\">\n<p>SameAsRequest<\/p>\n<\/td>\n<td valign=\"top\" width=\"179\">\n<p>SameAsRequest<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"143\">\n<p>ExpireTimeSpan<\/p>\n<\/td>\n<td valign=\"top\" width=\"600\">\n<p>Defines the expiration of the cookie.<\/p>\n<\/td>\n<td valign=\"top\" width=\"179\">\n<p>14 days<\/p>\n<\/td>\n<td valign=\"top\" width=\"179\">\n<p>5 minutes<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"143\">\n<p>LoginPath<\/p>\n<\/td>\n<td valign=\"top\" width=\"600\">\n<p>Defines the Login path when unauthorized request will be redirected to.<\/p>\n<\/td>\n<td valign=\"top\" width=\"179\">\n<p>&ldquo;\/Account\/Login&rdquo;<\/p>\n<\/td>\n<td valign=\"top\" width=\"179\">\n<p>&lt;null&gt;<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"143\">\n<p>ReturnUrlParameter<\/p>\n<\/td>\n<td valign=\"top\" width=\"600\">\n<p>Defines the return URL parameter name, which tells your application the URL of previous unauthorized request to redirect to after login. Your application code is responsible for retrieving it and redirecting the user agent to the return URL<\/p>\n<\/td>\n<td valign=\"top\" width=\"179\">\n<p>&ldquo;ReturnUrl&rdquo;<\/p>\n<\/td>\n<td valign=\"top\" width=\"179\">\n<p>&lt;null&gt;<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"143\">\n<p>SlidingExpiration<\/p>\n<\/td>\n<td valign=\"top\" width=\"600\">\n<p>Defines if the authentication supports sliding expiration, which will automatically extends the expiration time if user session is still active. By default, it&#8217;s true.<\/p>\n<\/td>\n<td valign=\"top\" width=\"179\">\n<p>True<\/p>\n<\/td>\n<td valign=\"top\" width=\"179\">\n<p>False<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"143\">\n<p>Provider<\/p>\n<\/td>\n<td valign=\"top\" width=\"600\">\n<p>The forms authentication provider that can intercept events during sign in and validate identity.<\/p>\n<p>&middot; OnResponseSignin: happens just before set-cookie is sent out<\/p>\n<p>&middot; OnValidateIdentity: happens just after incoming cookie is parsed into ClaimsIdentity<\/p>\n<\/td>\n<td valign=\"top\" width=\"179\">\n<p>&lt;null&gt;<\/p>\n<\/td>\n<td valign=\"top\" width=\"179\">\n<p>&lt;null&gt;<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3><a name=\"_Understanding_Application_Sign\"><\/a>Understanding Application Sign in Cookie flow<\/h3>\n<p>Active mode is similar to what the old ASP.NET forms authentication module did, while passive is a way to let framework code control the authentication explicitly.<\/p>\n<p>ApplicatinSignInCookie is an active forms authentication middleware, so when a valid cookie is returned, it will:<\/p>\n<p>&middot; Automatically redirect an unauthorized response to the login page.<\/p>\n<p>&middot; Set the logged in user principal to HttpContext.User, so the rest of ASP.NET pipeline will know what user is authenticated.<\/p>\n<p>&nbsp;<\/p>\n<p>The following is a basic flow of application forms authentication.<\/p>\n<table border=\"1\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td valign=\"top\" width=\"185\">\n<p><strong>User Agent<\/strong><\/p>\n<\/td>\n<td valign=\"top\" width=\"228\">\n<p><strong>Forms Authentication Middleware(Application)<\/strong><\/p>\n<\/td>\n<td valign=\"top\" width=\"209\">\n<p><strong>Web App<\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"185\">\n<p><strong>1. <\/strong><strong>Get \/Account\/Manage<\/strong><\/p>\n<p><strong>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-&gt;<\/strong><\/p>\n<\/td>\n<td valign=\"top\" width=\"228\">&nbsp;<\/td>\n<td valign=\"top\" width=\"209\">&nbsp;<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"185\">&nbsp;<\/td>\n<td valign=\"top\" width=\"228\">&nbsp;<\/td>\n<td valign=\"top\" width=\"209\">\n<p><strong>2. <\/strong><strong>Response Status: 401<\/strong><\/p>\n<p>AccountController is protected by Authroize attribute, so unauthorized request will return a 401 error.<\/p>\n<p>[Authorize]<\/p>\n<p>public class AccountController : Controller<\/p>\n<p>{<\/p>\n<p>}<\/p>\n<p><strong>&lt;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"185\">&nbsp;<\/td>\n<td valign=\"top\" width=\"228\">\n<p><strong>3. <\/strong><strong>Alter response status to 302 and redirect to \/Application\/Login?ReturnUrl=\/Account\/Manage<\/strong><\/p>\n<p>The application sign in cookie is in active authentication mode and it will automatically redirect to login page when there is a 401 response.<\/p>\n<p><strong>&lt;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<\/strong><\/p>\n<\/td>\n<td valign=\"top\" width=\"209\">&nbsp;<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"185\">\n<p><strong>4. <\/strong><strong>GET \/Application\/Login?ReturnUrl=\/Account\/Manage<\/strong><\/p>\n<p><strong>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-&gt;<\/strong><\/p>\n<\/td>\n<td valign=\"top\" width=\"228\">&nbsp;<\/td>\n<td valign=\"top\" width=\"209\">&nbsp;<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"185\">&nbsp;<\/td>\n<td valign=\"top\" width=\"228\">&nbsp;<\/td>\n<td valign=\"top\" width=\"209\">\n<p><strong>5. <\/strong><strong>Response Status: 200 and with login page in body<\/strong><\/p>\n<p><strong>&lt;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"185\">\n<p><strong>6. <\/strong><strong>POST \/Application\/Login?ReturnUrl=\/Account\/Manage<\/strong><\/p>\n<p>User input user name and password and post back to server<\/p>\n<p><strong>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-&gt;<\/strong><\/p>\n<\/td>\n<td valign=\"top\" width=\"228\">&nbsp;<\/td>\n<td valign=\"top\" width=\"209\">&nbsp;<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"185\">&nbsp;<\/td>\n<td valign=\"top\" width=\"228\">&nbsp;<\/td>\n<td valign=\"top\" width=\"209\">\n<p><strong>7. <\/strong><strong>Status: 301<\/strong><\/p>\n<p><strong>Location: \/Account\/Manage<\/strong><\/p>\n<p>Server code does:<\/p>\n<p>a. Validating user credentials<\/p>\n<p>b. Calling IdentityAuthenticationManager.SignIn to sign in with application sign in cookie<\/p>\n<p>c. Redirecting to returnUrl<\/p>\n<p><strong>&lt;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"185\">&nbsp;<\/td>\n<td valign=\"top\" width=\"228\">\n<p><strong>8. <\/strong><strong>Status: 302<\/strong><\/p>\n<p><strong>Location: \/Account\/Manage<\/strong><\/p>\n<p><strong>Set-Cookie: .AspNet.Application=&lt;Ticket Token&gt;<\/strong><\/p>\n<p>The middleware will convert user claims with extra data into ticket token and set it in cookie.<\/p>\n<p><strong>&lt;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<\/strong><\/p>\n<\/td>\n<td valign=\"top\" width=\"209\">&nbsp;<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"185\">\n<p><strong>9. <\/strong><strong>GET \/Account\/Manage<\/strong><\/p>\n<p><strong>Cookie: .AspNet.Application=&lt;Ticket Token&gt;<\/strong><\/p>\n<p><strong>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-&gt;<\/strong><\/p>\n<\/td>\n<td valign=\"top\" width=\"228\">&nbsp;<\/td>\n<td valign=\"top\" width=\"209\">&nbsp;<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"185\">&nbsp;<\/td>\n<td valign=\"top\" width=\"228\">\n<p>10. Validate &lt;Ticket Token&gt; and convert it to claims identity and set it to HttpContext.User<\/p>\n<p><strong>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-&gt;<\/strong><\/p>\n<\/td>\n<td valign=\"top\" width=\"209\">&nbsp;<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"185\">&nbsp;<\/td>\n<td valign=\"top\" width=\"228\">&nbsp;<\/td>\n<td valign=\"top\" width=\"209\">\n<p><strong>11. <\/strong><strong>Status: 200 with manage account page in body<\/strong><\/p>\n<p>Authorize attribute sees that the identity is authenticated from HttpContext.User. So allow the request to reach the action.<\/p>\n<p><strong>&lt;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<\/strong><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3><a name=\"_Understanding_External_Sign\"><\/a>Understanding External Sign in Cookie flow<\/h3>\n<p>ExternalSignInCookie is a passive forms authentication, which is unobtrusive to your application if you don&#8217;t explicitly ask it to do something. Your application code can explicitly ask it to provide the user identity or alter the response to set cookie or remove cookie. To demo external sign in cookie, you need to configure an external provider like Facebook. This flow chart starts from the point Facebook authentication middleware receives the user info from Facebook graph API. For the detailed flow for external provider sign in process, please check out Robert&rsquo;s tutorial: <a href=\"http:\/\/www.asp.net\/web-api\/overview\/security\/external-authentication-services\">External Authentication Services<\/a><\/p>\n<div style=\"background: #ffffff\">\n<div style=\"background: #ffffff;overflow: scroll\">\n<table style=\"width: 1005px\" border=\"1\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td valign=\"top\" width=\"206\">\n<p><strong><span style=\"font-size: x-small\">User Agent<\/span><\/strong><\/p>\n<\/td>\n<td valign=\"top\" width=\"140\">\n<p><span style=\"font-size: x-small\"><strong>Forms Authentication Middleware(Application)<\/strong><strong><\/strong><\/span><\/p>\n<\/td>\n<td valign=\"top\" width=\"205\">\n<p><span style=\"font-size: x-small\"><strong>Forms Authentication Middleware(External)<\/strong><strong><\/strong><\/span><\/p>\n<\/td>\n<td valign=\"top\" width=\"205\">\n<p><strong><span style=\"font-size: x-small\">Facebook Authentication Middleware<\/span><\/strong><\/p>\n<\/td>\n<td valign=\"top\" width=\"247\">\n<p><strong><span style=\"font-size: x-small\">Web App<\/span><\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"206\">\n<p><span style=\"font-size: x-small\">&lt;After facebook returns authorization code back to your app&gt;<\/span><\/p>\n<p><strong><span style=\"font-size: x-small\">1. GET \/signin-facebook?code=&lt;authorization code&gt;&amp;state=&lt;state&gt;<\/span><\/strong><\/p>\n<p><strong><span style=\"font-size: x-small\">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-&gt;<\/span><\/strong><\/p>\n<\/td>\n<td valign=\"top\" width=\"140\">&nbsp;<\/td>\n<td valign=\"top\" width=\"205\">&nbsp;<\/td>\n<td valign=\"top\" width=\"205\">&nbsp;<\/td>\n<td valign=\"top\" width=\"247\">&nbsp;<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"206\">&nbsp;<\/td>\n<td valign=\"top\" width=\"140\">&nbsp;<\/td>\n<td valign=\"top\" width=\"205\">&nbsp;<\/td>\n<td valign=\"top\" width=\"205\">\n<p><strong><span style=\"font-size: x-small\">2. Status: 302<\/span><\/strong><\/p>\n<p><strong><span style=\"font-size: x-small\">Location: \/Account\/ExternalLoginCallback?loginProvider=Facebook<\/span><\/strong><\/p>\n<p><span style=\"font-size: x-small\">Middleware code does:<\/span><\/p>\n<p><span style=\"font-size: x-small\">a. Get access token by authorization code from facebook<\/span><\/p>\n<p><span style=\"font-size: x-small\">b. Get user graph data from facebook<\/span><\/p>\n<p><span style=\"font-size: x-small\">c. Convert user graph data into claims identity<\/span><\/p>\n<p><span style=\"font-size: x-small\">d. Sign in claims identity as external type<\/span><\/p>\n<p><strong><span style=\"font-size: x-small\">&lt;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<\/span><\/strong><\/p>\n<\/td>\n<td valign=\"top\" width=\"247\">&nbsp;<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"206\">&nbsp;<\/td>\n<td valign=\"top\" width=\"140\">&nbsp;<\/td>\n<td valign=\"top\" width=\"205\">\n<p><strong><span style=\"font-size: x-small\">3. Status: 302<\/span><\/strong><\/p>\n<p><strong><span style=\"font-size: x-small\">Location: \/Account\/ExternalLoginCallback?loginProvider=Facebook<\/span><\/strong><\/p>\n<p><strong><span style=\"font-size: x-small\">Set-Cookie: .AspNet.External=&lt;ticket token&gt;<\/span><\/strong><\/p>\n<p><span style=\"font-size: x-small\">External forms middleware does: <\/span><\/p>\n<p><span style=\"font-size: x-small\">a. Convert claims identity to ApplicationTicket<\/span><\/p>\n<p><span style=\"font-size: x-small\">b. Serialize ApplicationTicket to byte array<\/span><\/p>\n<p><span style=\"font-size: x-small\">c. Encrypt and encode byte array to ticket token<\/span><\/p>\n<p><span style=\"font-size: x-small\">d. Set cookie to response<\/span><\/p>\n<p><strong><span style=\"font-size: x-small\">&lt;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<\/span><\/strong><\/p>\n<\/td>\n<td valign=\"top\" width=\"205\">&nbsp;<\/td>\n<td valign=\"top\" width=\"247\">&nbsp;<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"206\">\n<p><strong><span style=\"font-size: x-small\">4. Get \/Account\/ExternalLoginCallback?loginProvider=Facebook<\/span><\/strong><\/p>\n<p><strong><span style=\"font-size: x-small\">Cookie: .AspNet.External=&lt;ticket token&gt;<\/span><\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-size: x-small\"><strong>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-&gt;<\/strong><strong><\/strong><\/span><\/p>\n<\/td>\n<td valign=\"top\" width=\"140\">&nbsp;<\/td>\n<td valign=\"top\" width=\"205\">&nbsp;<\/td>\n<td valign=\"top\" width=\"205\">&nbsp;<\/td>\n<td valign=\"top\" width=\"247\">&nbsp;<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"206\">&nbsp;<\/td>\n<td valign=\"top\" width=\"140\">&nbsp;<\/td>\n<td valign=\"top\" width=\"205\">&nbsp;<\/td>\n<td valign=\"top\" width=\"205\">&nbsp;<\/td>\n<td valign=\"top\" width=\"247\">\n<p><span style=\"font-size: x-small\"><strong>5.<\/strong> <strong>IdentityAuthenticationManager.GetExternalIdentity()<\/strong><\/span><\/p>\n<p><span style=\"font-size: x-small\">The extension method will call into OWIN middleware to explicitly authenticate with external type<\/span><\/p>\n<p><strong><span style=\"font-size: x-small\">&lt;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<\/span><\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"206\">&nbsp;<\/td>\n<td valign=\"top\" width=\"140\">&nbsp;<\/td>\n<td valign=\"top\" width=\"205\">\n<p><strong><span style=\"font-size: x-small\">6. Authenticate cookie and return user claims identity<\/span><\/strong><\/p>\n<p><span style=\"font-size: x-small\">External forms middleware does: <\/span><\/p>\n<p><span style=\"font-size: x-small\">a. Decode and decrypt ticket token into byte array<\/span><\/p>\n<p><span style=\"font-size: x-small\">b. Deserialize byte array to ApplicationTicket<\/span><\/p>\n<p><span style=\"font-size: x-small\">c. Get claims identity from ApplicationTicket<\/span><\/p>\n<p><span style=\"font-size: x-small\">d. Return identity back to caller<\/span><\/p>\n<p><strong><span style=\"font-size: x-small\">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-&gt;<\/span><\/strong><\/p>\n<\/td>\n<td valign=\"top\" width=\"205\">&nbsp;<\/td>\n<td valign=\"top\" width=\"247\">&nbsp;<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"206\">&nbsp;<\/td>\n<td valign=\"top\" width=\"140\">&nbsp;<\/td>\n<td valign=\"top\" width=\"205\">&nbsp;<\/td>\n<td valign=\"top\" width=\"205\">&nbsp;<\/td>\n<td valign=\"top\" width=\"247\">\n<p><strong><span style=\"font-size: x-small\">7. Status: 200<\/span><\/strong><\/p>\n<p><strong><span style=\"font-size: x-small\">Body: external login page<\/span><\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-size: x-small\">After getting the external identity, check if the user is already registered. <\/span><\/p>\n<p><span style=\"font-size: x-small\">&#8211; If no, return external login confirmation page. <\/span><\/p>\n<p><span style=\"font-size: x-small\">&#8211; If yes, directly log user in (Not included in this flow)<\/span><\/p>\n<p><strong><span style=\"font-size: x-small\">&lt;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<\/span><\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"206\">\n<p><strong><span style=\"font-size: x-small\">8. POST \/Account\/ExternalLoginConfirmation<\/span><\/strong><\/p>\n<p><strong><span style=\"font-size: x-small\">Cookie: .AspNet.External=&lt;ticket token&gt;<\/span><\/strong><\/p>\n<p><strong><span style=\"font-size: x-small\">Body: UserName=test&amp;LoginProvider=Facebook<\/span><\/strong><\/p>\n<p><strong><span style=\"font-size: x-small\">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-&gt;<\/span><\/strong><\/p>\n<\/td>\n<td valign=\"top\" width=\"140\">&nbsp;<\/td>\n<td valign=\"top\" width=\"205\">&nbsp;<\/td>\n<td valign=\"top\" width=\"205\">&nbsp;<\/td>\n<td valign=\"top\" width=\"247\">&nbsp;<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"206\">&nbsp;<\/td>\n<td valign=\"top\" width=\"140\">&nbsp;<\/td>\n<td valign=\"top\" width=\"205\">&nbsp;<\/td>\n<td valign=\"top\" width=\"205\">&nbsp;<\/td>\n<td valign=\"top\" width=\"247\">\n<p><strong><span style=\"font-size: x-small\">9. IdentityAuthenticationManager.GetExternalIdentity()<\/span><\/strong><\/p>\n<p><span style=\"font-size: x-small\">The extension method will call into OWIN middleware to explicitly authenticate with external type<\/span><\/p>\n<p><strong><span style=\"font-size: x-small\">&lt;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<\/span><\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"206\">&nbsp;<\/td>\n<td valign=\"top\" width=\"140\">&nbsp;<\/td>\n<td valign=\"top\" width=\"205\">\n<p><strong><span style=\"font-size: x-small\">10. Authenticate cookie and return user claims identity<\/span><\/strong><\/p>\n<p><strong><span style=\"font-size: x-small\">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-&gt;<\/span><\/strong><\/p>\n<\/td>\n<td valign=\"top\" width=\"205\">&nbsp;<\/td>\n<td valign=\"top\" width=\"247\">&nbsp;<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"206\">&nbsp;<\/td>\n<td valign=\"top\" width=\"140\">&nbsp;<\/td>\n<td valign=\"top\" width=\"205\">&nbsp;<\/td>\n<td valign=\"top\" width=\"205\">&nbsp;<\/td>\n<td valign=\"top\" width=\"247\">\n<p><strong><span style=\"font-size: x-small\">11. Status: 302<\/span><\/strong><\/p>\n<p><strong><span style=\"font-size: x-small\">Location: \/<\/span><\/strong><\/p>\n<p><span style=\"font-size: x-small\">Web app code does:<\/span><\/p>\n<p><span style=\"font-size: x-small\">a. Create local user via membership provider<\/span><\/p>\n<p><span style=\"font-size: x-small\">b. Associate local user with external identity&rsquo;s ID claim (facebook id)<\/span><\/p>\n<p><span style=\"font-size: x-small\">c. Sign the external identity in as Application type<\/span><\/p>\n<p><span style=\"font-size: x-small\">d. Redirect to returnUrl or home page<\/span><\/p>\n<p><strong><span style=\"font-size: x-small\">&lt;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<\/span><\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"206\">&nbsp;<\/td>\n<td valign=\"top\" width=\"140\">\n<p><strong><span style=\"font-size: x-small\">12. Status: 302<\/span><\/strong><\/p>\n<p><strong><span style=\"font-size: x-small\">Location: \/<\/span><\/strong><\/p>\n<p><strong><span style=\"font-size: x-small\">Set-Cookie: .AspNet.Application=&lt;Ticket Token&gt;<\/span><\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-size: x-small\">Turn claims identity to ticket token and set cookie in response<\/span><\/p>\n<p><strong><span style=\"font-size: x-small\">&lt;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<\/span><\/strong><\/p>\n<\/td>\n<td valign=\"top\" width=\"205\">&nbsp;<\/td>\n<td valign=\"top\" width=\"205\">&nbsp;<\/td>\n<td valign=\"top\" width=\"247\">&nbsp;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<h3><a name=\"_Working_with_new\"><\/a>Working with new Identity API<\/h3>\n<p><strong>IdentityAuthenticationManager<\/strong> wraps everything that you need to work with Application and External sign in cookies.<\/p>\n<div id=\"scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:68555e1b-17fe-47ff-a58d-ed48fd718c5c\" class=\"wlWriterEditableSmartContent\" style=\"margin: 0px;padding: 0px;float: none\">\n<div style=\"border: #000080 1px solid;color: #000;font-family: 'Courier New', Courier, Monospace;font-size: 10pt\">\n<div style=\"background: #000080;color: #fff;font-family: Verdana, Tahoma, Arial, sans-serif;font-weight: bold;padding: 2px 5px\">Code Snippet<\/div>\n<div style=\"background: #ddd;max-height: 300px;overflow: auto\">\n<ol style=\"background: #ffffff;margin: 0 0 0 2.5em;padding: 0 0 0 5px\" start=\"1\">\n<li><span style=\"background: #ffffff;color: #0000ff\">public<\/span><span style=\"background: #ffffff;color: #0000ff\">class<\/span><span style=\"background: #ffffff;color: #2b91af\">IdentityAuthenticationManager<\/span><\/li>\n<li style=\"background: #f3f3f3\"><span style=\"background: #ffffff;color: #000000\">{<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">public<\/span><span style=\"background: #ffffff;color: #000000\"> IdentityAuthenticationManager();<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">public<\/span><span style=\"background: #ffffff;color: #000000\"> IdentityAuthenticationManager(IdentityStoreManager storeManager);<\/span><\/li>\n<li>&nbsp;<\/li>\n<li style=\"background: #f3f3f3\">&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">public<\/span><span style=\"background: #ffffff;color: #0000ff\">string<\/span><span style=\"background: #ffffff;color: #000000\"> ClaimsIssuer { <\/span><span style=\"background: #ffffff;color: #0000ff\">get<\/span><span style=\"background: #ffffff;color: #000000\">; <\/span><span style=\"background: #ffffff;color: #0000ff\">set<\/span><span style=\"background: #ffffff;color: #000000\">; }<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">public<\/span><span style=\"background: #ffffff;color: #0000ff\">string<\/span><span style=\"background: #ffffff;color: #000000\"> RoleClaimType { <\/span><span style=\"background: #ffffff;color: #0000ff\">get<\/span><span style=\"background: #ffffff;color: #000000\">; <\/span><span style=\"background: #ffffff;color: #0000ff\">set<\/span><span style=\"background: #ffffff;color: #000000\">; }<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">public<\/span><span style=\"background: #ffffff;color: #000000\"> IdentityStoreManager StoreManager { <\/span><span style=\"background: #ffffff;color: #0000ff\">get<\/span><span style=\"background: #ffffff;color: #000000\">; <\/span><span style=\"background: #ffffff;color: #0000ff\">set<\/span><span style=\"background: #ffffff;color: #000000\">; }<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">public<\/span><span style=\"background: #ffffff;color: #0000ff\">string<\/span><span style=\"background: #ffffff;color: #000000\"> UserIdClaimType { <\/span><span style=\"background: #ffffff;color: #0000ff\">get<\/span><span style=\"background: #ffffff;color: #000000\">; <\/span><span style=\"background: #ffffff;color: #0000ff\">set<\/span><span style=\"background: #ffffff;color: #000000\">; }<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">public<\/span><span style=\"background: #ffffff;color: #0000ff\">string<\/span><span style=\"background: #ffffff;color: #000000\"> UserNameClaimType { <\/span><span style=\"background: #ffffff;color: #0000ff\">get<\/span><span style=\"background: #ffffff;color: #000000\">; <\/span><span style=\"background: #ffffff;color: #0000ff\">set<\/span><span style=\"background: #ffffff;color: #000000\">; }<\/span><\/li>\n<li>&nbsp;<\/li>\n<li style=\"background: #f3f3f3\">&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">public<\/span><span style=\"background: #ffffff;color: #0000ff\">virtual<\/span><span style=\"background: #ffffff;color: #0000ff\">void<\/span><span style=\"background: #ffffff;color: #000000\"> Challenge(HttpContextBase context, <\/span><span style=\"background: #ffffff;color: #0000ff\">string<\/span><span style=\"background: #ffffff;color: #000000\"> authenticationType, <\/span><span style=\"background: #ffffff;color: #0000ff\">string<\/span><span style=\"background: #ffffff;color: #000000\"> redirectUrl);<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">public<\/span><span style=\"background: #ffffff;color: #0000ff\">virtual<\/span><span style=\"background: #ffffff;color: #000000\"> Task&lt;<\/span><span style=\"background: #ffffff;color: #0000ff\">bool<\/span><span style=\"background: #ffffff;color: #000000\">&gt; CheckPasswordAndSignIn(HttpContextBase context, <\/span><span style=\"background: #ffffff;color: #0000ff\">string<\/span><span style=\"background: #ffffff;color: #000000\"> userName, <\/span><span style=\"background: #ffffff;color: #0000ff\">string<\/span><span style=\"background: #ffffff;color: #000000\"> password, <\/span><span style=\"background: #ffffff;color: #0000ff\">bool<\/span><span style=\"background: #ffffff;color: #000000\"> isPersistent);<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">public<\/span><span style=\"background: #ffffff;color: #0000ff\">virtual<\/span><span style=\"background: #ffffff;color: #000000\"> Task&lt;<\/span><span style=\"background: #ffffff;color: #0000ff\">bool<\/span><span style=\"background: #ffffff;color: #000000\">&gt; CreateAndSignInExternalUser(HttpContextBase context, <\/span><span style=\"background: #ffffff;color: #0000ff\">string<\/span><span style=\"background: #ffffff;color: #000000\"> loginProvider, IUser user);<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">public<\/span><span style=\"background: #ffffff;color: #0000ff\">virtual<\/span><span style=\"background: #ffffff;color: #000000\"> IEnumerable&lt;Microsoft.Owin.Security.<\/span><span style=\"background: #ffffff;color: #2b91af\">AuthenticationDescription<\/span><span style=\"background: #ffffff;color: #000000\">&gt; GetExternalAuthenticationTypes(HttpContextBase context);<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">public<\/span><span style=\"background: #ffffff;color: #0000ff\">virtual<\/span><span style=\"background: #ffffff;color: #000000\"> Task&lt;ClaimsIdentity&gt; GetExternalIdentity(HttpContextBase context);<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">public<\/span><span style=\"background: #ffffff;color: #0000ff\">virtual<\/span><span style=\"background: #ffffff;color: #000000\"> Task&lt;IList&lt;Claim&gt;&gt; GetUserIdentityClaims(<\/span><span style=\"background: #ffffff;color: #0000ff\">string<\/span><span style=\"background: #ffffff;color: #000000\"> userId, IEnumerable&lt;Claim&gt; claims);<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">public<\/span><span style=\"background: #ffffff;color: #0000ff\">virtual<\/span><span style=\"background: #ffffff;color: #000000\"> Task&lt;<\/span><span style=\"background: #ffffff;color: #0000ff\">bool<\/span><span style=\"background: #ffffff;color: #000000\">&gt; LinkExternalIdentity(ClaimsIdentity id, <\/span><span style=\"background: #ffffff;color: #0000ff\">string<\/span><span style=\"background: #ffffff;color: #000000\"> userId, <\/span><span style=\"background: #ffffff;color: #0000ff\">string<\/span><span style=\"background: #ffffff;color: #000000\"> loginProvider);<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">public<\/span><span style=\"background: #ffffff;color: #0000ff\">virtual<\/span><span style=\"background: #ffffff;color: #000000\"> Task SignIn(HttpContextBase context, <\/span><span style=\"background: #ffffff;color: #0000ff\">string<\/span><span style=\"background: #ffffff;color: #000000\"> userId, <\/span><span style=\"background: #ffffff;color: #0000ff\">bool<\/span><span style=\"background: #ffffff;color: #000000\"> isPersistent);<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">public<\/span><span style=\"background: #ffffff;color: #0000ff\">virtual<\/span><span style=\"background: #ffffff;color: #000000\"> Task SignIn(HttpContextBase context, <\/span><span style=\"background: #ffffff;color: #0000ff\">string<\/span><span style=\"background: #ffffff;color: #000000\"> userId, IEnumerable&lt;Claim&gt; claims, <\/span><span style=\"background: #ffffff;color: #0000ff\">bool<\/span><span style=\"background: #ffffff;color: #000000\"> isPersistent);<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">public<\/span><span style=\"background: #ffffff;color: #0000ff\">virtual<\/span><span style=\"background: #ffffff;color: #000000\"> Task&lt;<\/span><span style=\"background: #ffffff;color: #0000ff\">bool<\/span><span style=\"background: #ffffff;color: #000000\">&gt; SignInExternalIdentity(HttpContextBase context, ClaimsIdentity id, <\/span><span style=\"background: #ffffff;color: #0000ff\">string<\/span><span style=\"background: #ffffff;color: #000000\"> loginProvider);<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">public<\/span><span style=\"background: #ffffff;color: #0000ff\">virtual<\/span><span style=\"background: #ffffff;color: #0000ff\">void<\/span><span style=\"background: #ffffff;color: #000000\"> SignOut(HttpContextBase context);<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">public<\/span><span style=\"background: #ffffff;color: #0000ff\">virtual<\/span><span style=\"background: #ffffff;color: #0000ff\">bool<\/span><span style=\"background: #ffffff;color: #000000\"> VerifyExternalIdentity(ClaimsIdentity id, <\/span><span style=\"background: #ffffff;color: #0000ff\">string<\/span><span style=\"background: #ffffff;color: #000000\"> loginProvider);<\/span><\/li>\n<li style=\"background: #f3f3f3\"><span style=\"background: #ffffff;color: #000000\">}<\/span><\/li>\n<\/ol>\n<\/div>\n<\/div>\n<\/div>\n<table border=\"1\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td valign=\"top\" width=\"312\">\n<p><strong>Method<\/strong><\/p>\n<\/td>\n<td valign=\"top\" width=\"312\">\n<p><strong>Description<\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"312\">\n<p>CheckPasswordAndSignIn<\/p>\n<\/td>\n<td valign=\"top\" width=\"312\">\n<p>Verify user name and password against storage like SQL server and sign in with Application cookie<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"312\">\n<p>CreateAndSignInExternalUser<\/p>\n<\/td>\n<td valign=\"top\" width=\"312\">\n<p>Create user based on external identity from External cookie in storage like SQL server, and sign in user as Application cookie<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"312\">\n<p>GetExternalIdentity<\/p>\n<\/td>\n<td valign=\"top\" width=\"312\">\n<p>Get external identity from External cookie<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"312\">\n<p>GetUserIdentityClaims<\/p>\n<\/td>\n<td valign=\"top\" width=\"312\">\n<p>Replace user id and name claims and add roles and user custom claims from storage.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"312\">\n<p>LinkExternalIdentity<\/p>\n<\/td>\n<td valign=\"top\" width=\"312\">\n<p>Link external identity with local user in storage<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"312\">\n<p>SignIn<\/p>\n<\/td>\n<td valign=\"top\" width=\"312\">\n<p>Sign out External cookie and sign in Application cookie<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"312\">\n<p>SignInExternalIdentity<\/p>\n<\/td>\n<td valign=\"top\" width=\"312\">\n<p>Get user associating with external identity in storage and sign this user in as Application cookie<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"312\">\n<p>SignOut<\/p>\n<\/td>\n<td valign=\"top\" width=\"312\">\n<p>Sign out from Application cookie<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"312\">\n<p>VerifyExternalIdentity<\/p>\n<\/td>\n<td valign=\"top\" width=\"312\">\n<p>Verify if the external identity has the same issuer as loginProvider<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"312\">\n<p>Challenge<\/p>\n<\/td>\n<td valign=\"top\" width=\"312\">\n<p>Explicitly ask authentication middleware to send challenge to the response. For example, Application forms middleware will challenge to redirect to login page with 302 status code.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"312\">\n<p>GetExternalAuthenticationTypes<\/p>\n<\/td>\n<td valign=\"top\" width=\"312\">\n<p>Get supported external authentication types which you register in the OWIN middleware pipeline, like Facebook, Google, etc.<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>The following shows the login code for the ASP.NET MVC template:<\/p>\n<div id=\"scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:827ed5d7-8797-453d-b0cc-b4b27c2d86fb\" class=\"wlWriterEditableSmartContent\" style=\"margin: 0px;padding: 0px;float: none\">\n<div style=\"border: #000080 1px solid;color: #000;font-family: 'Courier New', Courier, Monospace;font-size: 10pt\">\n<div style=\"background: #000080;color: #fff;font-family: Verdana, Tahoma, Arial, sans-serif;font-weight: bold;padding: 2px 5px\">Code Snippet<\/div>\n<div style=\"background: #ddd;max-height: 300px;overflow: auto\">\n<ol style=\"background: #ffffff;margin: 0 0 0 2.5em;padding: 0 0 0 5px\" start=\"1\">\n<li><span style=\"background: #ffffff;color: #000000\">[<\/span><span style=\"background: #ffffff;color: #2b91af\">HttpPost<\/span><span style=\"background: #ffffff;color: #000000\">]<\/span><\/li>\n<li style=\"background: #f3f3f3\"><span style=\"background: #ffffff;color: #000000\">[<\/span><span style=\"background: #ffffff;color: #2b91af\">AllowAnonymous<\/span><span style=\"background: #ffffff;color: #000000\">]<\/span><\/li>\n<li><span style=\"background: #ffffff;color: #000000\">[<\/span><span style=\"background: #ffffff;color: #2b91af\">ValidateAntiForgeryToken<\/span><span style=\"background: #ffffff;color: #000000\">]<\/span><\/li>\n<li style=\"background: #f3f3f3\"><span style=\"background: #ffffff;color: #0000ff\">public<\/span><span style=\"background: #ffffff;color: #0000ff\">async<\/span><span style=\"background: #ffffff;color: #2b91af\">Task<\/span><span style=\"background: #ffffff;color: #000000\">&lt;<\/span><span style=\"background: #ffffff;color: #2b91af\">ActionResult<\/span><span style=\"background: #ffffff;color: #000000\">&gt; Login(<\/span><span style=\"background: #ffffff;color: #2b91af\">LoginViewModel<\/span><span style=\"background: #ffffff;color: #000000\"> model, <\/span><span style=\"background: #ffffff;color: #0000ff\">string<\/span><span style=\"background: #ffffff;color: #000000\"> returnUrl)<\/span><\/li>\n<li><span style=\"background: #ffffff;color: #000000\">{<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">if<\/span><span style=\"background: #ffffff;color: #000000\"> (ModelState.IsValid)<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">{<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #008000\">\/\/ Validate the user password<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">if<\/span><span style=\"background: #ffffff;color: #000000\"> (<\/span><span style=\"background: #ffffff;color: #0000ff\">await<\/span><span style=\"background: #ffffff;color: #000000\"> AuthenticationManager.CheckPasswordAndSignIn(HttpContext, model.UserName, model.Password, model.RememberMe))<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">{<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">return<\/span><span style=\"background: #ffffff;color: #000000\"> RedirectToLocal(returnUrl);<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">}<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">}<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;<\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #008000\">\/\/ If we got this far, something failed, redisplay form<\/span><\/li>\n<li style=\"background: #f3f3f3\">&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #000000\">ModelState.AddModelError(<\/span><span style=\"background: #ffffff;color: #a31515\">&#8220;&#8221;<\/span><span style=\"background: #ffffff;color: #000000\">, <\/span><span style=\"background: #ffffff;color: #a31515\">&#8220;The user name or password provided is incorrect.&#8221;<\/span><span style=\"background: #ffffff;color: #000000\">);<\/span><\/li>\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"background: #ffffff;color: #0000ff\">return<\/span><span style=\"background: #ffffff;color: #000000\"> View(model);<\/span><\/li>\n<li style=\"background: #f3f3f3\"><span style=\"background: #ffffff;color: #000000\">}<\/span><\/li>\n<\/ol>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Overview The new security feature design for MVC 5 is based on OWIN authentication middleware. The benefit for it is that security feature can be shared by other components that can be hosted on OWIN. Since the Katana team did a great effort to support the OWIN integrated pipeline in ASP.NET, it can also secure [&hellip;]<\/p>\n","protected":false},"author":438,"featured_media":58792,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[197],"tags":[7438,7436],"class_list":["post-1544","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-aspnet","tag-identity","tag-visual-studio-2013"],"acf":[],"blog_post_summary":"<p>Overview The new security feature design for MVC 5 is based on OWIN authentication middleware. The benefit for it is that security feature can be shared by other components that can be hosted on OWIN. Since the Katana team did a great effort to support the OWIN integrated pipeline in ASP.NET, it can also secure [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/1544","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/users\/438"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/comments?post=1544"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/1544\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media\/58792"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media?parent=1544"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/categories?post=1544"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/tags?post=1544"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}