diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2009-03-11 09:19:39 -0700 |
---|---|---|
committer | Andrew Arnott <andrewarnott@gmail.com> | 2009-03-11 09:19:39 -0700 |
commit | bbf8a7718a719e3415fef458db2318f385b81cef (patch) | |
tree | 91313d8963598a7fe5e45382430cf559bc7b52bd /src | |
parent | ee17b8c87275fcde8936f34caf7766b8dd951c6a (diff) | |
download | DotNetOpenAuth-bbf8a7718a719e3415fef458db2318f385b81cef.zip DotNetOpenAuth-bbf8a7718a719e3415fef458db2318f385b81cef.tar.gz DotNetOpenAuth-bbf8a7718a719e3415fef458db2318f385b81cef.tar.bz2 |
Fixes handling of customized realm/return_to URLs in OpenIdTextBox and OpenIdAjaxTextBox (and OpenIdLogin implicitly).
Fixes Google Code Issue 214.
Port of fix from v2.5 branch commit a0115a09e6c1343b3ac3752fee72bd99b436f7be.
Diffstat (limited to 'src')
-rw-r--r-- | src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdAjaxTextBox.cs | 13 | ||||
-rw-r--r-- | src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdTextBox.cs | 13 |
2 files changed, 18 insertions, 8 deletions
diff --git a/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdAjaxTextBox.cs b/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdAjaxTextBox.cs index 7784ee5..216abcc 100644 --- a/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdAjaxTextBox.cs +++ b/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdAjaxTextBox.cs @@ -1172,12 +1172,16 @@ if (!openidbox.dnoi_internal.onSubmit()) {{ return false; }} var requests = new List<IAuthenticationRequest>(); using (OpenIdRelyingParty rp = CreateRelyingParty(true)) { + // Approximate the returnTo (either based on the customize property or the page URL) + // so we can use it to help with Realm resolution. + Uri returnToApproximation = this.ReturnToUrl != null ? new Uri(MessagingUtilities.GetRequestUrlFromContext(), this.ReturnToUrl) : this.Page.Request.Url; + // Resolve the trust root, and swap out the scheme and port if necessary to match the // return_to URL, since this match is required by OpenId, and the consumer app // may be using HTTP at some times and HTTPS at others. UriBuilder realm = OpenIdUtilities.GetResolvedRealm(this.Page, this.RealmUrl); - realm.Scheme = Page.Request.Url.Scheme; - realm.Port = Page.Request.Url.Port; + realm.Scheme = returnToApproximation.Scheme; + realm.Port = returnToApproximation.Port; // Initiate openid request // We use TryParse here to avoid throwing an exception which @@ -1186,8 +1190,9 @@ if (!openidbox.dnoi_internal.onSubmit()) {{ return false; }} if (string.IsNullOrEmpty(this.ReturnToUrl)) { requests.AddRange(rp.CreateRequests(userSuppliedIdentifier, typedRealm)); } else { - Uri returnTo = new Uri(MessagingUtilities.GetRequestUrlFromContext(), this.ReturnToUrl); - requests.AddRange(rp.CreateRequests(userSuppliedIdentifier, typedRealm, returnTo)); + // Since the user actually gave us a return_to value, + // the "approximation" is exactly what we want. + requests.AddRange(rp.CreateRequests(userSuppliedIdentifier, typedRealm, returnToApproximation)); } // Some OPs may be listed multiple times (one with HTTPS and the other with HTTP, for example). diff --git a/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdTextBox.cs b/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdTextBox.cs index 0294e09..97bca99 100644 --- a/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdTextBox.cs +++ b/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdTextBox.cs @@ -876,12 +876,16 @@ namespace DotNetOpenAuth.OpenId.RelyingParty { try { using (var consumer = this.CreateRelyingParty()) { + // Approximate the returnTo (either based on the customize property or the page URL) + // so we can use it to help with Realm resolution. + Uri returnToApproximation = this.ReturnToUrl != null ? new Uri(MessagingUtilities.GetRequestUrlFromContext(), this.ReturnToUrl) : this.Page.Request.Url; + // Resolve the trust root, and swap out the scheme and port if necessary to match the // return_to URL, since this match is required by OpenId, and the consumer app // may be using HTTP at some times and HTTPS at others. UriBuilder realm = OpenIdUtilities.GetResolvedRealm(this.Page, this.RealmUrl); - realm.Scheme = Page.Request.Url.Scheme; - realm.Port = Page.Request.Url.Port; + realm.Scheme = returnToApproximation.Scheme; + realm.Port = returnToApproximation.Port; // Initiate openid request // We use TryParse here to avoid throwing an exception which @@ -892,8 +896,9 @@ namespace DotNetOpenAuth.OpenId.RelyingParty { if (string.IsNullOrEmpty(this.ReturnToUrl)) { this.Request = consumer.CreateRequest(userSuppliedIdentifier, typedRealm); } else { - Uri returnTo = new Uri(MessagingUtilities.GetRequestUrlFromContext(), this.ReturnToUrl); - this.Request = consumer.CreateRequest(userSuppliedIdentifier, typedRealm, returnTo); + // Since the user actually gave us a return_to value, + // the "approximation" is exactly what we want. + this.Request = consumer.CreateRequest(userSuppliedIdentifier, typedRealm, returnToApproximation); } this.Request.Mode = this.ImmediateMode ? AuthenticationRequestMode.Immediate : AuthenticationRequestMode.Setup; if (this.EnableRequestProfile) { |