summaryrefslogtreecommitdiffstats
path: root/samples/OpenIdWebRingSsoProvider/Default.aspx.cs
blob: 6a930bdf337114b4e6d1bef327819a25009f276d (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
namespace OpenIdWebRingSsoProvider {
	using System;
	using System.Collections.Generic;
	using System.Linq;
	using System.Web;
	using System.Web.UI;
	using System.Web.UI.WebControls;
	using DotNetOpenAuth.Messaging;
	using DotNetOpenAuth.OpenId.Provider;
	using OpenIdWebRingSsoProvider.Code;

	public partial class _Default : System.Web.UI.Page {
		protected void Page_Load(object sender, EventArgs e) {
			this.RegisterAsyncTask(
				new PageAsyncTask(
					async ct => {
						// The user may have just completed a login.  If they're logged in, see if we can complete the OpenID login.
						if (User.Identity.IsAuthenticated && ProviderEndpoint.PendingAuthenticationRequest != null) {
							await
								Util.ProcessAuthenticationChallengeAsync(
									ProviderEndpoint.PendingAuthenticationRequest, Response.ClientDisconnectedToken);
							if (ProviderEndpoint.PendingAuthenticationRequest.IsAuthenticated.HasValue) {
								var providerEndpoint = new ProviderEndpoint();
								var responseMessage = await providerEndpoint.PrepareResponseAsync(this.Response.ClientDisconnectedToken);
								await responseMessage.SendAsync(new HttpContextWrapper(this.Context), this.Response.ClientDisconnectedToken);
								this.Context.Response.End();
							}
						}
					}));
		}
	}
}