summaryrefslogtreecommitdiffstats
path: root/projecttemplates/MvcRelyingParty/Code/FormsAuthenticationService.cs
blob: 471c32508651761e9d84ceaf71113636a4dd5298 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
namespace MvcRelyingParty {
	using System;
	using System.Collections.Generic;
	using System.Linq;
	using System.Web;
	using System.Web.Security;
	using DotNetOpenAuth.OpenId;

	/// <summary>
	/// Forms authentication interface to facilitate login/logout functionality.
	/// </summary>
	/// <remarks>
	/// The FormsAuthentication type is sealed and contains static members, so it is difficult to
	/// unit test code that calls its members. The interface and helper class below demonstrate
	/// how to create an abstract wrapper around such a type in order to make the AccountController
	/// code unit testable.
	/// </remarks>
	public interface IFormsAuthentication {
		void SignIn(Identifier claimedIdentifier, bool createPersistentCookie);

		void SignOut();
	}

	/// <summary>
	/// The standard FormsAuthentication behavior to use for the live site.
	/// </summary>
	public class FormsAuthenticationService : IFormsAuthentication {
		public void SignIn(Identifier claimedIdentifier, bool createPersistentCookie) {
			FormsAuthentication.SetAuthCookie(claimedIdentifier, createPersistentCookie);
		}

		public void SignOut() {
			FormsAuthentication.SignOut();
		}
	}
}