summaryrefslogtreecommitdiffstats
path: root/samples/OpenIdProviderMvc/Controllers/UserController.cs
blob: 3cb87ae80c073ae0c79281268b683cd38eee386d (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
37
38
39
40
41
42
43
44
45
namespace OpenIdProviderMvc.Controllers {
	using System;
	using System.Collections.Generic;
	using System.Linq;
	using System.Web;
	using System.Web.Mvc;
	using System.Web.Mvc.Ajax;

	public class UserController : Controller {
		public ActionResult PpidIdentity() {
			if (Request.AcceptTypes.Contains("application/xrds+xml")) {
				return View("Xrds");
			}

			return View();
		}

		public ActionResult Identity(string id) {
			var redirect = this.RedirectIfNotNormalizedRequestUri();
			if (redirect != null) {
				return redirect;
			}

			if (Request.AcceptTypes.Contains("application/xrds+xml")) {
				return View("Xrds");
			}

			this.ViewData["username"] = id;
			return View();
		}

		public ActionResult Xrds(string id) {
			return View();
		}

		private ActionResult RedirectIfNotNormalizedRequestUri() {
			Uri normalized = Models.User.GetNormalizedClaimedIdentifier(Request.Url);
			if (Request.Url != normalized) {
				return Redirect(normalized.AbsoluteUri);
			}

			return null;
		}
	}
}