blob: 4843639bba05a2e3f999d32de8e1733a298016bd (
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
46
47
48
|
namespace OpenIdProviderWebForms {
using System;
using System.Web.Security;
using System.Web.UI.WebControls;
using DotNetOpenAuth.Messaging;
using DotNetOpenAuth.OpenId;
using DotNetOpenAuth.OpenId.Provider;
using OpenIdProviderWebForms.Code;
/// <summary>
/// Page for handling logins to this server.
/// </summary>
public partial class _default : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
if (Request.QueryString["rp"] != null) {
if (Page.User.Identity.IsAuthenticated) {
this.SendAssertion(Request.QueryString["rp"]);
} else {
FormsAuthentication.RedirectToLoginPage();
}
} else {
TextBox relyingPartySite = (TextBox)this.loginView.FindControl("relyingPartySite");
if (relyingPartySite != null) {
relyingPartySite.Focus();
}
}
}
protected void sendAssertionButton_Click(object sender, EventArgs e) {
TextBox relyingPartySite = (TextBox)this.loginView.FindControl("relyingPartySite");
this.SendAssertion(relyingPartySite.Text);
}
private void SendAssertion(string relyingPartyRealm) {
Uri providerEndpoint = new Uri(Request.Url, Page.ResolveUrl("~/server.aspx"));
OpenIdProvider op = new OpenIdProvider();
try {
// Send user input through identifier parser so we accept more free-form input.
string rpSite = Identifier.Parse(relyingPartyRealm);
op.PrepareUnsolicitedAssertion(providerEndpoint, rpSite, Util.BuildIdentityUrl(), Util.BuildIdentityUrl()).Send();
} catch (ProtocolException ex) {
Label errorLabel = (Label)this.loginView.FindControl("errorLabel");
errorLabel.Visible = true;
errorLabel.Text = ex.Message;
}
}
}
}
|