diff options
-rw-r--r-- | samples/OpenIdOfflineProvider/CheckIdWindow.xaml.cs | 6 | ||||
-rw-r--r-- | samples/OpenIdOfflineProvider/HostedProvider.cs | 102 | ||||
-rw-r--r-- | samples/OpenIdOfflineProvider/MainWindow.xaml | 35 | ||||
-rw-r--r-- | samples/OpenIdOfflineProvider/MainWindow.xaml.cs | 33 | ||||
-rw-r--r-- | samples/OpenIdOfflineProvider/OpenIdOfflineProvider.csproj | 4 | ||||
-rw-r--r-- | samples/OpenIdOfflineProvider/openid.ico | bin | 0 -> 17006 bytes | |||
-rw-r--r-- | src/DotNetOpenAuth/Properties/AssemblyInfo.cs | 2 |
7 files changed, 124 insertions, 58 deletions
diff --git a/samples/OpenIdOfflineProvider/CheckIdWindow.xaml.cs b/samples/OpenIdOfflineProvider/CheckIdWindow.xaml.cs index cb8b6c9..279f15f 100644 --- a/samples/OpenIdOfflineProvider/CheckIdWindow.xaml.cs +++ b/samples/OpenIdOfflineProvider/CheckIdWindow.xaml.cs @@ -44,8 +44,10 @@ namespace DotNetOpenAuth.OpenIdOfflineProvider { this.discoverableYesLabel.Visibility = isRPDiscoverable ? Visibility.Visible : Visibility.Collapsed; this.discoverableNoLabel.Visibility = isRPDiscoverable ? Visibility.Collapsed : Visibility.Visible; - this.claimedIdentifierBox.Text = request.ClaimedIdentifier; - this.localIdentifierBox.Text = request.LocalIdentifier; + if (!request.IsDirectedIdentity) { + this.claimedIdentifierBox.Text = request.ClaimedIdentifier; + this.localIdentifierBox.Text = request.LocalIdentifier; + } } /// <summary> diff --git a/samples/OpenIdOfflineProvider/HostedProvider.cs b/samples/OpenIdOfflineProvider/HostedProvider.cs index 9636b44..5efaf9b 100644 --- a/samples/OpenIdOfflineProvider/HostedProvider.cs +++ b/samples/OpenIdOfflineProvider/HostedProvider.cs @@ -9,9 +9,11 @@ namespace DotNetOpenAuth.OpenIdOfflineProvider { 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. @@ -25,22 +27,22 @@ namespace DotNetOpenAuth.OpenIdOfflineProvider { /// <summary> /// The path to the OP Identifier. /// </summary> - private const string OPIdentifier = "/"; + private const string OPIdentifierPath = "/"; /// <summary> - /// The path to the user identity page that always generates a positive assertion. + /// The URL path with which all user identities must start. /// </summary> - private const string YesIdentity = "/user"; + private const string UserIdentifierPath = "/user/"; /// <summary> - /// The path to the user identity page that always generates a negative response. + /// The <see cref="OpenIdProvider"/> instance that processes incoming requests. /// </summary> - private const string NoIdentity = "/no"; + private OpenIdProvider provider = new OpenIdProvider(new StandardProviderApplicationStore()); /// <summary> - /// The <see cref="OpenIdProvider"/> instance that processes incoming requests. + /// The logger the class may use. /// </summary> - private OpenIdProvider provider = new OpenIdProvider(new StandardProviderApplicationStore()); + private ILog logger = log4net.LogManager.GetLogger(typeof(HostedProvider)); /// <summary> /// The HTTP listener that acts as the OpenID Provider socket. @@ -51,8 +53,6 @@ namespace DotNetOpenAuth.OpenIdOfflineProvider { /// Initializes a new instance of the <see cref="HostedProvider"/> class. /// </summary> internal HostedProvider() { - this.AffirmativeIdentities = new HashSet<Uri>(); - this.NegativeIdentities = new HashSet<Uri>(); } /// <summary> @@ -66,16 +66,6 @@ namespace DotNetOpenAuth.OpenIdOfflineProvider { } /// <summary> - /// Gets a collection of identity URLs that always produce positive assertions. - /// </summary> - internal ICollection<Uri> AffirmativeIdentities { get; private set; } - - /// <summary> - /// Gets a collection of identity URLs that always produce cancellation responses. - /// </summary> - internal ICollection<Uri> NegativeIdentities { get; private set; } - - /// <summary> /// Gets the <see cref="OpenIdProvider"/> instance that processes incoming requests. /// </summary> internal OpenIdProvider Provider { @@ -98,6 +88,20 @@ namespace DotNetOpenAuth.OpenIdOfflineProvider { internal Action<IAuthenticationRequest> ProcessAuthenticationRequest { get; set; } /// <summary> + /// Gets the OP identifier. + /// </summary> + internal Uri OPIdentifier { + get { + UriBuilder providerEndpointBuilder = new UriBuilder(); + providerEndpointBuilder.Scheme = Uri.UriSchemeHttp; + providerEndpointBuilder.Host = "localhost"; + providerEndpointBuilder.Port = this.httpHost.Port; + providerEndpointBuilder.Path = OPIdentifierPath; + return providerEndpointBuilder.Uri; + } + } + + /// <summary> /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. /// </summary> public void Dispose() { @@ -110,8 +114,6 @@ namespace DotNetOpenAuth.OpenIdOfflineProvider { internal void StartProvider() { Contract.Ensures(this.IsRunning); this.httpHost = HttpHost.CreateHost(this.RequestHandler); - this.AffirmativeIdentities.Add(new Uri(this.httpHost.BaseUri, YesIdentity)); - this.NegativeIdentities.Add(new Uri(this.httpHost.BaseUri, NoIdentity)); } /// <summary> @@ -150,8 +152,8 @@ namespace DotNetOpenAuth.OpenIdOfflineProvider { /// <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(string providerEndpoint, string localId) { - Contract.Requires(providerEndpoint != null && providerEndpoint.Length > 0); + private static string GenerateHtmlDiscoveryDocument(Uri providerEndpoint, string localId) { + Contract.Requires(providerEndpoint != null); const string DelegatedHtmlDiscoveryFormat = @"<html><head> <link rel=""openid.server"" href=""{0}"" /> @@ -167,11 +169,43 @@ namespace DotNetOpenAuth.OpenIdOfflineProvider { return string.Format( localId != null ? DelegatedHtmlDiscoveryFormat : NonDelegatedHtmlDiscoveryFormat, - providerEndpoint, + 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> @@ -182,6 +216,13 @@ namespace DotNetOpenAuth.OpenIdOfflineProvider { 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); IRequest providerRequest = this.Provider.GetRequest(requestInfo); @@ -200,15 +241,22 @@ namespace DotNetOpenAuth.OpenIdOfflineProvider { } this.Provider.PrepareResponse(providerRequest).Send(context.Response); - } else if (context.Request.Url.AbsolutePath == YesIdentity || context.Request.Url.AbsolutePath == NoIdentity) { + } else if (context.Request.Url.AbsolutePath.StartsWith(UserIdentifierPath, StringComparison.Ordinal)) { using (StreamWriter sw = new StreamWriter(outputStream)) { - string providerEndpoint = string.Format("http://localhost:{0}{1}", context.Request.Url.Port, ProviderPath); + 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 = DotNetOpenAuth.Yadis.ContentTypes.Xrds; context.Response.StatusCode = (int)HttpStatusCode.OK; + this.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; diff --git a/samples/OpenIdOfflineProvider/MainWindow.xaml b/samples/OpenIdOfflineProvider/MainWindow.xaml index 80a9fe4..80fd4ea 100644 --- a/samples/OpenIdOfflineProvider/MainWindow.xaml +++ b/samples/OpenIdOfflineProvider/MainWindow.xaml @@ -2,7 +2,7 @@ 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> + <Grid Margin="4"> <Grid.RowDefinitions> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> @@ -14,19 +14,28 @@ <Grid.ColumnDefinitions> <ColumnDefinition Width="auto" /> <ColumnDefinition /> + <ColumnDefinition Width="auto" /> </Grid.ColumnDefinitions> - <Label >Port</Label> - <Label Name="portLabel" Grid.Column="1" /> <Label Grid.Row="1">OP Identifier</Label> - <Label Grid.Column="1" Grid.Row="1" Name="opIdentifierLabel"></Label> - <Label Grid.Row="2">Yes Identifier</Label> - <Label Grid.Column="1" Grid.Row="2" Name="yesIdentity" ></Label> - <Label Grid.Row="3">No Identifier</Label> - <Label Grid.Column="1" Grid.Row="3" Name="noIdentity" ></Label> - <StackPanel Orientation="Horizontal" Grid.Row="4" Grid.ColumnSpan="2"> - <Button Name="startButton" Click="startButton_Click" Padding="10,0,10,0">Start</Button> - <Button Name="stopButton" Click="stopButton_Click" Padding="10,0,10,0">Stop</Button> - </StackPanel> - <TextBox Height="auto" Grid.Row="5" Grid.ColumnSpan="2" Name="logBox" IsReadOnly="True" VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Auto" /> + <Label Grid.Column="1" Grid.Row="1" Name="opIdentifierLabel" ToolTip="Click to copy URI to clipboard" MouseDown="opIdentifierLabel_MouseDown" /> + <Label Grid.Row="2">associate requests</Label> + <ComboBox Grid.Column="1" Grid.Row="2" Name="associateRequestList" SelectedIndex="0"> + <ComboBoxItem>Auto respond</ComboBoxItem> + <ComboBoxItem>Intercept</ComboBoxItem> + </ComboBox> + <Button Grid.Column="2" Grid.Row="2">Configure</Button> + <Label Grid.Row="3">checkid requests</Label> + <ComboBox Grid.Column="1" Grid.Row="3" Name="checkidRequestList" SelectedIndex="0"> + <ComboBoxItem>Auto respond</ComboBoxItem> + <ComboBoxItem>Intercept</ComboBoxItem> + </ComboBox> + <Button Grid.Column="2" Grid.Row="3">Configure</Button> + <Label Grid.Row="4">check__auth requests</Label> + <ComboBox Grid.Column="1" Grid.Row="4" Name="checkauthRequestList" SelectedIndex="0"> + <ComboBoxItem>Auto respond</ComboBoxItem> + <ComboBoxItem>Intercept</ComboBoxItem> + </ComboBox> + <Button Grid.Column="2" Grid.Row="4">Configure</Button> + <TextBox Height="auto" Grid.Row="5" Grid.ColumnSpan="3" Name="logBox" IsReadOnly="True" VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Auto" /> </Grid> </Window> diff --git a/samples/OpenIdOfflineProvider/MainWindow.xaml.cs b/samples/OpenIdOfflineProvider/MainWindow.xaml.cs index 9b8061c..bd4f0a0 100644 --- a/samples/OpenIdOfflineProvider/MainWindow.xaml.cs +++ b/samples/OpenIdOfflineProvider/MainWindow.xaml.cs @@ -51,6 +51,8 @@ namespace DotNetOpenAuth.OpenIdOfflineProvider { if (boxLogger != null) { boxLogger.Writer = new TextBoxTextWriter(logBox); } + + this.startProvider(); } #region IDisposable Members @@ -84,34 +86,33 @@ namespace DotNetOpenAuth.OpenIdOfflineProvider { /// </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.hostedProvider.StopProvider(); + this.stopProvider(); base.OnClosing(e); } /// <summary> - /// Handles the Click event of the startButton control. + /// Starts the provider. /// </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 startButton_Click(object sender, RoutedEventArgs e) { + private void startProvider() { this.hostedProvider.StartProvider(); - this.portLabel.Content = this.hostedProvider.ProviderEndpoint.Port; - this.opIdentifierLabel.Content = "not yet supported"; // string.Format(url, this.httpHost.Port, OPIdentifier); - this.noIdentity.Content = this.hostedProvider.NegativeIdentities.First().AbsoluteUri; - this.yesIdentity.Content = this.hostedProvider.AffirmativeIdentities.First().AbsoluteUri; + this.opIdentifierLabel.Content = this.hostedProvider.OPIdentifier; } /// <summary> - /// Handles the Click event of the stopButton control. + /// Stops the provider. /// </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 stopButton_Click(object sender, RoutedEventArgs e) { + private void stopProvider() { this.hostedProvider.StopProvider(); - this.portLabel.Content = string.Empty; - this.noIdentity.Content = string.Empty; - this.yesIdentity.Content = string.Empty; 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) { + Clipboard.SetText(opIdentifierLabel.Content.ToString()); + } } } diff --git a/samples/OpenIdOfflineProvider/OpenIdOfflineProvider.csproj b/samples/OpenIdOfflineProvider/OpenIdOfflineProvider.csproj index 9b884aa..5b59b7d 100644 --- a/samples/OpenIdOfflineProvider/OpenIdOfflineProvider.csproj +++ b/samples/OpenIdOfflineProvider/OpenIdOfflineProvider.csproj @@ -15,6 +15,7 @@ <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> @@ -155,6 +156,9 @@ <Name>DotNetOpenAuth</Name> </ProjectReference> </ItemGroup> + <ItemGroup> + <Resource Include="openid.ico" /> + </ItemGroup> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <!-- To modify your build process, add your task inside one of the targets below and uncomment it. Other similar extension points exist, see Microsoft.Common.targets. diff --git a/samples/OpenIdOfflineProvider/openid.ico b/samples/OpenIdOfflineProvider/openid.ico Binary files differnew file mode 100644 index 0000000..651aeba --- /dev/null +++ b/samples/OpenIdOfflineProvider/openid.ico diff --git a/src/DotNetOpenAuth/Properties/AssemblyInfo.cs b/src/DotNetOpenAuth/Properties/AssemblyInfo.cs index 69d4dc4..25d8c9f 100644 --- a/src/DotNetOpenAuth/Properties/AssemblyInfo.cs +++ b/src/DotNetOpenAuth/Properties/AssemblyInfo.cs @@ -65,8 +65,10 @@ using System.Web.UI; // keep this assembly from being useful to shared host (medium trust) web sites. [assembly: AllowPartiallyTrustedCallers] +[assembly: InternalsVisibleTo("OpenIdOfflineProvider, PublicKey=0024000004800000940000000602000000240000525341310004000001000100AD093C3765257C89A7010E853F2C7C741FF92FA8ACE06D7B8254702CAD5CF99104447F63AB05F8BB6F51CE0D81C8C93D2FCE8C20AAFF7042E721CBA16EAAE98778611DED11C0ABC8900DC5667F99B50A9DADEC24DBD8F2C91E3E8AD300EF64F1B4B9536CEB16FB440AF939F57624A9B486F867807C649AE4830EAB88C6C03998")] [assembly: InternalsVisibleTo("DotNetOpenAuth.Test, PublicKey=0024000004800000940000000602000000240000525341310004000001000100AD093C3765257C89A7010E853F2C7C741FF92FA8ACE06D7B8254702CAD5CF99104447F63AB05F8BB6F51CE0D81C8C93D2FCE8C20AAFF7042E721CBA16EAAE98778611DED11C0ABC8900DC5667F99B50A9DADEC24DBD8F2C91E3E8AD300EF64F1B4B9536CEB16FB440AF939F57624A9B486F867807C649AE4830EAB88C6C03998")] #else +[assembly: InternalsVisibleTo("OpenIdOfflineProvider")] [assembly: InternalsVisibleTo("DotNetOpenAuth.Test")] #endif |