summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.OpenId.Provider.UI
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2013-03-26 11:19:06 -0700
committerAndrew Arnott <andrewarnott@gmail.com>2013-03-26 11:19:06 -0700
commit3d37ff45cab6838d80b22e6b782a0b9b4c2f4aeb (patch)
treec15816c3d7f6e74334553f2ff98605ce1c22c538 /src/DotNetOpenAuth.OpenId.Provider.UI
parent5e9014f36b2d53b8e419918675df636540ea24e2 (diff)
parente6f7409f4caceb7bc2a5b4ddbcb1a4097af340f2 (diff)
downloadDotNetOpenAuth-3d37ff45cab6838d80b22e6b782a0b9b4c2f4aeb.zip
DotNetOpenAuth-3d37ff45cab6838d80b22e6b782a0b9b4c2f4aeb.tar.gz
DotNetOpenAuth-3d37ff45cab6838d80b22e6b782a0b9b4c2f4aeb.tar.bz2
Move to HttpClient throughout library.
Diffstat (limited to 'src/DotNetOpenAuth.OpenId.Provider.UI')
-rw-r--r--src/DotNetOpenAuth.OpenId.Provider.UI/DotNetOpenAuth.OpenId.Provider.UI.csproj8
-rw-r--r--src/DotNetOpenAuth.OpenId.Provider.UI/OpenId/Provider/ProviderEndpoint.cs106
-rw-r--r--src/DotNetOpenAuth.OpenId.Provider.UI/packages.config3
3 files changed, 63 insertions, 54 deletions
diff --git a/src/DotNetOpenAuth.OpenId.Provider.UI/DotNetOpenAuth.OpenId.Provider.UI.csproj b/src/DotNetOpenAuth.OpenId.Provider.UI/DotNetOpenAuth.OpenId.Provider.UI.csproj
index 3e0369d..93a0697 100644
--- a/src/DotNetOpenAuth.OpenId.Provider.UI/DotNetOpenAuth.OpenId.Provider.UI.csproj
+++ b/src/DotNetOpenAuth.OpenId.Provider.UI/DotNetOpenAuth.OpenId.Provider.UI.csproj
@@ -52,9 +52,11 @@
</ItemGroup>
<ItemGroup>
<Reference Include="System" />
- <Reference Include="Validation">
- <HintPath>..\packages\Validation.2.0.1.12362\lib\portable-windows8+net40+sl5+windowsphone8\Validation.dll</HintPath>
- <Private>True</Private>
+ <Reference Include="System.Net.Http" />
+ <Reference Include="System.Net.Http.WebRequest" />
+ <Reference Include="Validation, Version=2.0.0.0, Culture=neutral, PublicKeyToken=2fc06f0d701809a7, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\packages\Validation.2.0.2.13022\lib\portable-windows8+net40+sl5+windowsphone8\Validation.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
diff --git a/src/DotNetOpenAuth.OpenId.Provider.UI/OpenId/Provider/ProviderEndpoint.cs b/src/DotNetOpenAuth.OpenId.Provider.UI/OpenId/Provider/ProviderEndpoint.cs
index a29f6e3..603d530 100644
--- a/src/DotNetOpenAuth.OpenId.Provider.UI/OpenId/Provider/ProviderEndpoint.cs
+++ b/src/DotNetOpenAuth.OpenId.Provider.UI/OpenId/Provider/ProviderEndpoint.cs
@@ -8,7 +8,10 @@ namespace DotNetOpenAuth.OpenId.Provider {
using System;
using System.Collections.Generic;
using System.ComponentModel;
+ using System.Net.Http;
using System.Text;
+ using System.Threading;
+ using System.Threading.Tasks;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
@@ -43,12 +46,14 @@ namespace DotNetOpenAuth.OpenId.Provider {
/// <summary>
/// Backing field for the <see cref="Provider"/> property.
/// </summary>
- private static OpenIdProvider provider;
+ private Lazy<OpenIdProvider> provider;
/// <summary>
- /// The lock that must be obtained when initializing the provider field.
+ /// Initializes a new instance of the <see cref="ProviderEndpoint"/> class.
/// </summary>
- private static object providerInitializerLock = new object();
+ public ProviderEndpoint() {
+ this.provider = new Lazy<OpenIdProvider>(this.CreateProvider);
+ }
/// <summary>
/// Fired when an incoming OpenID request is an authentication challenge
@@ -67,22 +72,14 @@ namespace DotNetOpenAuth.OpenId.Provider {
/// Gets or sets the <see cref="OpenIdProvider"/> instance to use for all instances of this control.
/// </summary>
/// <value>The default value is an <see cref="OpenIdProvider"/> instance initialized according to the web.config file.</value>
- public static OpenIdProvider Provider {
+ public OpenIdProvider Provider {
get {
- if (provider == null) {
- lock (providerInitializerLock) {
- if (provider == null) {
- provider = CreateProvider();
- }
- }
- }
-
- return provider;
+ return this.provider.Value;
}
set {
Requires.NotNull(value, "value");
- provider = value;
+ this.provider = new Lazy<OpenIdProvider>(() => value, LazyThreadSafetyMode.PublicationOnly);
}
}
@@ -172,12 +169,16 @@ namespace DotNetOpenAuth.OpenId.Provider {
}
/// <summary>
- /// Sends the response for the <see cref="PendingAuthenticationRequest"/> and clears the property.
+ /// Sends the response for the <see cref="PendingAuthenticationRequest" /> and clears the property.
/// </summary>
- public static void SendResponse() {
+ /// <param name="cancellationToken">The cancellation token.</param>
+ /// <returns>
+ /// The response message.
+ /// </returns>
+ public Task<HttpResponseMessage> PrepareResponseAsync(CancellationToken cancellationToken = default(CancellationToken)) {
var pendingRequest = PendingRequest;
PendingRequest = null;
- Provider.SendResponse(pendingRequest);
+ return this.Provider.PrepareResponseAsync(pendingRequest, cancellationToken);
}
/// <summary>
@@ -189,41 +190,46 @@ namespace DotNetOpenAuth.OpenId.Provider {
protected override void OnLoad(EventArgs e) {
base.OnLoad(e);
- // There is the unusual scenario that this control is hosted by
- // an ASP.NET web page that has other UI on it to that the user
- // might see, including controls that cause a postback to occur.
- // We definitely want to ignore postbacks, since any openid messages
- // they contain will be old.
- if (this.Enabled && !this.Page.IsPostBack) {
- // 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.
- // determine what incoming message was received
- IRequest request = Provider.GetRequest();
- if (request != null) {
- PendingRequest = null;
+ this.Page.RegisterAsyncTask(new PageAsyncTask(async cancellationToken => {
+ // There is the unusual scenario that this control is hosted by
+ // an ASP.NET web page that has other UI on it to that the user
+ // might see, including controls that cause a postback to occur.
+ // We definitely want to ignore postbacks, since any openid messages
+ // they contain will be old.
+ if (this.Enabled && !this.Page.IsPostBack) {
+ // 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.
+ // determine what incoming message was received
+ IRequest request = await Provider.GetRequestAsync(new HttpRequestWrapper(this.Context.Request), cancellationToken);
+ if (request != null) {
+ PendingRequest = null;
- // process the incoming message appropriately and send the response
- IAuthenticationRequest idrequest;
- IAnonymousRequest anonRequest;
- if ((idrequest = request as IAuthenticationRequest) != null) {
- PendingAuthenticationRequest = idrequest;
- this.OnAuthenticationChallenge(idrequest);
- } else if ((anonRequest = request as IAnonymousRequest) != null) {
- PendingAnonymousRequest = anonRequest;
- if (!this.OnAnonymousRequest(anonRequest)) {
- // This is a feature not supported by the OP, so
- // go ahead and set disapproved so we can send a response.
- Logger.OpenId.Warn("An incoming anonymous OpenID request message was detected, but the ProviderEndpoint.AnonymousRequest event is not handled, so returning cancellation message to relying party.");
- anonRequest.IsApproved = false;
+ // process the incoming message appropriately and send the response
+ IAuthenticationRequest idrequest;
+ IAnonymousRequest anonRequest;
+ if ((idrequest = request as IAuthenticationRequest) != null) {
+ PendingAuthenticationRequest = idrequest;
+ this.OnAuthenticationChallenge(idrequest);
+ } else if ((anonRequest = request as IAnonymousRequest) != null) {
+ PendingAnonymousRequest = anonRequest;
+ if (!this.OnAnonymousRequest(anonRequest)) {
+ // This is a feature not supported by the OP, so
+ // go ahead and set disapproved so we can send a response.
+ Logger.OpenId.Warn(
+ "An incoming anonymous OpenID request message was detected, but the ProviderEndpoint.AnonymousRequest event is not handled, so returning cancellation message to relying party.");
+ anonRequest.IsApproved = false;
+ }
+ }
+ if (request.IsResponseReady) {
+ PendingAuthenticationRequest = null;
+ var response = await Provider.PrepareResponseAsync(request, cancellationToken);
+ await response.SendAsync(new HttpContextWrapper(this.Context), cancellationToken);
+ this.Context.Response.End();
}
- }
- if (request.IsResponseReady) {
- PendingAuthenticationRequest = null;
- Provider.SendResponse(request);
}
}
- }
+ }));
}
/// <summary>
@@ -256,8 +262,8 @@ namespace DotNetOpenAuth.OpenId.Provider {
/// Creates the default OpenIdProvider to use.
/// </summary>
/// <returns>The new instance of OpenIdProvider.</returns>
- private static OpenIdProvider CreateProvider() {
- return new OpenIdProvider(OpenIdElement.Configuration.Provider.ApplicationStore.CreateInstance(OpenIdProvider.HttpApplicationStore));
+ private OpenIdProvider CreateProvider() {
+ return new OpenIdProvider(OpenIdElement.Configuration.Provider.ApplicationStore.CreateInstance(OpenIdProvider.GetHttpApplicationStore(new HttpContextWrapper(this.Context)), null));
}
}
}
diff --git a/src/DotNetOpenAuth.OpenId.Provider.UI/packages.config b/src/DotNetOpenAuth.OpenId.Provider.UI/packages.config
index 58890d8..d32d62f 100644
--- a/src/DotNetOpenAuth.OpenId.Provider.UI/packages.config
+++ b/src/DotNetOpenAuth.OpenId.Provider.UI/packages.config
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
- <package id="Validation" version="2.0.1.12362" targetFramework="net45" />
+ <package id="Microsoft.Net.Http" version="2.0.20710.0" targetFramework="net45" />
+ <package id="Validation" version="2.0.2.13022" targetFramework="net45" />
</packages> \ No newline at end of file