diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2009-04-03 16:43:05 -0700 |
---|---|---|
committer | Andrew Arnott <andrewarnott@gmail.com> | 2009-04-03 16:43:05 -0700 |
commit | 10a0eaf4306e74974d360b59595656ee63ba1598 (patch) | |
tree | 7e7b81a525ea799b7661fcbc580a6343094a572d | |
parent | 6a4a04faa4a84524cf876a8ad5d9713ee3272222 (diff) | |
download | DotNetOpenAuth-10a0eaf4306e74974d360b59595656ee63ba1598.zip DotNetOpenAuth-10a0eaf4306e74974d360b59595656ee63ba1598.tar.gz DotNetOpenAuth-10a0eaf4306e74974d360b59595656ee63ba1598.tar.bz2 |
Added OP unsolicited assertion bookmarking feature so that users can bookmark a URL that will cause the OP to immediately log the user into the RP.
-rw-r--r-- | samples/OpenIdProviderWebForms/Default.aspx | 53 |
1 files changed, 48 insertions, 5 deletions
diff --git a/samples/OpenIdProviderWebForms/Default.aspx b/samples/OpenIdProviderWebForms/Default.aspx index f05a33a..36272c4 100644 --- a/samples/OpenIdProviderWebForms/Default.aspx +++ b/samples/OpenIdProviderWebForms/Default.aspx @@ -7,13 +7,32 @@ <%@ Register Assembly="DotNetOpenAuth" Namespace="DotNetOpenAuth" TagPrefix="openauth" %> <script runat="server"> + protected void Page_Load(object sender, EventArgs e) { + if (Request.QueryString["rp"] != null) { + if (Page.User.Identity.IsAuthenticated) { + SendAssertion(Request.QueryString["rp"]); + } else { + FormsAuthentication.RedirectToLoginPage(); + } + } else { + TextBox relyingPartySite = (TextBox)loginView.FindControl("relyingPartySite"); + if (relyingPartySite != null) { + relyingPartySite.Focus(); + } + } + } + protected void sendAssertionButton_Click(object sender, EventArgs e) { TextBox relyingPartySite = (TextBox)loginView.FindControl("relyingPartySite"); + 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(relyingPartySite.Text); + string rpSite = Identifier.Parse(relyingPartyRealm); op.PrepareUnsolicitedAssertion(providerEndpoint, rpSite, Util.BuildIdentityUrl(), Util.BuildIdentityUrl()).Send(); } catch (ProtocolException ex) { Label errorLabel = (Label)loginView.FindControl("errorLabel"); @@ -25,6 +44,27 @@ <asp:Content runat="server" ContentPlaceHolderID="head"> <openauth:XrdsPublisher runat="server" XrdsUrl="~/op_xrds.aspx" /> + + <script language="javascript"> + String.prototype.startsWith = function(substring) { + if (this.length < substring.length) { + return false; + } + return this.substring(0, substring.length) == substring; + }; + + function updateBookmark(rpRealm) { + if (!(rpRealm.startsWith("http://") || rpRealm.startsWith("https://"))) { + rpRealm = "http://" + rpRealm; + } + + var bookmarkUrl = document.location + "?rp=" + encodeURIComponent(rpRealm); + bookmarkParagraph.style.display = ''; + bookmark.href = bookmarkUrl; + bookmark.innerHTML = bookmarkUrl; + } + </script> + </asp:Content> <asp:Content runat="server" ContentPlaceHolderID="Main"> <h2>Provider </h2> @@ -34,16 +74,19 @@ <asp:LoginView runat="server" ID="loginView"> <LoggedInTemplate> <asp:Panel runat="server" DefaultButton="sendAssertionButton"> - <p>You're logged in as <b><%= HttpUtility.HtmlEncode(User.Identity.Name) %></b> </p> - <p>Your claimed identifier is <b><%= HttpUtility.HtmlEncode(Util.BuildIdentityUrl()) %></b> </p> + <p>You're logged in as <b> + <%= HttpUtility.HtmlEncode(User.Identity.Name) %></b> </p> + <p>Your claimed identifier is <b> + <%= HttpUtility.HtmlEncode(Util.BuildIdentityUrl()) %></b> </p> <p>Since you're logged in, try sending an unsolicited assertion to an OpenID 2.0 relying party site. Just type in the URL to the site's home page. This could be the sample relying party web site. </p> <div> - <asp:TextBox runat="server" ID="relyingPartySite" Columns="40" /> - <asp:Button runat="server" ID="sendAssertionButton" Text="Send assertion" OnClick="sendAssertionButton_Click" /> + <asp:TextBox runat="server" ID="relyingPartySite" Columns="40" onchange="updateBookmark(this.value)" onkeyup="updateBookmark(this.value)" /> + <asp:Button runat="server" ID="sendAssertionButton" Text="Login" OnClick="sendAssertionButton_Click" /> <asp:RequiredFieldValidator runat="server" ControlToValidate="relyingPartySite" Text="Specify relying party site first" /> </div> + <p id="bookmarkParagraph" style="display:none">Bookmark <a id="bookmark"></a> so you can log into the RP automatically in the future.</p> <p>An unsolicited assertion is a way to log in to a relying party site directly from your OpenID Provider. </p> <p><asp:Label runat="server" EnableViewState="false" Visible="false" ID="errorLabel" |