summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2009-04-26 14:52:19 -0700
committerAndrew Arnott <andrewarnott@gmail.com>2009-04-26 14:52:19 -0700
commit478bac96d7c00ed333a19021bbe6115dea865ba1 (patch)
tree82675bd8b562a1b8745430aab40d788fd9638cd3
parent6b9e91cc059a489eb5c593d57b72156ecef8d0e3 (diff)
downloadDotNetOpenAuth-478bac96d7c00ed333a19021bbe6115dea865ba1.zip
DotNetOpenAuth-478bac96d7c00ed333a19021bbe6115dea865ba1.tar.gz
DotNetOpenAuth-478bac96d7c00ed333a19021bbe6115dea865ba1.tar.bz2
The auto-respond vs. intercept setting for checkid messages works now.
-rw-r--r--samples/OpenIdOfflineProvider/CheckIdWindow.xaml.cs12
-rw-r--r--samples/OpenIdOfflineProvider/HostedProvider.cs28
-rw-r--r--samples/OpenIdOfflineProvider/MainWindow.xaml.cs32
3 files changed, 44 insertions, 28 deletions
diff --git a/samples/OpenIdOfflineProvider/CheckIdWindow.xaml.cs b/samples/OpenIdOfflineProvider/CheckIdWindow.xaml.cs
index 279f15f..6bab2ae 100644
--- a/samples/OpenIdOfflineProvider/CheckIdWindow.xaml.cs
+++ b/samples/OpenIdOfflineProvider/CheckIdWindow.xaml.cs
@@ -55,11 +55,17 @@ namespace DotNetOpenAuth.OpenIdOfflineProvider {
/// </summary>
/// <param name="provider">The OpenID Provider host.</param>
/// <param name="request">The incoming authentication request.</param>
- internal static void ProcessAuthentication(HostedProvider provider, IAuthenticationRequest request) {
+ /// <param name="skipUI">if set to <c>true</c> no dialog should be displayed to the user.</param>
+ internal static void ProcessAuthentication(HostedProvider provider, IAuthenticationRequest request, bool skipUI) {
Contract.Requires(provider != null);
Contract.Requires(request != null);
- App.Current.Dispatcher.Invoke((Action)delegate {
+ if (skipUI) {
+ if (request.IsDirectedIdentity) {
+ throw new NotImplementedException();
+ }
+ request.IsAuthenticated = true;
+ } else {
var window = new CheckIdWindow(provider, request);
bool? result = window.ShowDialog();
@@ -74,7 +80,7 @@ namespace DotNetOpenAuth.OpenIdOfflineProvider {
request.ClaimedIdentifier = window.claimedIdentifierBox.Text;
request.LocalIdentifier = window.localIdentifierBox.Text;
}
- });
+ }
}
/// <summary>
diff --git a/samples/OpenIdOfflineProvider/HostedProvider.cs b/samples/OpenIdOfflineProvider/HostedProvider.cs
index 5efaf9b..785932e 100644
--- a/samples/OpenIdOfflineProvider/HostedProvider.cs
+++ b/samples/OpenIdOfflineProvider/HostedProvider.cs
@@ -40,11 +40,6 @@ namespace DotNetOpenAuth.OpenIdOfflineProvider {
private OpenIdProvider provider = new OpenIdProvider(new StandardProviderApplicationStore());
/// <summary>
- /// The logger the class may use.
- /// </summary>
- private ILog logger = log4net.LogManager.GetLogger(typeof(HostedProvider));
-
- /// <summary>
/// The HTTP listener that acts as the OpenID Provider socket.
/// </summary>
private HttpHost httpHost;
@@ -85,7 +80,7 @@ namespace DotNetOpenAuth.OpenIdOfflineProvider {
/// <summary>
/// Gets or sets the delegate that handles authentication requests.
/// </summary>
- internal Action<IAuthenticationRequest> ProcessAuthenticationRequest { get; set; }
+ internal Action<HttpRequestInfo, HttpListenerResponse> ProcessRequest { get; set; }
/// <summary>
/// Gets the OP identifier.
@@ -212,7 +207,7 @@ namespace DotNetOpenAuth.OpenIdOfflineProvider {
private void RequestHandler(HttpListenerContext context) {
Contract.Requires(context != null);
Contract.Requires(context.Response.OutputStream != null);
- Contract.Requires(this.ProcessAuthenticationRequest != null);
+ Contract.Requires(this.ProcessRequest != null);
Stream outputStream = context.Response.OutputStream;
Contract.Assume(outputStream != null); // CC static verification shortcoming.
@@ -225,22 +220,7 @@ namespace DotNetOpenAuth.OpenIdOfflineProvider {
if (context.Request.Url.AbsolutePath == ProviderPath) {
HttpRequestInfo requestInfo = new HttpRequestInfo(context.Request);
- IRequest providerRequest = this.Provider.GetRequest(requestInfo);
- if (providerRequest == null) {
- App.Logger.Error("A request came in that did not carry an OpenID message.");
- context.Response.StatusCode = (int)HttpStatusCode.BadRequest;
- using (StreamWriter sw = new StreamWriter(outputStream)) {
- sw.WriteLine("<html><body>This is an OpenID Provider endpoint.</body></html>");
- }
- return;
- }
-
- if (!providerRequest.IsResponseReady) {
- var authRequest = (IAuthenticationRequest)providerRequest;
- this.ProcessAuthenticationRequest(authRequest);
- }
-
- this.Provider.PrepareResponse(providerRequest).Send(context.Response);
+ this.ProcessRequest(requestInfo, context.Response);
} else if (context.Request.Url.AbsolutePath.StartsWith(UserIdentifierPath, StringComparison.Ordinal)) {
using (StreamWriter sw = new StreamWriter(outputStream)) {
context.Response.StatusCode = (int)HttpStatusCode.OK;
@@ -253,7 +233,7 @@ namespace DotNetOpenAuth.OpenIdOfflineProvider {
} else if (context.Request.Url == this.OPIdentifier) {
context.Response.ContentType = DotNetOpenAuth.Yadis.ContentTypes.Xrds;
context.Response.StatusCode = (int)HttpStatusCode.OK;
- this.logger.Info("Discovery on OP Identifier detected.");
+ App.Logger.Info("Discovery on OP Identifier detected.");
using (StreamWriter sw = new StreamWriter(outputStream)) {
sw.Write(GenerateXrdsOPIdentifierDocument(providerEndpoint, Enumerable.Empty<string>()));
}
diff --git a/samples/OpenIdOfflineProvider/MainWindow.xaml.cs b/samples/OpenIdOfflineProvider/MainWindow.xaml.cs
index bd4f0a0..6018c20 100644
--- a/samples/OpenIdOfflineProvider/MainWindow.xaml.cs
+++ b/samples/OpenIdOfflineProvider/MainWindow.xaml.cs
@@ -23,6 +23,8 @@ namespace DotNetOpenAuth.OpenIdOfflineProvider {
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
+ using DotNetOpenAuth.Messaging;
+ using DotNetOpenAuth.OpenId.Provider;
using log4net;
using log4net.Appender;
using log4net.Core;
@@ -46,7 +48,7 @@ namespace DotNetOpenAuth.OpenIdOfflineProvider {
/// </summary>
public MainWindow() {
this.InitializeComponent();
- this.hostedProvider.ProcessAuthenticationRequest = request => CheckIdWindow.ProcessAuthentication(this.hostedProvider, request);
+ this.hostedProvider.ProcessRequest = this.ProcessRequest;
TextWriterAppender boxLogger = log4net.LogManager.GetRepository().GetAppenders().OfType<TextWriterAppender>().FirstOrDefault(a => a.Name == "TextBoxAppender");
if (boxLogger != null) {
boxLogger.Writer = new TextBoxTextWriter(logBox);
@@ -91,6 +93,34 @@ namespace DotNetOpenAuth.OpenIdOfflineProvider {
}
/// <summary>
+ /// Processes an incoming request at the OpenID Provider endpoint.
+ /// </summary>
+ /// <param name="requestInfo">The request info.</param>
+ /// <param name="response">The response.</param>
+ private void ProcessRequest(HttpRequestInfo requestInfo, HttpListenerResponse response) {
+ IRequest request = this.hostedProvider.Provider.GetRequest(requestInfo);
+ if (request == null) {
+ App.Logger.Error("A request came in that did not carry an OpenID message.");
+ response.StatusCode = (int)HttpStatusCode.BadRequest;
+ using (StreamWriter sw = new StreamWriter(response.OutputStream)) {
+ sw.WriteLine("<html><body>This is an OpenID Provider endpoint.</body></html>");
+ }
+ return;
+ }
+
+ this.Dispatcher.Invoke((Action)delegate {
+ if (!request.IsResponseReady) {
+ var authRequest = request as IAuthenticationRequest;
+ if (authRequest != null) {
+ CheckIdWindow.ProcessAuthentication(this.hostedProvider, authRequest, checkidRequestList.SelectedIndex == 0);
+ }
+ }
+ });
+
+ this.hostedProvider.Provider.PrepareResponse(request).Send(response);
+ }
+
+ /// <summary>
/// Starts the provider.
/// </summary>
private void startProvider() {