diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2009-04-25 22:09:28 -0700 |
---|---|---|
committer | Andrew Arnott <andrewarnott@gmail.com> | 2009-04-25 22:09:28 -0700 |
commit | c7ec035307552a4ed1be95b955d9c6a3553924ff (patch) | |
tree | bca727e7a69b910cd3ca452391dc262ea32ccf93 /samples | |
parent | 54776ee65a6df3a3a98f911879d8df9ce4bc9023 (diff) | |
download | DotNetOpenAuth-c7ec035307552a4ed1be95b955d9c6a3553924ff.zip DotNetOpenAuth-c7ec035307552a4ed1be95b955d9c6a3553924ff.tar.gz DotNetOpenAuth-c7ec035307552a4ed1be95b955d9c6a3553924ff.tar.bz2 |
Added user interactivity to begin to customize auth responses to the OpenIdOfflineProvider tool.
Diffstat (limited to 'samples')
-rw-r--r-- | samples/OpenIdOfflineProvider/App.config | 10 | ||||
-rw-r--r-- | samples/OpenIdOfflineProvider/CheckIdWindow.xaml | 84 | ||||
-rw-r--r-- | samples/OpenIdOfflineProvider/CheckIdWindow.xaml.cs | 88 | ||||
-rw-r--r-- | samples/OpenIdOfflineProvider/HostedProvider.cs | 31 | ||||
-rw-r--r-- | samples/OpenIdOfflineProvider/MainWindow.xaml.cs | 3 | ||||
-rw-r--r-- | samples/OpenIdOfflineProvider/OpenIdOfflineProvider.csproj | 17 |
6 files changed, 219 insertions, 14 deletions
diff --git a/samples/OpenIdOfflineProvider/App.config b/samples/OpenIdOfflineProvider/App.config index 93e2027..cd04b13 100644 --- a/samples/OpenIdOfflineProvider/App.config +++ b/samples/OpenIdOfflineProvider/App.config @@ -4,6 +4,16 @@ <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" /> diff --git a/samples/OpenIdOfflineProvider/CheckIdWindow.xaml b/samples/OpenIdOfflineProvider/CheckIdWindow.xaml new file mode 100644 index 0000000..9ffe919 --- /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"> + <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"> + <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..cb8b6c9 --- /dev/null +++ b/samples/OpenIdOfflineProvider/CheckIdWindow.xaml.cs @@ -0,0 +1,88 @@ +//----------------------------------------------------------------------- +// <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; + + 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); + + App.Current.Dispatcher.Invoke((Action)delegate { + 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 index 7a8cf01..9636b44 100644 --- a/samples/OpenIdOfflineProvider/HostedProvider.cs +++ b/samples/OpenIdOfflineProvider/HostedProvider.cs @@ -52,7 +52,7 @@ namespace DotNetOpenAuth.OpenIdOfflineProvider { /// </summary> internal HostedProvider() { this.AffirmativeIdentities = new HashSet<Uri>(); - this.NegativeIdentitities = new HashSet<Uri>(); + this.NegativeIdentities = new HashSet<Uri>(); } /// <summary> @@ -73,7 +73,14 @@ namespace DotNetOpenAuth.OpenIdOfflineProvider { /// <summary> /// Gets a collection of identity URLs that always produce cancellation responses. /// </summary> - internal ICollection<Uri> NegativeIdentitities { get; private set; } + internal ICollection<Uri> NegativeIdentities { get; private set; } + + /// <summary> + /// Gets the <see cref="OpenIdProvider"/> instance that processes incoming requests. + /// </summary> + internal OpenIdProvider Provider { + get { return this.provider; } + } /// <summary> /// Gets the provider endpoint. @@ -86,6 +93,11 @@ namespace DotNetOpenAuth.OpenIdOfflineProvider { } /// <summary> + /// Gets or sets the delegate that handles authentication requests. + /// </summary> + internal Action<IAuthenticationRequest> ProcessAuthenticationRequest { get; set; } + + /// <summary> /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. /// </summary> public void Dispose() { @@ -99,7 +111,7 @@ namespace DotNetOpenAuth.OpenIdOfflineProvider { Contract.Ensures(this.IsRunning); this.httpHost = HttpHost.CreateHost(this.RequestHandler); this.AffirmativeIdentities.Add(new Uri(this.httpHost.BaseUri, YesIdentity)); - this.NegativeIdentitities.Add(new Uri(this.httpHost.BaseUri, NoIdentity)); + this.NegativeIdentities.Add(new Uri(this.httpHost.BaseUri, NoIdentity)); } /// <summary> @@ -166,12 +178,13 @@ namespace DotNetOpenAuth.OpenIdOfflineProvider { private void RequestHandler(HttpListenerContext context) { Contract.Requires(context != null); Contract.Requires(context.Response.OutputStream != null); + Contract.Requires(this.ProcessAuthenticationRequest != null); Stream outputStream = context.Response.OutputStream; Contract.Assume(outputStream != null); // CC static verification shortcoming. if (context.Request.Url.AbsolutePath == ProviderPath) { HttpRequestInfo requestInfo = new HttpRequestInfo(context.Request); - IRequest providerRequest = this.provider.GetRequest(requestInfo); + 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; @@ -182,15 +195,11 @@ namespace DotNetOpenAuth.OpenIdOfflineProvider { } if (!providerRequest.IsResponseReady) { - var authRequest = providerRequest as IAuthenticationRequest; - if (authRequest.IsDirectedIdentity) { - throw new NotImplementedException(); - } - - authRequest.IsAuthenticated = new Uri(authRequest.ClaimedIdentifier).AbsolutePath == YesIdentity; + var authRequest = (IAuthenticationRequest)providerRequest; + this.ProcessAuthenticationRequest(authRequest); } - this.provider.PrepareResponse(providerRequest).Send(context.Response); + this.Provider.PrepareResponse(providerRequest).Send(context.Response); } else if (context.Request.Url.AbsolutePath == YesIdentity || context.Request.Url.AbsolutePath == NoIdentity) { using (StreamWriter sw = new StreamWriter(outputStream)) { string providerEndpoint = string.Format("http://localhost:{0}{1}", context.Request.Url.Port, ProviderPath); diff --git a/samples/OpenIdOfflineProvider/MainWindow.xaml.cs b/samples/OpenIdOfflineProvider/MainWindow.xaml.cs index d6332dd..9b8061c 100644 --- a/samples/OpenIdOfflineProvider/MainWindow.xaml.cs +++ b/samples/OpenIdOfflineProvider/MainWindow.xaml.cs @@ -46,6 +46,7 @@ namespace DotNetOpenAuth.OpenIdOfflineProvider { /// </summary> public MainWindow() { this.InitializeComponent(); + this.hostedProvider.ProcessAuthenticationRequest = request => CheckIdWindow.ProcessAuthentication(this.hostedProvider, request); TextWriterAppender boxLogger = log4net.LogManager.GetRepository().GetAppenders().OfType<TextWriterAppender>().FirstOrDefault(a => a.Name == "TextBoxAppender"); if (boxLogger != null) { boxLogger.Writer = new TextBoxTextWriter(logBox); @@ -96,7 +97,7 @@ namespace DotNetOpenAuth.OpenIdOfflineProvider { 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.NegativeIdentitities.First().AbsoluteUri; + this.noIdentity.Content = this.hostedProvider.NegativeIdentities.First().AbsoluteUri; this.yesIdentity.Content = this.hostedProvider.AffirmativeIdentities.First().AbsoluteUri; } diff --git a/samples/OpenIdOfflineProvider/OpenIdOfflineProvider.csproj b/samples/OpenIdOfflineProvider/OpenIdOfflineProvider.csproj index 3e9970c..9b884aa 100644 --- a/samples/OpenIdOfflineProvider/OpenIdOfflineProvider.csproj +++ b/samples/OpenIdOfflineProvider/OpenIdOfflineProvider.csproj @@ -24,13 +24,13 @@ <DefineConstants>DEBUG;TRACE</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> - <CodeContractsEnableRuntimeChecking>True</CodeContractsEnableRuntimeChecking> + <CodeContractsEnableRuntimeChecking>False</CodeContractsEnableRuntimeChecking> <CodeContractsCustomRewriterAssembly> </CodeContractsCustomRewriterAssembly> <CodeContractsCustomRewriterClass> </CodeContractsCustomRewriterClass> <CodeContractsRuntimeCheckingLevel>Full</CodeContractsRuntimeCheckingLevel> - <CodeContractsRunCodeAnalysis>True</CodeContractsRunCodeAnalysis> + <CodeContractsRunCodeAnalysis>False</CodeContractsRunCodeAnalysis> <CodeContractsBuildReferenceAssembly>False</CodeContractsBuildReferenceAssembly> <CodeContractsNonNullObligations>False</CodeContractsNonNullObligations> <CodeContractsBoundsObligations>False</CodeContractsBoundsObligations> @@ -46,6 +46,7 @@ <CodeContractsUseBaseLine>False</CodeContractsUseBaseLine> <CodeContractsRunInBackground>True</CodeContractsRunInBackground> <CodeContractsShowSquigglies>True</CodeContractsShowSquigglies> + <CodeContractsRuntimeOnlyPublicSurface>False</CodeContractsRuntimeOnlyPublicSurface> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <DebugType>pdbonly</DebugType> @@ -55,6 +56,11 @@ <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> @@ -95,6 +101,10 @@ <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> @@ -109,6 +119,9 @@ </Compile> </ItemGroup> <ItemGroup> + <Compile Include="CheckIdWindow.xaml.cs"> + <DependentUpon>CheckIdWindow.xaml</DependentUpon> + </Compile> <Compile Include="HostedProvider.cs" /> <Compile Include="HttpHost.cs" /> <Compile Include="Properties\AssemblyInfo.cs"> |