Skip to content
This repository has been archived by the owner on Mar 20, 2019. It is now read-only.

Commit

Permalink
OpenIdTextBox now catches some failure exceptions and fires the Error…
Browse files Browse the repository at this point in the history
… event as appropriate. Fixes issue 19.

git-svn-id: https://dotnetopenid.googlecode.com/svn/trunk@78 01efa1a6-402a-0410-b0ae-47b76eba00f0
  • Loading branch information
AArnott committed Jan 21, 2008
1 parent e27557e commit 338dc70
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 33 deletions.
7 changes: 3 additions & 4 deletions source/JanRain.OpenID.ConsumerPortal/login.aspx.cs
Expand Up @@ -15,8 +15,6 @@

public partial class login : System.Web.UI.Page
{


/// <summary>
/// Handles the Load event of the Page control.
/// </summary>
Expand All @@ -34,12 +32,13 @@ protected void Page_Load(object sender, EventArgs e)
/// <param name="sender"></param>
/// <param name="e"></param>
protected void OpenIdLogin1_LoggedIn(object sender, NerdBank.OpenId.Consumer.OpenIdTextBox.OpenIdEventArgs e)
{
State.ProfileFields = e.ProfileFields;
{
State.ProfileFields = e.ProfileFields;
}
protected void OpenIdLogin1_Error(object sender, NerdBank.OpenId.Consumer.OpenIdTextBox.ErrorEventArgs e)
{
loginFailedLabel.Visible = true;
loginFailedLabel.Text += ": " + e.ErrorMessage;
}
protected void OpenIdLogin1_Canceled(object sender, NerdBank.OpenId.Consumer.OpenIdTextBox.ErrorEventArgs e)
{
Expand Down
65 changes: 36 additions & 29 deletions source/Janrain.OpenId/Consumer/OpenIdTextBox.cs
Expand Up @@ -24,6 +24,7 @@
using Janrain.OpenId.Session;
using Janrain.OpenId.RegistrationExtension;
using Janrain.OpenId.Store;
using System.Net;

namespace NerdBank.OpenId.RegistrationExtension
{
Expand Down Expand Up @@ -336,37 +337,43 @@ public void Login()
if (string.IsNullOrEmpty(Text))
throw new InvalidOperationException(Janrain.OpenId.Strings.OpenIdTextBoxEmpty);

Janrain.OpenId.Consumer.Consumer consumer =
new Janrain.OpenId.Consumer.Consumer(new SystemHttpSessionState(Page.Session), MemoryStore.GetInstance());

Uri userUri = UriUtil.NormalizeUri(Text);
// Initiate openid request
AuthRequest request = consumer.Begin(userUri);
if (EnableRequestProfile) addProfileArgs(request);

// Build the trust root
UriBuilder builder = new UriBuilder(Page.Request.Url.AbsoluteUri);
builder.Query = null;
builder.Password = null;
builder.UserName = null;
builder.Fragment = null;
builder.Path = Page.Request.ApplicationPath;
string trustRoot = builder.Uri.ToString();

// Build the return_to URL
UriBuilder return_to = new UriBuilder(Page.Request.Url);
// Trim off any old "openid." prefixed parameters to avoid carrying
// state from a prior login attempt.
return_to.Query = string.Empty;
NameValueCollection return_to_params = new NameValueCollection(Page.Request.QueryString.Count);
foreach (string key in Page.Request.QueryString) {
if (!key.StartsWith(QueryStringArgs.openid.Prefix) && key != QueryStringArgs.nonce) {
return_to_params.Add(key, Page.Request.QueryString[key]);
try {
Janrain.OpenId.Consumer.Consumer consumer =
new Janrain.OpenId.Consumer.Consumer(new SystemHttpSessionState(Page.Session), MemoryStore.GetInstance());

Uri userUri = UriUtil.NormalizeUri(Text);
// Initiate openid request
AuthRequest request = consumer.Begin(userUri);
if (EnableRequestProfile) addProfileArgs(request);

// Build the trust root
UriBuilder builder = new UriBuilder(Page.Request.Url.AbsoluteUri);
builder.Query = null;
builder.Password = null;
builder.UserName = null;
builder.Fragment = null;
builder.Path = Page.Request.ApplicationPath;
string trustRoot = builder.Uri.ToString();

// Build the return_to URL
UriBuilder return_to = new UriBuilder(Page.Request.Url);
// Trim off any old "openid." prefixed parameters to avoid carrying
// state from a prior login attempt.
return_to.Query = string.Empty;
NameValueCollection return_to_params = new NameValueCollection(Page.Request.QueryString.Count);
foreach (string key in Page.Request.QueryString) {
if (!key.StartsWith(QueryStringArgs.openid.Prefix) && key != QueryStringArgs.nonce) {
return_to_params.Add(key, Page.Request.QueryString[key]);
}
}
UriUtil.AppendQueryArgs(return_to, return_to_params);
Uri redirectUrl = request.CreateRedirect(trustRoot, return_to.Uri, AuthRequest.Mode.SETUP);
Page.Response.Redirect(redirectUrl.AbsoluteUri);
} catch (WebException ex) {
OnError(ex);
} catch (FailureException ex) {
OnError(ex);
}
UriUtil.AppendQueryArgs(return_to, return_to_params);
Uri redirectUrl = request.CreateRedirect(trustRoot, return_to.Uri, AuthRequest.Mode.SETUP);
Page.Response.Redirect(redirectUrl.AbsoluteUri);
}

void addProfileArgs(AuthRequest request)
Expand Down

0 comments on commit 338dc70

Please sign in to comment.