diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2009-02-05 08:03:54 -0800 |
---|---|---|
committer | Andrew Arnott <andrewarnott@gmail.com> | 2009-02-05 08:03:54 -0800 |
commit | f63e1944066d0b74fa28c287b58d47030df1ea94 (patch) | |
tree | 4943e9f3bf1d357bb3eb39d1e79444c7bcba06f1 /src | |
parent | dd2bfbfbbc86a9d1801da5a257561d6746524f89 (diff) | |
download | DotNetOpenAuth-f63e1944066d0b74fa28c287b58d47030df1ea94.zip DotNetOpenAuth-f63e1944066d0b74fa28c287b58d47030df1ea94.tar.gz DotNetOpenAuth-f63e1944066d0b74fa28c287b58d47030df1ea94.tar.bz2 |
Channel now implements IDisposable and disposes the necessary binding elements.
All users of the channel also implement and call Dispose as necessary.
Work for future: Fix up samples and controls to reuse a static instance of OP and RP facade classes since they are now thread-safe.
Diffstat (limited to 'src')
-rw-r--r-- | src/DotNetOpenAuth/Messaging/Channel.cs | 27 | ||||
-rw-r--r-- | src/DotNetOpenAuth/OAuth/ConsumerBase.cs | 24 | ||||
-rw-r--r-- | src/DotNetOpenAuth/OAuth/ServiceProvider.cs | 24 | ||||
-rw-r--r-- | src/DotNetOpenAuth/OpenId/Provider/OpenIdProvider.cs | 24 | ||||
-rw-r--r-- | src/DotNetOpenAuth/OpenId/Provider/ProviderEndpoint.cs | 34 | ||||
-rw-r--r-- | src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdAjaxTextBox.cs | 114 | ||||
-rw-r--r-- | src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdRelyingParty.cs | 24 | ||||
-rw-r--r-- | src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdTextBox.cs | 105 |
8 files changed, 246 insertions, 130 deletions
diff --git a/src/DotNetOpenAuth/Messaging/Channel.cs b/src/DotNetOpenAuth/Messaging/Channel.cs index d5e6c09..8e55112 100644 --- a/src/DotNetOpenAuth/Messaging/Channel.cs +++ b/src/DotNetOpenAuth/Messaging/Channel.cs @@ -23,7 +23,7 @@ namespace DotNetOpenAuth.Messaging { /// <summary> /// Manages sending direct messages to a remote party and receiving responses. /// </summary> - public abstract class Channel { + public abstract class Channel : IDisposable { /// <summary> /// The encoding to use when writing out POST entity strings. /// </summary> @@ -356,6 +356,18 @@ namespace DotNetOpenAuth.Messaging { return responseMessage; } + #region IDisposable Members + + /// <summary> + /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. + /// </summary> + public void Dispose() { + this.Dispose(true); + GC.SuppressFinalize(true); + } + + #endregion + /// <summary> /// Gets the current HTTP request being processed. /// </summary> @@ -372,6 +384,19 @@ namespace DotNetOpenAuth.Messaging { } /// <summary> + /// Releases unmanaged and - optionally - managed resources + /// </summary> + /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param> + protected virtual void Dispose(bool disposing) { + if (disposing) { + // Call dispose on any binding elements that need it. + foreach (IDisposable bindingElement in this.BindingElements.OfType<IDisposable>()) { + bindingElement.Dispose(); + } + } + } + + /// <summary> /// Fires the <see cref="Sending"/> event. /// </summary> /// <param name="message">The message about to be encoded and sent.</param> diff --git a/src/DotNetOpenAuth/OAuth/ConsumerBase.cs b/src/DotNetOpenAuth/OAuth/ConsumerBase.cs index c995066..ae2e1d1 100644 --- a/src/DotNetOpenAuth/OAuth/ConsumerBase.cs +++ b/src/DotNetOpenAuth/OAuth/ConsumerBase.cs @@ -17,7 +17,7 @@ namespace DotNetOpenAuth.OAuth { /// <summary> /// Base class for <see cref="WebConsumer"/> and <see cref="DesktopConsumer"/> types. /// </summary> - public class ConsumerBase { + public class ConsumerBase : IDisposable { /// <summary> /// Initializes a new instance of the <see cref="ConsumerBase"/> class. /// </summary> @@ -162,5 +162,27 @@ namespace DotNetOpenAuth.OAuth { this.TokenManager.ExpireRequestTokenAndStoreNewAccessToken(this.ConsumerKey, requestToken, grantAccess.AccessToken, grantAccess.TokenSecret); return grantAccess; } + + #region IDisposable Members + + /// <summary> + /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. + /// </summary> + public void Dispose() { + this.Dispose(true); + GC.SuppressFinalize(this); + } + + /// <summary> + /// Releases unmanaged and - optionally - managed resources + /// </summary> + /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param> + protected virtual void Dispose(bool disposing) { + if (disposing) { + this.Channel.Dispose(); + } + } + + #endregion } } diff --git a/src/DotNetOpenAuth/OAuth/ServiceProvider.cs b/src/DotNetOpenAuth/OAuth/ServiceProvider.cs index 182f5d4..9a706fe 100644 --- a/src/DotNetOpenAuth/OAuth/ServiceProvider.cs +++ b/src/DotNetOpenAuth/OAuth/ServiceProvider.cs @@ -26,7 +26,7 @@ namespace DotNetOpenAuth.OAuth { /// <item>Any additional request parameters that the Service Provider requires in order to obtain a Token. Service Provider specific parameters MUST NOT begin with oauth_.</item> /// </list> /// </remarks> - public class ServiceProvider { + public class ServiceProvider : IDisposable { /// <summary> /// The field behind the <see cref="OAuthChannel"/> property. /// </summary> @@ -392,5 +392,27 @@ namespace DotNetOpenAuth.OAuth { this.TokenManager.StoreNewRequestToken(grantRequestTokenResponse.RequestMessage, grantRequestTokenResponse); } } + + #region IDisposable Members + + /// <summary> + /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. + /// </summary> + public void Dispose() { + this.Dispose(true); + GC.SuppressFinalize(this); + } + + /// <summary> + /// Releases unmanaged and - optionally - managed resources + /// </summary> + /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param> + protected virtual void Dispose(bool disposing) { + if (disposing) { + this.Channel.Dispose(); + } + } + + #endregion } } diff --git a/src/DotNetOpenAuth/OpenId/Provider/OpenIdProvider.cs b/src/DotNetOpenAuth/OpenId/Provider/OpenIdProvider.cs index 4744a4f..3e4e570 100644 --- a/src/DotNetOpenAuth/OpenId/Provider/OpenIdProvider.cs +++ b/src/DotNetOpenAuth/OpenId/Provider/OpenIdProvider.cs @@ -18,7 +18,7 @@ namespace DotNetOpenAuth.OpenId.Provider { /// <summary> /// Offers services for a web page that is acting as an OpenID identity server. /// </summary> - public sealed class OpenIdProvider { + public sealed class OpenIdProvider : IDisposable { /// <summary> /// The name of the key to use in the HttpApplication cache to store the /// instance of <see cref="StandardProviderApplicationStore"/> to use. @@ -232,5 +232,27 @@ namespace DotNetOpenAuth.OpenId.Provider { return this.Channel.PrepareResponse(positiveAssertion); } + + #region IDisposable Members + + /// <summary> + /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. + /// </summary> + public void Dispose() { + this.Dispose(true); + GC.SuppressFinalize(this); + } + + /// <summary> + /// Releases unmanaged and - optionally - managed resources + /// </summary> + /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param> + private void Dispose(bool disposing) { + if (disposing) { + this.Channel.Dispose(); + } + } + + #endregion } } diff --git a/src/DotNetOpenAuth/OpenId/Provider/ProviderEndpoint.cs b/src/DotNetOpenAuth/OpenId/Provider/ProviderEndpoint.cs index 90d4b23..eef73e9 100644 --- a/src/DotNetOpenAuth/OpenId/Provider/ProviderEndpoint.cs +++ b/src/DotNetOpenAuth/OpenId/Provider/ProviderEndpoint.cs @@ -97,23 +97,23 @@ namespace DotNetOpenAuth.OpenId.Provider { // Use the explicitly given state store on this control if there is one. // Then try the configuration file specified one. Finally, use the default // in-memory one that's built into OpenIdProvider. - OpenIdProvider provider = new OpenIdProvider(this.CustomApplicationStore ?? DotNetOpenAuthSection.Configuration.OpenId.Provider.ApplicationStore.CreateInstance(OpenIdProvider.HttpApplicationStore)); - - // determine what incoming message was received - IRequest request = provider.GetRequest(); - if (request != null) { - // process the incoming message appropriately and send the response - if (!request.IsResponseReady) { - var idrequest = (IAuthenticationRequest)request; - PendingAuthenticationRequest = idrequest; - this.OnAuthenticationChallenge(idrequest); - } else { - PendingAuthenticationRequest = null; - } - if (request.IsResponseReady) { - request.Response.Send(); - Page.Response.End(); - PendingAuthenticationRequest = null; + using (OpenIdProvider provider = new OpenIdProvider(this.CustomApplicationStore ?? DotNetOpenAuthSection.Configuration.OpenId.Provider.ApplicationStore.CreateInstance(OpenIdProvider.HttpApplicationStore))) { + // determine what incoming message was received + IRequest request = provider.GetRequest(); + if (request != null) { + // process the incoming message appropriately and send the response + if (!request.IsResponseReady) { + var idrequest = (IAuthenticationRequest)request; + PendingAuthenticationRequest = idrequest; + this.OnAuthenticationChallenge(idrequest); + } else { + PendingAuthenticationRequest = null; + } + if (request.IsResponseReady) { + request.Response.Send(); + Page.Response.End(); + PendingAuthenticationRequest = null; + } } } } diff --git a/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdAjaxTextBox.cs b/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdAjaxTextBox.cs index 42342dd..f30d4fd 100644 --- a/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdAjaxTextBox.cs +++ b/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdAjaxTextBox.cs @@ -353,12 +353,13 @@ namespace DotNetOpenAuth.OpenId.RelyingParty { HttpRequestInfo clientResponseInfo = new HttpRequestInfo { Url = authUri, }; - var rp = CreateRelyingParty(true); - this.authenticationResponse = rp.GetResponse(clientResponseInfo); + using (var rp = CreateRelyingParty(true)) { + this.authenticationResponse = rp.GetResponse(clientResponseInfo); - // Save out the authentication response to viewstate so we can find it on - // a subsequent postback. - this.ViewState[AuthenticationResponseViewStateKey] = new AuthenticationResponseSnapshot(this.authenticationResponse); + // Save out the authentication response to viewstate so we can find it on + // a subsequent postback. + this.ViewState[AuthenticationResponseViewStateKey] = new AuthenticationResponseSnapshot(this.authenticationResponse); + } } else { this.authenticationResponse = viewstateResponse; } @@ -1170,49 +1171,49 @@ if (!openidbox.dnoi_internal.onSubmit()) {{ return false; }} private List<IAuthenticationRequest> CreateRequests(string userSuppliedIdentifier, bool immediate) { var requests = new List<IAuthenticationRequest>(); - OpenIdRelyingParty rp = CreateRelyingParty(true); - - // 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; - - // Initiate openid request - // We use TryParse here to avoid throwing an exception which - // might slip through our validator control if it is disabled. - Realm typedRealm = new Realm(realm); - 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)); - } + using (OpenIdRelyingParty rp = CreateRelyingParty(true)) { + // 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; + + // Initiate openid request + // We use TryParse here to avoid throwing an exception which + // might slip through our validator control if it is disabled. + Realm typedRealm = new Realm(realm); + 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)); + } - // Some OPs may be listed multiple times (one with HTTPS and the other with HTTP, for example). - // Since we're gathering OPs to try one after the other, just take the first choice of each OP - // and don't try it multiple times. - requests = RemoveDuplicateEndpoints(requests); + // Some OPs may be listed multiple times (one with HTTPS and the other with HTTP, for example). + // Since we're gathering OPs to try one after the other, just take the first choice of each OP + // and don't try it multiple times. + requests = RemoveDuplicateEndpoints(requests); - // Configure each generated request. - int reqIndex = 0; - foreach (var req in requests) { - req.AddCallbackArguments("index", (reqIndex++).ToString(CultureInfo.InvariantCulture)); + // Configure each generated request. + int reqIndex = 0; + foreach (var req in requests) { + req.AddCallbackArguments("index", (reqIndex++).ToString(CultureInfo.InvariantCulture)); - // If the ReturnToUrl was explicitly set, we'll need to reset our first parameter - if (string.IsNullOrEmpty(HttpUtility.ParseQueryString(req.ReturnToUrl.Query)["dotnetopenid.userSuppliedIdentifier"])) { - req.AddCallbackArguments("dotnetopenid.userSuppliedIdentifier", userSuppliedIdentifier); - } + // If the ReturnToUrl was explicitly set, we'll need to reset our first parameter + if (string.IsNullOrEmpty(HttpUtility.ParseQueryString(req.ReturnToUrl.Query)["dotnetopenid.userSuppliedIdentifier"])) { + req.AddCallbackArguments("dotnetopenid.userSuppliedIdentifier", userSuppliedIdentifier); + } - // Our javascript needs to let the user know which endpoint responded. So we force it here. - // This gives us the info even for 1.0 OPs and 2.0 setup_required responses. - req.AddCallbackArguments("dotnetopenid.op_endpoint", req.Provider.Uri.AbsoluteUri); - req.AddCallbackArguments("dotnetopenid.claimed_id", req.ClaimedIdentifier); - req.AddCallbackArguments("dotnetopenid.phase", "2"); - if (immediate) { - req.Mode = AuthenticationRequestMode.Immediate; - ((AuthenticationRequest)req).AssociationPreference = AssociationPreference.IfAlreadyEstablished; + // Our javascript needs to let the user know which endpoint responded. So we force it here. + // This gives us the info even for 1.0 OPs and 2.0 setup_required responses. + req.AddCallbackArguments("dotnetopenid.op_endpoint", req.Provider.Uri.AbsoluteUri); + req.AddCallbackArguments("dotnetopenid.claimed_id", req.ClaimedIdentifier); + req.AddCallbackArguments("dotnetopenid.phase", "2"); + if (immediate) { + req.Mode = AuthenticationRequestMode.Immediate; + ((AuthenticationRequest)req).AssociationPreference = AssociationPreference.IfAlreadyEstablished; + } } } @@ -1226,19 +1227,20 @@ if (!openidbox.dnoi_internal.onSubmit()) {{ return false; }} Logger.InfoFormat("AJAX (iframe) callback from OP: {0}", this.Page.Request.Url); List<string> assignments = new List<string>(); - OpenIdRelyingParty rp = CreateRelyingParty(false); - var f = HttpUtility.ParseQueryString(this.Page.Request.Url.Query).ToDictionary(); - var authResponse = rp.GetResponse(); - if (authResponse.Status == AuthenticationStatus.Authenticated) { - this.OnUnconfirmedPositiveAssertion(); - foreach (var pair in this.clientScriptExtensions) { - IClientScriptExtensionResponse extension = (IClientScriptExtensionResponse)authResponse.GetExtension(pair.Key); - var positiveResponse = (PositiveAuthenticationResponse)authResponse; - string js = extension.InitializeJavaScriptData(positiveResponse.Response); - if (string.IsNullOrEmpty(js)) { - js = "null"; + using (OpenIdRelyingParty rp = CreateRelyingParty(false)) { + var f = HttpUtility.ParseQueryString(this.Page.Request.Url.Query).ToDictionary(); + var authResponse = rp.GetResponse(); + if (authResponse.Status == AuthenticationStatus.Authenticated) { + this.OnUnconfirmedPositiveAssertion(); + foreach (var pair in this.clientScriptExtensions) { + IClientScriptExtensionResponse extension = (IClientScriptExtensionResponse)authResponse.GetExtension(pair.Key); + var positiveResponse = (PositiveAuthenticationResponse)authResponse; + string js = extension.InitializeJavaScriptData(positiveResponse.Response); + if (string.IsNullOrEmpty(js)) { + js = "null"; + } + assignments.Add(pair.Value + " = " + js); } - assignments.Add(pair.Value + " = " + js); } } diff --git a/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdRelyingParty.cs b/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdRelyingParty.cs index 9166be8..7b3d62f 100644 --- a/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdRelyingParty.cs +++ b/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdRelyingParty.cs @@ -31,7 +31,7 @@ namespace DotNetOpenAuth.OpenId.RelyingParty { /// <summary> /// Provides the programmatic facilities to act as an OpenId consumer. /// </summary> - public sealed class OpenIdRelyingParty { + public sealed class OpenIdRelyingParty : IDisposable { /// <summary> /// The name of the key to use in the HttpApplication cache to store the /// instance of <see cref="StandardRelyingPartyApplicationStore"/> to use. @@ -478,5 +478,27 @@ namespace DotNetOpenAuth.OpenId.RelyingParty { return this.CreateRequests(userSuppliedIdentifier, new Realm(realmUrl.Uri)); } + + #region IDisposable Members + + /// <summary> + /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. + /// </summary> + public void Dispose() { + this.Dispose(true); + GC.SuppressFinalize(this); + } + + /// <summary> + /// Releases unmanaged and - optionally - managed resources + /// </summary> + /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param> + private void Dispose(bool disposing) { + if (disposing) { + this.Channel.Dispose(); + } + } + + #endregion } } diff --git a/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdTextBox.cs b/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdTextBox.cs index fe79658..a632599 100644 --- a/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdTextBox.cs +++ b/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdTextBox.cs @@ -874,37 +874,37 @@ namespace DotNetOpenAuth.OpenId.RelyingParty { ErrorUtilities.VerifyOperation(!string.IsNullOrEmpty(this.Text), OpenIdStrings.OpenIdTextBoxEmpty); try { - var consumer = this.CreateRelyingParty(); - - // 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; - - // Initiate openid request - // We use TryParse here to avoid throwing an exception which - // might slip through our validator control if it is disabled. - Identifier userSuppliedIdentifier; - if (Identifier.TryParse(this.Text, out userSuppliedIdentifier)) { - Realm typedRealm = new Realm(realm); - if (string.IsNullOrEmpty(this.ReturnToUrl)) { - this.Request = consumer.CreateRequest(userSuppliedIdentifier, typedRealm); + using (var consumer = this.CreateRelyingParty()) { + // 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; + + // Initiate openid request + // We use TryParse here to avoid throwing an exception which + // might slip through our validator control if it is disabled. + Identifier userSuppliedIdentifier; + if (Identifier.TryParse(this.Text, out userSuppliedIdentifier)) { + Realm typedRealm = new Realm(realm); + 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); + } + this.Request.Mode = this.ImmediateMode ? AuthenticationRequestMode.Immediate : AuthenticationRequestMode.Setup; + if (this.EnableRequestProfile) { + this.AddProfileArgs(this.Request); + } + + // Add state that needs to survive across the redirect. + this.Request.AddCallbackArguments(UsePersistentCookieCallbackKey, this.UsePersistentCookie.ToString(CultureInfo.InvariantCulture)); } else { - Uri returnTo = new Uri(MessagingUtilities.GetRequestUrlFromContext(), this.ReturnToUrl); - this.Request = consumer.CreateRequest(userSuppliedIdentifier, typedRealm, returnTo); + Logger.WarnFormat("An invalid identifier was entered ({0}), but not caught by any validation routine.", this.Text); + this.Request = null; } - this.Request.Mode = this.ImmediateMode ? AuthenticationRequestMode.Immediate : AuthenticationRequestMode.Setup; - if (this.EnableRequestProfile) { - this.AddProfileArgs(this.Request); - } - - // Add state that needs to survive across the redirect. - this.Request.AddCallbackArguments(UsePersistentCookieCallbackKey, this.UsePersistentCookie.ToString(CultureInfo.InvariantCulture)); - } else { - Logger.WarnFormat("An invalid identifier was entered ({0}), but not caught by any validation routine.", this.Text); - this.Request = null; } } catch (ProtocolException ex) { this.OnFailed(new FailedAuthenticationResponse(ex)); @@ -962,30 +962,31 @@ namespace DotNetOpenAuth.OpenId.RelyingParty { return; } - var rp = this.CreateRelyingParty(); - var response = rp.GetResponse(); - if (response != null) { - string persistentString = response.GetCallbackArgument(UsePersistentCookieCallbackKey); - bool persistentBool; - if (persistentString != null && bool.TryParse(persistentString, out persistentBool)) { - this.UsePersistentCookie = persistentBool; - } + using (var rp = this.CreateRelyingParty()) { + var response = rp.GetResponse(); + if (response != null) { + string persistentString = response.GetCallbackArgument(UsePersistentCookieCallbackKey); + bool persistentBool; + if (persistentString != null && bool.TryParse(persistentString, out persistentBool)) { + this.UsePersistentCookie = persistentBool; + } - switch (response.Status) { - case AuthenticationStatus.Canceled: - this.OnCanceled(response); - break; - case AuthenticationStatus.Authenticated: - this.OnLoggedIn(response); - break; - case AuthenticationStatus.SetupRequired: - this.OnSetupRequired(response); - break; - case AuthenticationStatus.Failed: - this.OnFailed(response); - break; - default: - throw new InvalidOperationException("Unexpected response status code."); + switch (response.Status) { + case AuthenticationStatus.Canceled: + this.OnCanceled(response); + break; + case AuthenticationStatus.Authenticated: + this.OnLoggedIn(response); + break; + case AuthenticationStatus.SetupRequired: + this.OnSetupRequired(response); + break; + case AuthenticationStatus.Failed: + this.OnFailed(response); + break; + default: + throw new InvalidOperationException("Unexpected response status code."); + } } } } |