summaryrefslogtreecommitdiffstats
path: root/samples/OpenIdOfflineProvider
diff options
context:
space:
mode:
Diffstat (limited to 'samples/OpenIdOfflineProvider')
-rw-r--r--samples/OpenIdOfflineProvider/App.config37
-rw-r--r--samples/OpenIdOfflineProvider/App.xaml8
-rw-r--r--samples/OpenIdOfflineProvider/App.xaml.cs33
-rw-r--r--samples/OpenIdOfflineProvider/CheckIdWindow.xaml84
-rw-r--r--samples/OpenIdOfflineProvider/CheckIdWindow.xaml.cs91
-rw-r--r--samples/OpenIdOfflineProvider/HostedProvider.cs253
-rw-r--r--samples/OpenIdOfflineProvider/HttpHost.cs140
-rw-r--r--samples/OpenIdOfflineProvider/MainWindow.xaml25
-rw-r--r--samples/OpenIdOfflineProvider/MainWindow.xaml.cs173
-rw-r--r--samples/OpenIdOfflineProvider/NativeMethods.cs60
-rw-r--r--samples/OpenIdOfflineProvider/OpenIdOfflineProvider.csproj165
-rw-r--r--samples/OpenIdOfflineProvider/Properties/AssemblyInfo.cs40
-rw-r--r--samples/OpenIdOfflineProvider/Properties/Resources.Designer.cs63
-rw-r--r--samples/OpenIdOfflineProvider/Properties/Resources.resx117
-rw-r--r--samples/OpenIdOfflineProvider/Properties/Settings.Designer.cs26
-rw-r--r--samples/OpenIdOfflineProvider/Properties/Settings.settings7
-rw-r--r--samples/OpenIdOfflineProvider/Settings.StyleCop19
-rw-r--r--samples/OpenIdOfflineProvider/TextBoxTextWriter.cs87
-rw-r--r--samples/OpenIdOfflineProvider/openid.icobin0 -> 17006 bytes
19 files changed, 1428 insertions, 0 deletions
diff --git a/samples/OpenIdOfflineProvider/App.config b/samples/OpenIdOfflineProvider/App.config
new file mode 100644
index 0000000..cd04b13
--- /dev/null
+++ b/samples/OpenIdOfflineProvider/App.config
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<configuration>
+ <configSections>
+ <section name="dotNetOpenAuth" type="DotNetOpenAuth.Configuration.DotNetOpenAuthSection, DotNetOpenAuth" requirePermission="false" allowLocation="true"/>
+ <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" requirePermission="false"/>
+ </configSections>
+ <dotNetOpenAuth>
+ <messaging>
+ <untrustedWebRequest>
+ <whitelistHosts>
+ <!-- since this is a tool designed for local use and will often be used with localhost -->
+ <add name="localhost" />
+ </whitelistHosts>
+ </untrustedWebRequest>
+ </messaging>
+ </dotNetOpenAuth>
+ <log4net>
+ <appender name="TextBoxAppender" type="log4net.Appender.TextWriterAppender">
+ <immediateFlush value="true" />
+ <layout type="log4net.Layout.PatternLayout">
+ <conversionPattern value="%-5level %message%newline" />
+ </layout>
+ </appender>
+ <!-- Setup the root category, add the appenders and set the default level -->
+ <root>
+ <level value="Info" />
+ <appender-ref ref="TextBoxAppender" />
+ </root>
+ <!-- Specify the level for some specific categories -->
+ <logger name="DotNetOpenAuth">
+ <level value="INFO" />
+ </logger>
+ <logger name="DotNetOpenAuth.OpenId.ChannelElements.SigningBindingElement">
+ <level value="WARN" />
+ </logger>
+ </log4net>
+</configuration> \ No newline at end of file
diff --git a/samples/OpenIdOfflineProvider/App.xaml b/samples/OpenIdOfflineProvider/App.xaml
new file mode 100644
index 0000000..a23f243
--- /dev/null
+++ b/samples/OpenIdOfflineProvider/App.xaml
@@ -0,0 +1,8 @@
+<Application x:Class="DotNetOpenAuth.OpenIdOfflineProvider.App"
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ StartupUri="MainWindow.xaml">
+ <Application.Resources>
+
+ </Application.Resources>
+</Application>
diff --git a/samples/OpenIdOfflineProvider/App.xaml.cs b/samples/OpenIdOfflineProvider/App.xaml.cs
new file mode 100644
index 0000000..ed0f25a
--- /dev/null
+++ b/samples/OpenIdOfflineProvider/App.xaml.cs
@@ -0,0 +1,33 @@
+//-----------------------------------------------------------------------
+// <copyright file="App.xaml.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOpenAuth.OpenIdOfflineProvider {
+ using System;
+ using System.Collections.Generic;
+ using System.Configuration;
+ using System.Data;
+ using System.Linq;
+ using System.Windows;
+ using log4net;
+ using log4net.Core;
+
+ /// <summary>
+ /// Interaction logic for App.xaml
+ /// </summary>
+ public partial class App : Application {
+ /// <summary>
+ /// Message logger.
+ /// </summary>
+ internal static ILog Logger = log4net.LogManager.GetLogger(typeof(App));
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="App"/> class.
+ /// </summary>
+ public App() {
+ log4net.Config.XmlConfigurator.Configure();
+ }
+ }
+}
diff --git a/samples/OpenIdOfflineProvider/CheckIdWindow.xaml b/samples/OpenIdOfflineProvider/CheckIdWindow.xaml
new file mode 100644
index 0000000..29e5126
--- /dev/null
+++ b/samples/OpenIdOfflineProvider/CheckIdWindow.xaml
@@ -0,0 +1,84 @@
+<Window x:Class="DotNetOpenAuth.OpenIdOfflineProvider.CheckIdWindow"
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ Title="Authentication request" Height="345" Width="379" ShowInTaskbar="False">
+ <DockPanel Margin="12">
+ <TextBlock DockPanel.Dock="Top" TextWrapping="Wrap">An authentication request has been received. How do you want to proceed?</TextBlock>
+ <Expander DockPanel.Dock="Top" Header="View request details" IsExpanded="True">
+ <Grid>
+ <Grid.RowDefinitions>
+ <RowDefinition Height="auto" />
+ <RowDefinition Height="auto" />
+ <RowDefinition Height="auto" />
+ <RowDefinition Height="auto" />
+ <RowDefinition Height="auto" />
+ </Grid.RowDefinitions>
+ <Grid.ColumnDefinitions>
+ <ColumnDefinition Width="auto" />
+ <ColumnDefinition />
+ </Grid.ColumnDefinitions>
+ <Label>Immediate?</Label>
+ <Label Grid.Column="1" Name="immediateModeLabel" Content="Yes" />
+ <Label Grid.Column="1" Name="setupModeLabel" Content="No" />
+ <Label Grid.Row="1">Realm</Label>
+ <Label Grid.Row="1" Grid.Column="1" Name="realmLabel" />
+ <!--<Label Grid.Row="2">Callback</Label>
+ <Label Grid.Row="2" Grid.Column="1" Name="callbackLabel" />-->
+ <Label Grid.Row="3">Discoverable</Label>
+ <Label Grid.Row="3" Grid.Column="1" Name="discoverableYesLabel" Content="Yes" />
+ <Label Grid.Row="3" Grid.Column="1" Name="discoverableNoLabel" Content="No" />
+ <!--<Label Grid.Row="4">Shared association?</Label>
+ <Label Grid.Row="4" Grid.Column="1" Name="sharedAssociationLabel" Content="Yes" />
+ <Label Grid.Row="4" Grid.Column="1" Name="privateAssociationLabel" Content="No" />-->
+ </Grid>
+ </Expander>
+ <StackPanel DockPanel.Dock="Bottom" HorizontalAlignment="Right" Orientation="Horizontal" Margin="0,12,0,0">
+ <Button Name="sendResponseButton" IsDefault="True" Margin="0,0,4,0" Click="sendResponseButton_Click">Send response</Button>
+ <Button Name="cancelButton" IsCancel="True">Cancel</Button>
+ </StackPanel>
+
+ <TabControl Name="tabControl1">
+ <TabItem Header="Positive assertion" Name="positiveTab">
+ <StackPanel>
+ <TextBlock TextWrapping="Wrap">You may customize the positive assertion if you wish.</TextBlock>
+ <Grid>
+ <Grid.RowDefinitions>
+ <RowDefinition Height="auto" />
+ <RowDefinition Height="auto" />
+ <RowDefinition Height="auto" />
+ <RowDefinition Height="auto" />
+ </Grid.RowDefinitions>
+ <Grid.ColumnDefinitions>
+ <ColumnDefinition Width="auto" />
+ <ColumnDefinition Width="*" />
+ </Grid.ColumnDefinitions>
+ <Label>Claimed identifier</Label>
+ <TextBox Grid.Column="1" Name="claimedIdentifierBox" />
+ <Label Grid.Row="1">OP Local identifier</Label>
+ <TextBox Grid.Column="1" Grid.Row="1" Name="localIdentifierBox" />
+ <!--<Label Grid.Row="2">Association</Label>
+ <WrapPanel Grid.Row="2" Grid.Column="1" VerticalAlignment="Center">
+ <RadioButton Margin="0,0,12,0" GroupName="AssociationType">Shared</RadioButton>
+ <RadioButton GroupName="AssociationType">Private</RadioButton>
+ </WrapPanel>-->
+ </Grid>
+ </StackPanel>
+ </TabItem>
+ <TabItem Header="Negative assertion" Name="negativeTab">
+ <TextBlock TextWrapping="Wrap">There is nothing to customize in a negative assertion.</TextBlock>
+ </TabItem>
+ <!--<TabItem Header="Error" Name="errorTab" >
+ <StackPanel>
+ <TextBlock TextWrapping="Wrap">What message do you want to send describing the simulated error?</TextBlock>
+ <TextBox TextWrapping="Wrap" />
+ </StackPanel>
+ </TabItem>
+ <TabItem Header="Invalid" Name="invalidTab">
+ <StackPanel>
+ <TextBlock TextWrapping="Wrap">This tab is useful for testing a relying party's resiliance to invalid responses.</TextBlock>
+ <TextBlock TextWrapping="Wrap">But it's not implemented yet. :)</TextBlock>
+ </StackPanel>
+ </TabItem>-->
+ </TabControl>
+ </DockPanel>
+</Window>
diff --git a/samples/OpenIdOfflineProvider/CheckIdWindow.xaml.cs b/samples/OpenIdOfflineProvider/CheckIdWindow.xaml.cs
new file mode 100644
index 0000000..597f72f
--- /dev/null
+++ b/samples/OpenIdOfflineProvider/CheckIdWindow.xaml.cs
@@ -0,0 +1,91 @@
+//-----------------------------------------------------------------------
+// <copyright file="CheckIdWindow.xaml.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOpenAuth.OpenIdOfflineProvider {
+ using System;
+ using System.Collections.Generic;
+ using System.Diagnostics.Contracts;
+ using System.Linq;
+ using System.Text;
+ using System.Windows;
+ using System.Windows.Controls;
+ using System.Windows.Data;
+ using System.Windows.Documents;
+ using System.Windows.Input;
+ using System.Windows.Media;
+ using System.Windows.Media.Imaging;
+ using System.Windows.Shapes;
+ using DotNetOpenAuth.Messaging;
+ using DotNetOpenAuth.OpenId.Provider;
+
+ /// <summary>
+ /// Interaction logic for CheckIdWindow.xaml
+ /// </summary>
+ public partial class CheckIdWindow : Window {
+ /// <summary>
+ /// Initializes a new instance of the <see cref="CheckIdWindow"/> class.
+ /// </summary>
+ /// <param name="provider">The OpenID Provider host.</param>
+ /// <param name="request">The incoming authentication request.</param>
+ private CheckIdWindow(HostedProvider provider, IAuthenticationRequest request) {
+ Contract.Requires(request != null);
+
+ InitializeComponent();
+
+ // Initialize the window with appropriate values.
+ this.realmLabel.Content = request.Realm;
+ this.immediateModeLabel.Visibility = request.Immediate ? Visibility.Visible : Visibility.Collapsed;
+ this.setupModeLabel.Visibility = request.Immediate ? Visibility.Collapsed : Visibility.Visible;
+
+ bool isRPDiscoverable = request.IsReturnUrlDiscoverable(provider.Provider.Channel.WebRequestHandler);
+ this.discoverableYesLabel.Visibility = isRPDiscoverable ? Visibility.Visible : Visibility.Collapsed;
+ this.discoverableNoLabel.Visibility = isRPDiscoverable ? Visibility.Collapsed : Visibility.Visible;
+
+ if (request.IsDirectedIdentity) {
+ this.claimedIdentifierBox.Text = provider.UserIdentityPageBase.AbsoluteUri;
+ this.localIdentifierBox.Text = provider.UserIdentityPageBase.AbsoluteUri;
+ } else {
+ this.claimedIdentifierBox.Text = request.ClaimedIdentifier;
+ this.localIdentifierBox.Text = request.LocalIdentifier;
+ }
+ }
+
+ /// <summary>
+ /// Processes an authentication request by a popup window.
+ /// </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) {
+ Contract.Requires(provider != null);
+ Contract.Requires(request != null);
+
+ var window = new CheckIdWindow(provider, request);
+ bool? result = window.ShowDialog();
+
+ // If the user pressed Esc or cancel, just send a negative assertion.
+ if (!result.HasValue || !result.Value) {
+ request.IsAuthenticated = false;
+ return;
+ }
+
+ request.IsAuthenticated = window.tabControl1.SelectedItem == window.positiveTab;
+ if (request.IsAuthenticated.Value) {
+ request.ClaimedIdentifier = window.claimedIdentifierBox.Text;
+ request.LocalIdentifier = window.localIdentifierBox.Text;
+ }
+ }
+
+ /// <summary>
+ /// Handles the Click event of the sendResponseButton control.
+ /// </summary>
+ /// <param name="sender">The source of the event.</param>
+ /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
+ private void sendResponseButton_Click(object sender, RoutedEventArgs e) {
+ this.DialogResult = true;
+ Close();
+ }
+ }
+}
diff --git a/samples/OpenIdOfflineProvider/HostedProvider.cs b/samples/OpenIdOfflineProvider/HostedProvider.cs
new file mode 100644
index 0000000..3d50dd9
--- /dev/null
+++ b/samples/OpenIdOfflineProvider/HostedProvider.cs
@@ -0,0 +1,253 @@
+//-----------------------------------------------------------------------
+// <copyright file="HostedProvider.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOpenAuth.OpenIdOfflineProvider {
+ using System;
+ using System.Collections.Generic;
+ using System.Diagnostics.Contracts;
+ using System.IO;
+ using System.Linq;
+ using System.Net;
+ using DotNetOpenAuth.Messaging;
+ using DotNetOpenAuth.OpenId.Provider;
+ using log4net;
+
+ /// <summary>
+ /// The OpenID Provider host.
+ /// </summary>
+ internal class HostedProvider : IDisposable {
+ /// <summary>
+ /// The path to the Provider Endpoint.
+ /// </summary>
+ private const string ProviderPath = "/provider";
+
+ /// <summary>
+ /// The path to the OP Identifier.
+ /// </summary>
+ private const string OPIdentifierPath = "/";
+
+ /// <summary>
+ /// The URL path with which all user identities must start.
+ /// </summary>
+ private const string UserIdentifierPath = "/user/";
+
+ /// <summary>
+ /// The <see cref="OpenIdProvider"/> instance that processes incoming requests.
+ /// </summary>
+ private OpenIdProvider provider = new OpenIdProvider(new StandardProviderApplicationStore());
+
+ /// <summary>
+ /// The HTTP listener that acts as the OpenID Provider socket.
+ /// </summary>
+ private HttpHost httpHost;
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="HostedProvider"/> class.
+ /// </summary>
+ internal HostedProvider() {
+ }
+
+ /// <summary>
+ /// Gets a value indicating whether this instance is running.
+ /// </summary>
+ /// <value>
+ /// <c>true</c> if this instance is running; otherwise, <c>false</c>.
+ /// </value>
+ internal bool IsRunning {
+ get { return this.httpHost != null; }
+ }
+
+ /// <summary>
+ /// Gets the <see cref="OpenIdProvider"/> instance that processes incoming requests.
+ /// </summary>
+ internal OpenIdProvider Provider {
+ get { return this.provider; }
+ }
+
+ /// <summary>
+ /// Gets or sets the delegate that handles authentication requests.
+ /// </summary>
+ internal Action<HttpRequestInfo, HttpListenerResponse> ProcessRequest { get; set; }
+
+ /// <summary>
+ /// Gets the provider endpoint.
+ /// </summary>
+ internal Uri ProviderEndpoint {
+ get {
+ Contract.Requires(this.IsRunning);
+ return new Uri(this.httpHost.BaseUri, ProviderPath);
+ }
+ }
+
+ /// <summary>
+ /// Gets the base URI that all user identities must start with.
+ /// </summary>
+ internal Uri UserIdentityPageBase {
+ get {
+ Contract.Requires(this.IsRunning);
+ return new Uri(this.httpHost.BaseUri, UserIdentifierPath);
+ }
+ }
+
+ /// <summary>
+ /// Gets the OP identifier.
+ /// </summary>
+ internal Uri OPIdentifier {
+ get {
+ Contract.Requires(this.IsRunning);
+ return new Uri(this.httpHost.BaseUri, OPIdentifierPath);
+ }
+ }
+
+ /// <summary>
+ /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
+ /// </summary>
+ public void Dispose() {
+ this.Dispose(true);
+ }
+
+ /// <summary>
+ /// Starts the provider.
+ /// </summary>
+ internal void StartProvider() {
+ Contract.Ensures(this.IsRunning);
+ this.httpHost = HttpHost.CreateHost(this.RequestHandler);
+ }
+
+ /// <summary>
+ /// Stops the provider.
+ /// </summary>
+ internal void StopProvider() {
+ Contract.Ensures(!this.IsRunning);
+ if (this.httpHost != null) {
+ this.httpHost.Dispose();
+ this.httpHost = null;
+ }
+ }
+
+ #region IDisposable Members
+
+ /// <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) {
+ var host = this.httpHost as IDisposable;
+ if (host != null) {
+ host.Dispose();
+ }
+
+ this.httpHost = null;
+ }
+ }
+
+ #endregion
+
+ /// <summary>
+ /// Generates HTML for an identity page.
+ /// </summary>
+ /// <param name="providerEndpoint">The provider endpoint.</param>
+ /// <param name="localId">The local id.</param>
+ /// <returns>The HTML document to return to the RP.</returns>
+ private static string GenerateHtmlDiscoveryDocument(Uri providerEndpoint, string localId) {
+ Contract.Requires(providerEndpoint != null);
+
+ const string DelegatedHtmlDiscoveryFormat = @"<html><head>
+ <link rel=""openid.server"" href=""{0}"" />
+ <link rel=""openid.delegate"" href=""{1}"" />
+ <link rel=""openid2.provider"" href=""{0}"" />
+ <link rel=""openid2.local_id"" href=""{1}"" />
+ </head><body></body></html>";
+
+ const string NonDelegatedHtmlDiscoveryFormat = @"<html><head>
+ <link rel=""openid.server"" href=""{0}"" />
+ <link rel=""openid2.provider"" href=""{0}"" />
+ </head><body></body></html>";
+
+ return string.Format(
+ localId != null ? DelegatedHtmlDiscoveryFormat : NonDelegatedHtmlDiscoveryFormat,
+ providerEndpoint.AbsoluteUri,
+ localId);
+ }
+
+ /// <summary>
+ /// Generates the OP Identifier XRDS document.
+ /// </summary>
+ /// <param name="providerEndpoint">The provider endpoint.</param>
+ /// <param name="supportedExtensions">The supported extensions.</param>
+ /// <returns>The content of the XRDS document.</returns>
+ private static string GenerateXrdsOPIdentifierDocument(Uri providerEndpoint, IEnumerable<string> supportedExtensions) {
+ Contract.Requires(providerEndpoint != null);
+ Contract.Requires(supportedExtensions != null);
+
+ const string OPIdentifierDiscoveryFormat = @"<xrds:XRDS
+ xmlns:xrds='xri://$xrds'
+ xmlns:openid='http://openid.net/xmlns/1.0'
+ xmlns='xri://$xrd*($v*2.0)'>
+ <XRD>
+ <Service priority='10'>
+ <Type>http://specs.openid.net/auth/2.0/server</Type>
+ {1}
+ <URI>{0}</URI>
+ </Service>
+ </XRD>
+</xrds:XRDS>";
+
+ string extensions = string.Join(
+ "\n\t\t\t",
+ supportedExtensions.Select(ext => "<Type>" + ext + "</Type>").ToArray());
+ return string.Format(
+ OPIdentifierDiscoveryFormat,
+ providerEndpoint.AbsoluteUri,
+ extensions);
+ }
+
+ /// <summary>
+ /// Handles incoming HTTP requests.
+ /// </summary>
+ /// <param name="context">The HttpListener context.</param>
+ private void RequestHandler(HttpListenerContext context) {
+ Contract.Requires(context != null);
+ Contract.Requires(context.Response.OutputStream != null);
+ Contract.Requires(this.ProcessRequest != null);
+ Stream outputStream = context.Response.OutputStream;
+ Contract.Assume(outputStream != null); // CC static verification shortcoming.
+
+ UriBuilder providerEndpointBuilder = new UriBuilder();
+ providerEndpointBuilder.Scheme = Uri.UriSchemeHttp;
+ providerEndpointBuilder.Host = "localhost";
+ providerEndpointBuilder.Port = context.Request.Url.Port;
+ providerEndpointBuilder.Path = ProviderPath;
+ Uri providerEndpoint = providerEndpointBuilder.Uri;
+
+ if (context.Request.Url.AbsolutePath == ProviderPath) {
+ HttpRequestInfo requestInfo = new HttpRequestInfo(context.Request);
+ 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;
+
+ string localId = null; // string.Format("http://localhost:{0}/user", context.Request.Url.Port);
+ string html = GenerateHtmlDiscoveryDocument(providerEndpoint, localId);
+ sw.WriteLine(html);
+ }
+ context.Response.OutputStream.Close();
+ } else if (context.Request.Url == this.OPIdentifier) {
+ context.Response.ContentType = "application/xrds+xml";
+ context.Response.StatusCode = (int)HttpStatusCode.OK;
+ App.Logger.Info("Discovery on OP Identifier detected.");
+ using (StreamWriter sw = new StreamWriter(outputStream)) {
+ sw.Write(GenerateXrdsOPIdentifierDocument(providerEndpoint, Enumerable.Empty<string>()));
+ }
+ context.Response.OutputStream.Close();
+ } else {
+ context.Response.StatusCode = (int)HttpStatusCode.NotFound;
+ context.Response.OutputStream.Close();
+ }
+ }
+ }
+}
diff --git a/samples/OpenIdOfflineProvider/HttpHost.cs b/samples/OpenIdOfflineProvider/HttpHost.cs
new file mode 100644
index 0000000..a2558f4
--- /dev/null
+++ b/samples/OpenIdOfflineProvider/HttpHost.cs
@@ -0,0 +1,140 @@
+//-----------------------------------------------------------------------
+// <copyright file="HttpHost.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOpenAuth.OpenIdOfflineProvider {
+ using System;
+ using System.Diagnostics.Contracts;
+ using System.Globalization;
+ using System.IO;
+ using System.Net;
+ using System.Threading;
+ using DotNetOpenAuth.Messaging;
+ using DotNetOpenAuth.OpenId.Provider;
+
+ /// <summary>
+ /// An HTTP Listener that dispatches incoming requests for handling.
+ /// </summary>
+ internal class HttpHost : IDisposable {
+ /// <summary>
+ /// The HttpListener that waits for incoming requests.
+ /// </summary>
+ private readonly HttpListener listener;
+
+ /// <summary>
+ /// The thread that listens for incoming HTTP requests and dispatches them
+ /// to the <see cref="handler"/>.
+ /// </summary>
+ private Thread listenerThread;
+
+ /// <summary>
+ /// The handler for incoming HTTP requests.
+ /// </summary>
+ private RequestHandler handler;
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="HttpHost"/> class.
+ /// </summary>
+ /// <param name="handler">The handler for incoming HTTP requests.</param>
+ private HttpHost(RequestHandler handler) {
+ Contract.Requires(handler != null);
+
+ this.Port = 45235;
+ this.handler = handler;
+ Random r = new Random();
+ tryAgain:
+ try {
+ this.listener = new HttpListener();
+ this.listener.Prefixes.Add(string.Format(CultureInfo.InvariantCulture, "http://localhost:{0}/", this.Port));
+ this.listener.Start();
+ } catch (HttpListenerException ex) {
+ if (ex.Message.Contains("conflicts")) {
+ this.Port += r.Next(1, 20);
+ goto tryAgain;
+ }
+ throw;
+ }
+
+ this.listenerThread = new Thread(this.ProcessRequests);
+ this.listenerThread.Start();
+ }
+
+ /// <summary>
+ /// The request handler delegate.
+ /// </summary>
+ /// <param name="context">Information on the incoming HTTP request.</param>
+ internal delegate void RequestHandler(HttpListenerContext context);
+
+ /// <summary>
+ /// Gets the port that HTTP requests are being listened for on.
+ /// </summary>
+ public int Port { get; private set; }
+
+ /// <summary>
+ /// Gets the base URI for all incoming web requests that will be received.
+ /// </summary>
+ public Uri BaseUri {
+ get { return new Uri("http://localhost:" + this.Port.ToString() + "/"); }
+ }
+
+ /// <summary>
+ /// Creates the HTTP host.
+ /// </summary>
+ /// <param name="handler">The handler for incoming HTTP requests.</param>
+ /// <returns>The instantiated host.</returns>
+ public static HttpHost CreateHost(RequestHandler handler) {
+ Contract.Requires(handler != null);
+ Contract.Ensures(Contract.Result<HttpHost>() != null);
+
+ return new HttpHost(handler);
+ }
+
+ #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.listener.Close();
+ this.listenerThread.Join(1000);
+ this.listenerThread.Abort();
+ }
+ }
+
+ #endregion
+
+ /// <summary>
+ /// The HTTP listener thread body.
+ /// </summary>
+ private void ProcessRequests() {
+ Contract.Requires(this.listener != null);
+
+ while (true) {
+ try {
+ HttpListenerContext context = this.listener.GetContext();
+ this.handler(context);
+ } catch (HttpListenerException ex) {
+ if (this.listener.IsListening) {
+ App.Logger.Error("Unexpected exception.", ex);
+ } else {
+ // the listener is probably being shut down
+ App.Logger.Warn("HTTP listener is closing down.", ex);
+ break;
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/samples/OpenIdOfflineProvider/MainWindow.xaml b/samples/OpenIdOfflineProvider/MainWindow.xaml
new file mode 100644
index 0000000..de215ba
--- /dev/null
+++ b/samples/OpenIdOfflineProvider/MainWindow.xaml
@@ -0,0 +1,25 @@
+<Window x:Class="DotNetOpenAuth.OpenIdOfflineProvider.MainWindow"
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ Title="DotNetOpenAuth Offline OpenID Provider" Height="289" Width="493">
+ <Grid Margin="4">
+ <Grid.RowDefinitions>
+ <RowDefinition Height="Auto" />
+ <RowDefinition Height="Auto" />
+ <RowDefinition Height="*"/>
+ </Grid.RowDefinitions>
+ <Grid.ColumnDefinitions>
+ <ColumnDefinition Width="auto" />
+ <ColumnDefinition />
+ </Grid.ColumnDefinitions>
+ <Label Grid.Row="0">OP Identifier</Label>
+ <Label Grid.Column="1" Grid.Row="0" Name="opIdentifierLabel" ToolTip="Click to copy URI to clipboard" MouseDown="opIdentifierLabel_MouseDown" />
+ <Label Grid.Row="1">checkid requests</Label>
+ <ComboBox Grid.Column="1" Grid.Row="1" Name="checkidRequestList" SelectedIndex="0">
+ <ComboBoxItem>Auto respond: Yes</ComboBoxItem>
+ <ComboBoxItem>Auto respond: No</ComboBoxItem>
+ <ComboBoxItem>Intercept</ComboBoxItem>
+ </ComboBox>
+ <TextBox Height="auto" Margin="0,8,0,0" Grid.Row="2" Grid.ColumnSpan="2" Name="logBox" IsReadOnly="True" VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Auto" />
+ </Grid>
+</Window>
diff --git a/samples/OpenIdOfflineProvider/MainWindow.xaml.cs b/samples/OpenIdOfflineProvider/MainWindow.xaml.cs
new file mode 100644
index 0000000..8f04da3
--- /dev/null
+++ b/samples/OpenIdOfflineProvider/MainWindow.xaml.cs
@@ -0,0 +1,173 @@
+//-----------------------------------------------------------------------
+// <copyright file="MainWindow.xaml.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOpenAuth.OpenIdOfflineProvider {
+ using System;
+ using System.Collections.Generic;
+ using System.Diagnostics;
+ using System.Diagnostics.Contracts;
+ using System.Globalization;
+ using System.IO;
+ using System.Linq;
+ using System.Net;
+ using System.Runtime.InteropServices;
+ using System.Text;
+ using System.Windows;
+ using System.Windows.Controls;
+ using System.Windows.Data;
+ using System.Windows.Documents;
+ using System.Windows.Input;
+ using System.Windows.Media;
+ 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;
+
+ /// <summary>
+ /// Interaction logic for MainWindow.xaml
+ /// </summary>
+ public partial class MainWindow : Window, IDisposable {
+ /// <summary>
+ /// The OpenID Provider host object.
+ /// </summary>
+ private HostedProvider hostedProvider = new HostedProvider();
+
+ /// <summary>
+ /// The logger the application may use.
+ /// </summary>
+ private ILog logger = log4net.LogManager.GetLogger(typeof(MainWindow));
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="MainWindow"/> class.
+ /// </summary>
+ public MainWindow() {
+ this.InitializeComponent();
+ 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);
+ }
+
+ this.startProvider();
+ }
+
+ #region IDisposable Members
+
+ /// <summary>
+ /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
+ /// </summary>
+ public void Dispose() {
+ this.Dispose(true);
+ }
+
+ /// <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) {
+ var host = this.hostedProvider as IDisposable;
+ if (host != null) {
+ host.Dispose();
+ }
+
+ this.hostedProvider = null;
+ }
+ }
+
+ #endregion
+
+ /// <summary>
+ /// Raises the <see cref="E:Closing"/> event.
+ /// </summary>
+ /// <param name="e">The <see cref="System.ComponentModel.CancelEventArgs"/> instance containing the event data.</param>
+ protected override void OnClosing(System.ComponentModel.CancelEventArgs e) {
+ this.stopProvider();
+ base.OnClosing(e);
+ }
+
+ /// <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.ContentType = "text/html";
+ 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) {
+ switch (checkidRequestList.SelectedIndex) {
+ case 0:
+ if (authRequest.IsDirectedIdentity) {
+ authRequest.ClaimedIdentifier = new Uri(this.hostedProvider.UserIdentityPageBase, "directedidentity");
+ authRequest.LocalIdentifier = authRequest.ClaimedIdentifier;
+ }
+ authRequest.IsAuthenticated = true;
+ break;
+ case 1:
+ authRequest.IsAuthenticated = false;
+ break;
+ case 2:
+ IntPtr oldForegroundWindow = NativeMethods.GetForegroundWindow();
+ bool stoleFocus = NativeMethods.SetForegroundWindow(this);
+ CheckIdWindow.ProcessAuthentication(this.hostedProvider, authRequest);
+ if (stoleFocus) {
+ NativeMethods.SetForegroundWindow(oldForegroundWindow);
+ }
+ break;
+ }
+ }
+ }
+ });
+
+ this.hostedProvider.Provider.PrepareResponse(request).Send(response);
+ }
+
+ /// <summary>
+ /// Starts the provider.
+ /// </summary>
+ private void startProvider() {
+ this.hostedProvider.StartProvider();
+ this.opIdentifierLabel.Content = this.hostedProvider.OPIdentifier;
+ }
+
+ /// <summary>
+ /// Stops the provider.
+ /// </summary>
+ private void stopProvider() {
+ this.hostedProvider.StopProvider();
+ this.opIdentifierLabel.Content = string.Empty;
+ }
+
+ /// <summary>
+ /// Handles the MouseDown event of the opIdentifierLabel control.
+ /// </summary>
+ /// <param name="sender">The source of the event.</param>
+ /// <param name="e">The <see cref="System.Windows.Input.MouseButtonEventArgs"/> instance containing the event data.</param>
+ private void opIdentifierLabel_MouseDown(object sender, MouseButtonEventArgs e) {
+ try {
+ Clipboard.SetText(opIdentifierLabel.Content.ToString());
+ } catch (COMException ex) {
+ MessageBox.Show(this, ex.Message, "Error while copying OP Identifier to the clipboard", MessageBoxButton.OK, MessageBoxImage.Error);
+ }
+ }
+ }
+}
diff --git a/samples/OpenIdOfflineProvider/NativeMethods.cs b/samples/OpenIdOfflineProvider/NativeMethods.cs
new file mode 100644
index 0000000..b512d70
--- /dev/null
+++ b/samples/OpenIdOfflineProvider/NativeMethods.cs
@@ -0,0 +1,60 @@
+//-----------------------------------------------------------------------
+// <copyright file="NativeMethods.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOpenAuth.OpenIdOfflineProvider {
+ using System;
+ using System.Runtime.InteropServices;
+ using System.Windows;
+ using System.Windows.Interop;
+
+ /// <summary>
+ /// P/Invoke methods and wrappers.
+ /// </summary>
+ internal static class NativeMethods {
+ /// <summary>
+ /// Gets the HWND of the current foreground window on the system.
+ /// </summary>
+ /// <returns>A handle to the foreground window.</returns>
+ [DllImport("user32.dll")]
+ internal static extern IntPtr GetForegroundWindow();
+
+ /// <summary>
+ /// Sets the foreground window of the system.
+ /// </summary>
+ /// <param name="hWnd">The HWND of the window to set as active.</param>
+ /// <returns>A value indicating whether the foreground window was actually changed.</returns>
+ [DllImport("user32.dll")]
+ [return: MarshalAs(UnmanagedType.Bool)]
+ internal static extern bool SetForegroundWindow(IntPtr hWnd);
+
+ /// <summary>
+ /// Sets the foreground window of the system.
+ /// </summary>
+ /// <param name="window">The window to bring to the foreground.</param>
+ /// <returns>
+ /// A value indicating whether the foreground window was actually changed.
+ /// </returns>
+ internal static bool SetForegroundWindow(Window window) {
+ return SetForegroundWindow(new WindowInteropHelper(window).Handle);
+ }
+
+ /// <summary>
+ /// Sets the active window of the process.
+ /// </summary>
+ /// <param name="window">The window to bring to the foreground.</param>
+ internal static void SetActiveWindow(Window window) {
+ SetActiveWindow(new WindowInteropHelper(window).Handle);
+ }
+
+ /// <summary>
+ /// Sets the active window of the process.
+ /// </summary>
+ /// <param name="hWnd">The HWND of the window to set as active.</param>
+ /// <returns>The window that was previously active?</returns>
+ [DllImport("user32.dll")]
+ private static extern IntPtr SetActiveWindow(IntPtr hWnd);
+ }
+}
diff --git a/samples/OpenIdOfflineProvider/OpenIdOfflineProvider.csproj b/samples/OpenIdOfflineProvider/OpenIdOfflineProvider.csproj
new file mode 100644
index 0000000..bb307a4
--- /dev/null
+++ b/samples/OpenIdOfflineProvider/OpenIdOfflineProvider.csproj
@@ -0,0 +1,165 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>9.0.30729</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{5C65603B-235F-47E6-B536-06385C60DE7F}</ProjectGuid>
+ <OutputType>WinExe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>DotNetOpenAuth.OpenIdOfflineProvider</RootNamespace>
+ <AssemblyName>OpenIdOfflineProvider</AssemblyName>
+ <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <WarningLevel>4</WarningLevel>
+ <UICulture>en-US</UICulture>
+ <ApplicationIcon>openid.ico</ApplicationIcon>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <CodeContractsEnableRuntimeChecking>False</CodeContractsEnableRuntimeChecking>
+ <CodeContractsCustomRewriterAssembly>
+ </CodeContractsCustomRewriterAssembly>
+ <CodeContractsCustomRewriterClass>
+ </CodeContractsCustomRewriterClass>
+ <CodeContractsRuntimeCheckingLevel>Full</CodeContractsRuntimeCheckingLevel>
+ <CodeContractsRunCodeAnalysis>False</CodeContractsRunCodeAnalysis>
+ <CodeContractsBuildReferenceAssembly>False</CodeContractsBuildReferenceAssembly>
+ <CodeContractsNonNullObligations>False</CodeContractsNonNullObligations>
+ <CodeContractsBoundsObligations>False</CodeContractsBoundsObligations>
+ <CodeContractsArithmeticObligations>False</CodeContractsArithmeticObligations>
+ <CodeContractsLibPaths>
+ </CodeContractsLibPaths>
+ <CodeContractsPlatformPath>
+ </CodeContractsPlatformPath>
+ <CodeContractsExtraAnalysisOptions>
+ </CodeContractsExtraAnalysisOptions>
+ <CodeContractsBaseLineFile>
+ </CodeContractsBaseLineFile>
+ <CodeContractsUseBaseLine>False</CodeContractsUseBaseLine>
+ <CodeContractsRunInBackground>True</CodeContractsRunInBackground>
+ <CodeContractsShowSquigglies>True</CodeContractsShowSquigglies>
+ <CodeContractsRuntimeOnlyPublicSurface>False</CodeContractsRuntimeOnlyPublicSurface>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Sign)' == 'true' ">
+ <SignAssembly>true</SignAssembly>
+ <AssemblyOriginatorKeyFile>..\..\src\official-build-key.pfx</AssemblyOriginatorKeyFile>
+ <DefineConstants>$(DefineConstants);StrongNameSigned</DefineConstants>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\lib\log4net.dll</HintPath>
+ </Reference>
+ <Reference Include="Microsoft.Contracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=736440c9b414ea16, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\lib\Microsoft.Contracts.dll</HintPath>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="System.Core">
+ <RequiredTargetFramework>3.5</RequiredTargetFramework>
+ </Reference>
+ <Reference Include="System.Web" />
+ <Reference Include="System.Xml.Linq">
+ <RequiredTargetFramework>3.5</RequiredTargetFramework>
+ </Reference>
+ <Reference Include="System.Data.DataSetExtensions">
+ <RequiredTargetFramework>3.5</RequiredTargetFramework>
+ </Reference>
+ <Reference Include="System.Data" />
+ <Reference Include="System.Xml" />
+ <Reference Include="UIAutomationProvider">
+ <RequiredTargetFramework>3.0</RequiredTargetFramework>
+ </Reference>
+ <Reference Include="WindowsBase">
+ <RequiredTargetFramework>3.0</RequiredTargetFramework>
+ </Reference>
+ <Reference Include="PresentationCore">
+ <RequiredTargetFramework>3.0</RequiredTargetFramework>
+ </Reference>
+ <Reference Include="PresentationFramework">
+ <RequiredTargetFramework>3.0</RequiredTargetFramework>
+ </Reference>
+ </ItemGroup>
+ <ItemGroup>
+ <ApplicationDefinition Include="App.xaml">
+ <Generator>MSBuild:Compile</Generator>
+ <SubType>Designer</SubType>
+ </ApplicationDefinition>
+ <Page Include="CheckIdWindow.xaml">
+ <SubType>Designer</SubType>
+ <Generator>MSBuild:Compile</Generator>
+ </Page>
+ <Page Include="MainWindow.xaml">
+ <Generator>MSBuild:Compile</Generator>
+ <SubType>Designer</SubType>
+ </Page>
+ <Compile Include="App.xaml.cs">
+ <DependentUpon>App.xaml</DependentUpon>
+ <SubType>Code</SubType>
+ </Compile>
+ <Compile Include="MainWindow.xaml.cs">
+ <DependentUpon>MainWindow.xaml</DependentUpon>
+ <SubType>Code</SubType>
+ </Compile>
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="CheckIdWindow.xaml.cs">
+ <DependentUpon>CheckIdWindow.xaml</DependentUpon>
+ </Compile>
+ <Compile Include="HostedProvider.cs" />
+ <Compile Include="HttpHost.cs" />
+ <Compile Include="NativeMethods.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs">
+ <SubType>Code</SubType>
+ </Compile>
+ <Compile Include="Properties\Resources.Designer.cs">
+ <AutoGen>True</AutoGen>
+ <DesignTime>True</DesignTime>
+ <DependentUpon>Resources.resx</DependentUpon>
+ </Compile>
+ <Compile Include="Properties\Settings.Designer.cs">
+ <AutoGen>True</AutoGen>
+ <DependentUpon>Settings.settings</DependentUpon>
+ <DesignTimeSharedInput>True</DesignTimeSharedInput>
+ </Compile>
+ <Compile Include="TextBoxTextWriter.cs" />
+ <EmbeddedResource Include="Properties\Resources.resx">
+ <Generator>ResXFileCodeGenerator</Generator>
+ <LastGenOutput>Resources.Designer.cs</LastGenOutput>
+ </EmbeddedResource>
+ <None Include="App.config" />
+ <None Include="Properties\Settings.settings">
+ <Generator>SettingsSingleFileGenerator</Generator>
+ <LastGenOutput>Settings.Designer.cs</LastGenOutput>
+ </None>
+ <AppDesigner Include="Properties\" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\..\src\DotNetOpenAuth\DotNetOpenAuth.csproj">
+ <Project>{3191B653-F76D-4C1A-9A5A-347BC3AAAAB7}</Project>
+ <Name>DotNetOpenAuth</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <ItemGroup>
+ <Resource Include="openid.ico" />
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <Import Project="..\..\tools\DotNetOpenAuth.Versioning.targets" />
+</Project>
diff --git a/samples/OpenIdOfflineProvider/Properties/AssemblyInfo.cs b/samples/OpenIdOfflineProvider/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..77d7464
--- /dev/null
+++ b/samples/OpenIdOfflineProvider/Properties/AssemblyInfo.cs
@@ -0,0 +1,40 @@
+//-----------------------------------------------------------------------
+// <copyright file="AssemblyInfo.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+using System.Reflection;
+using System.Resources;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+using System.Windows;
+
+// We DON'T put an AssemblyVersionAttribute in here because it is generated in the build.
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("OpenIdOfflineProvider")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("Andrew Arnott")]
+[assembly: AssemblyProduct("DotNetOpenAuth Offline OpenID Provider")]
+[assembly: AssemblyCopyright("Copyright © Andrew Arnott 2009")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
+
+[assembly: ThemeInfo(
+ ResourceDictionaryLocation.None, // where theme specific resource dictionaries are located
+ // (used if a resource is not found in the page,
+ // or application resource dictionaries)
+ ResourceDictionaryLocation.SourceAssembly)] // where the generic resource dictionary is located
+ // (used if a resource is not found in the page,
+ // app, or any theme specific resource dictionaries)
diff --git a/samples/OpenIdOfflineProvider/Properties/Resources.Designer.cs b/samples/OpenIdOfflineProvider/Properties/Resources.Designer.cs
new file mode 100644
index 0000000..ac28082
--- /dev/null
+++ b/samples/OpenIdOfflineProvider/Properties/Resources.Designer.cs
@@ -0,0 +1,63 @@
+//------------------------------------------------------------------------------
+// <auto-generated>
+// This code was generated by a tool.
+// Runtime Version:2.0.50727.4912
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+// </auto-generated>
+//------------------------------------------------------------------------------
+
+namespace DotNetOpenAuth.OpenIdOfflineProvider.Properties {
+ using System;
+
+
+ /// <summary>
+ /// A strongly-typed resource class, for looking up localized strings, etc.
+ /// </summary>
+ // This class was auto-generated by the StronglyTypedResourceBuilder
+ // class via a tool like ResGen or Visual Studio.
+ // To add or remove a member, edit your .ResX file then rerun ResGen
+ // with the /str option, or rebuild your VS project.
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "2.0.0.0")]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
+ internal class Resources {
+
+ private static global::System.Resources.ResourceManager resourceMan;
+
+ private static global::System.Globalization.CultureInfo resourceCulture;
+
+ [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
+ internal Resources() {
+ }
+
+ /// <summary>
+ /// Returns the cached ResourceManager instance used by this class.
+ /// </summary>
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+ internal static global::System.Resources.ResourceManager ResourceManager {
+ get {
+ if (object.ReferenceEquals(resourceMan, null)) {
+ global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("DotNetOpenAuth.OpenIdOfflineProvider.Properties.Resources", typeof(Resources).Assembly);
+ resourceMan = temp;
+ }
+ return resourceMan;
+ }
+ }
+
+ /// <summary>
+ /// Overrides the current thread's CurrentUICulture property for all
+ /// resource lookups using this strongly typed resource class.
+ /// </summary>
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+ internal static global::System.Globalization.CultureInfo Culture {
+ get {
+ return resourceCulture;
+ }
+ set {
+ resourceCulture = value;
+ }
+ }
+ }
+}
diff --git a/samples/OpenIdOfflineProvider/Properties/Resources.resx b/samples/OpenIdOfflineProvider/Properties/Resources.resx
new file mode 100644
index 0000000..af7dbeb
--- /dev/null
+++ b/samples/OpenIdOfflineProvider/Properties/Resources.resx
@@ -0,0 +1,117 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+ <!--
+ Microsoft ResX Schema
+
+ Version 2.0
+
+ The primary goals of this format is to allow a simple XML format
+ that is mostly human readable. The generation and parsing of the
+ various data types are done through the TypeConverter classes
+ associated with the data types.
+
+ Example:
+
+ ... ado.net/XML headers & schema ...
+ <resheader name="resmimetype">text/microsoft-resx</resheader>
+ <resheader name="version">2.0</resheader>
+ <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+ <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+ <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+ <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+ <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+ <value>[base64 mime encoded serialized .NET Framework object]</value>
+ </data>
+ <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+ <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+ <comment>This is a comment</comment>
+ </data>
+
+ There are any number of "resheader" rows that contain simple
+ name/value pairs.
+
+ Each data row contains a name, and value. The row also contains a
+ type or mimetype. Type corresponds to a .NET class that support
+ text/value conversion through the TypeConverter architecture.
+ Classes that don't support this are serialized and stored with the
+ mimetype set.
+
+ The mimetype is used for serialized objects, and tells the
+ ResXResourceReader how to depersist the object. This is currently not
+ extensible. For a given mimetype the value must be set accordingly:
+
+ Note - application/x-microsoft.net.object.binary.base64 is the format
+ that the ResXResourceWriter will generate, however the reader can
+ read any of the formats listed below.
+
+ mimetype: application/x-microsoft.net.object.binary.base64
+ value : The object must be serialized with
+ : System.Serialization.Formatters.Binary.BinaryFormatter
+ : and then encoded with base64 encoding.
+
+ mimetype: application/x-microsoft.net.object.soap.base64
+ value : The object must be serialized with
+ : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+ : and then encoded with base64 encoding.
+
+ mimetype: application/x-microsoft.net.object.bytearray.base64
+ value : The object must be serialized into a byte array
+ : using a System.ComponentModel.TypeConverter
+ : and then encoded with base64 encoding.
+ -->
+ <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+ <xsd:element name="root" msdata:IsDataSet="true">
+ <xsd:complexType>
+ <xsd:choice maxOccurs="unbounded">
+ <xsd:element name="metadata">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" />
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string" />
+ <xsd:attribute name="type" type="xsd:string" />
+ <xsd:attribute name="mimetype" type="xsd:string" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="assembly">
+ <xsd:complexType>
+ <xsd:attribute name="alias" type="xsd:string" />
+ <xsd:attribute name="name" type="xsd:string" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="data">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+ <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
+ <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+ <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="resheader">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string" use="required" />
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:choice>
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:schema>
+ <resheader name="resmimetype">
+ <value>text/microsoft-resx</value>
+ </resheader>
+ <resheader name="version">
+ <value>2.0</value>
+ </resheader>
+ <resheader name="reader">
+ <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </resheader>
+ <resheader name="writer">
+ <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </resheader>
+</root> \ No newline at end of file
diff --git a/samples/OpenIdOfflineProvider/Properties/Settings.Designer.cs b/samples/OpenIdOfflineProvider/Properties/Settings.Designer.cs
new file mode 100644
index 0000000..014a460
--- /dev/null
+++ b/samples/OpenIdOfflineProvider/Properties/Settings.Designer.cs
@@ -0,0 +1,26 @@
+//------------------------------------------------------------------------------
+// <auto-generated>
+// This code was generated by a tool.
+// Runtime Version:2.0.50727.4912
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+// </auto-generated>
+//------------------------------------------------------------------------------
+
+namespace DotNetOpenAuth.OpenIdOfflineProvider.Properties {
+
+
+ [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "9.0.0.0")]
+ internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
+
+ private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
+
+ public static Settings Default {
+ get {
+ return defaultInstance;
+ }
+ }
+ }
+}
diff --git a/samples/OpenIdOfflineProvider/Properties/Settings.settings b/samples/OpenIdOfflineProvider/Properties/Settings.settings
new file mode 100644
index 0000000..033d7a5
--- /dev/null
+++ b/samples/OpenIdOfflineProvider/Properties/Settings.settings
@@ -0,0 +1,7 @@
+<?xml version='1.0' encoding='utf-8'?>
+<SettingsFile xmlns="uri:settings" CurrentProfile="(Default)">
+ <Profiles>
+ <Profile Name="(Default)" />
+ </Profiles>
+ <Settings />
+</SettingsFile> \ No newline at end of file
diff --git a/samples/OpenIdOfflineProvider/Settings.StyleCop b/samples/OpenIdOfflineProvider/Settings.StyleCop
new file mode 100644
index 0000000..0d69b34
--- /dev/null
+++ b/samples/OpenIdOfflineProvider/Settings.StyleCop
@@ -0,0 +1,19 @@
+<StyleCopSettings Version="4.3">
+ <Analyzers>
+ <Analyzer AnalyzerId="Microsoft.StyleCop.CSharp.DocumentationRules">
+ <Rules>
+ <Rule Name="FileMustHaveHeader">
+ <RuleSettings>
+ <BooleanProperty Name="Enabled">True</BooleanProperty>
+ </RuleSettings>
+ </Rule>
+ <Rule Name="ElementsMustBeDocumented">
+ <RuleSettings>
+ <BooleanProperty Name="Enabled">True</BooleanProperty>
+ </RuleSettings>
+ </Rule>
+ </Rules>
+ <AnalyzerSettings />
+ </Analyzer>
+ </Analyzers>
+</StyleCopSettings> \ No newline at end of file
diff --git a/samples/OpenIdOfflineProvider/TextBoxTextWriter.cs b/samples/OpenIdOfflineProvider/TextBoxTextWriter.cs
new file mode 100644
index 0000000..8118986
--- /dev/null
+++ b/samples/OpenIdOfflineProvider/TextBoxTextWriter.cs
@@ -0,0 +1,87 @@
+//-----------------------------------------------------------------------
+// <copyright file="TextBoxTextWriter.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOpenAuth.OpenIdOfflineProvider {
+ using System;
+ using System.Diagnostics.Contracts;
+ using System.IO;
+ using System.Text;
+ using System.Windows.Controls;
+
+ /// <summary>
+ /// A text writer that appends all write calls to a text box.
+ /// </summary>
+ internal class TextBoxTextWriter : TextWriter {
+ /// <summary>
+ /// Initializes a new instance of the <see cref="TextBoxTextWriter"/> class.
+ /// </summary>
+ /// <param name="box">The text box to append log messages to.</param>
+ internal TextBoxTextWriter(TextBox box) {
+ Contract.Requires(box != null);
+ this.Box = box;
+ }
+
+ /// <summary>
+ /// Gets the <see cref="T:System.Text.Encoding"/> in which the output is written.
+ /// </summary>
+ /// <returns>
+ /// The Encoding in which the output is written.
+ /// </returns>
+ public override Encoding Encoding {
+ get { return Encoding.Unicode; }
+ }
+
+ /// <summary>
+ /// Gets the box to append to.
+ /// </summary>
+ internal TextBox Box { get; private set; }
+
+ /// <summary>
+ /// Writes a character to the text stream.
+ /// </summary>
+ /// <param name="value">The character to write to the text stream.</param>
+ /// <exception cref="T:System.ObjectDisposedException">
+ /// The <see cref="T:System.IO.TextWriter"/> is closed.
+ /// </exception>
+ /// <exception cref="T:System.IO.IOException">
+ /// An I/O error occurs.
+ /// </exception>
+ public override void Write(char value) {
+ this.Box.Dispatcher.BeginInvoke((Action<string>)this.AppendText, value.ToString());
+ }
+
+ /// <summary>
+ /// Writes a string to the text stream.
+ /// </summary>
+ /// <param name="value">The string to write.</param>
+ /// <exception cref="T:System.ObjectDisposedException">
+ /// The <see cref="T:System.IO.TextWriter"/> is closed.
+ /// </exception>
+ /// <exception cref="T:System.IO.IOException">
+ /// An I/O error occurs.
+ /// </exception>
+ public override void Write(string value) {
+ this.Box.Dispatcher.BeginInvoke((Action<string>)this.AppendText, value);
+ }
+
+ /// <summary>
+ /// Verifies conditions that should be true for any valid state of this object.
+ /// </summary>
+ [ContractInvariantMethod]
+ protected void ObjectInvariant() {
+ Contract.Invariant(this.Box != null);
+ }
+
+ /// <summary>
+ /// Appends text to the text box.
+ /// </summary>
+ /// <param name="value">The string to append.</param>
+ private void AppendText(string value) {
+ this.Box.AppendText(value);
+ this.Box.ScrollToEnd();
+ }
+ }
+}
diff --git a/samples/OpenIdOfflineProvider/openid.ico b/samples/OpenIdOfflineProvider/openid.ico
new file mode 100644
index 0000000..651aeba
--- /dev/null
+++ b/samples/OpenIdOfflineProvider/openid.ico
Binary files differ