Permalink
Browse files

Merge branch 'v3.0' into v3.1

Conflicts:
	src/DotNetOpenAuth.vsmdi
	src/DotNetOpenAuth/OpenId/OpenIdStrings.Designer.cs
	src/DotNetOpenAuth/OpenId/OpenIdStrings.resx
  • Loading branch information...
AArnott committed Sep 1, 2009
2 parents 0918f55 + 307ba2d commit 0488ebcfaef60e51bfcf7958b4a59d0ba5332a0f
Showing with 1,333 additions and 119 deletions.
  1. +34 −0 samples/OAuthConsumerWpf/App.config
  2. +7 −8 samples/OAuthConsumerWpf/Authorize.xaml.cs
  3. +71 −45 samples/OAuthConsumerWpf/MainWindow.xaml
  4. +79 −12 samples/OAuthConsumerWpf/MainWindow.xaml.cs
  5. +36 −0 samples/OAuthConsumerWpf/OAuthConsumerWpf.csproj
  6. +4 −0 samples/OAuthConsumerWpf/Service References/WcfSampleService/DataApi.disco
  7. +310 −0 samples/OAuthConsumerWpf/Service References/WcfSampleService/DataApi.wsdl
  8. +9 −0 samples/OAuthConsumerWpf/Service References/WcfSampleService/DataApi.xsd
  9. +40 −0 samples/OAuthConsumerWpf/Service References/WcfSampleService/DataApi1.xsd
  10. +42 −0 samples/OAuthConsumerWpf/Service References/WcfSampleService/DataApi2.xsd
  11. +67 −0 samples/OAuthConsumerWpf/Service References/WcfSampleService/Reference.cs
  12. +33 −0 samples/OAuthConsumerWpf/Service References/WcfSampleService/Reference.svcmap
  13. +10 −0 samples/OAuthConsumerWpf/Service References/WcfSampleService/configuration.svcinfo
  14. +210 −0 samples/OAuthConsumerWpf/Service References/WcfSampleService/configuration91.svcinfo
  15. +1 −1 samples/OAuthServiceProvider/App_Code/OAuthConsumer.cs
  16. +1 −1 samples/OAuthServiceProvider/App_Code/OAuthToken.cs
  17. +3 −0 samples/OAuthServiceProvider/Default.aspx
  18. +1 −1 samples/OpenIdProviderMvc/Controllers/UserController.cs
  19. +1 −0 src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj
  20. +11 −7 src/DotNetOpenAuth.Test/Hosting/HostingTests.cs
  21. +42 −0 src/DotNetOpenAuth.Test/Mocks/MockRealm.cs
  22. +22 −0 src/DotNetOpenAuth.Test/OpenId/AuthenticationTests.cs
  23. +13 −0 src/DotNetOpenAuth.Test/OpenId/OpenIdTestBase.cs
  24. +14 −9 src/DotNetOpenAuth.Test/OpenId/Provider/OpenIdProviderTests.cs
  25. +41 −0 src/DotNetOpenAuth.Test/OpenId/RelyingParty/OpenIdRelyingPartyTests.cs
  26. +3 −0 src/DotNetOpenAuth.sln
  27. +19 −16 src/DotNetOpenAuth.vsmdi
  28. +1 −0 src/DotNetOpenAuth/DotNetOpenAuth.csproj
  29. +5 −1 src/DotNetOpenAuth/OAuth/ChannelElements/OAuthChannel.cs
  30. +1 −1 src/DotNetOpenAuth/OAuth/ChannelElements/OAuthServiceProviderMessageFactory.cs
  31. +24 −3 src/DotNetOpenAuth/OAuth/ServiceProvider.cs
  32. +1 −1 src/DotNetOpenAuth/OpenId/DiffieHellmanUtilities.cs
  33. +2 −0 src/DotNetOpenAuth/OpenId/Extensions/SimpleRegistration/ClaimsRequest.cs
  34. +1 −1 src/DotNetOpenAuth/OpenId/HmacShaAssociation.cs
  35. +10 −0 src/DotNetOpenAuth/OpenId/Identifier.cs
  36. +10 −1 src/DotNetOpenAuth/OpenId/OpenIdStrings.Designer.cs
  37. +4 −1 src/DotNetOpenAuth/OpenId/OpenIdStrings.resx
  38. +1 −1 src/DotNetOpenAuth/OpenId/Provider/OpenIdProvider.cs
  39. +2 −2 src/DotNetOpenAuth/OpenId/Realm.cs
  40. +10 −0 src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdRelyingParty.cs
  41. +115 −0 src/DotNetOpenAuth/OpenId/RelyingParty/SimpleXrdsProviderEndpoint.cs
  42. +4 −0 src/DotNetOpenAuth/OpenId/RelyingPartyDescription.cs
  43. +14 −6 src/DotNetOpenAuth/OpenId/UriIdentifier.cs
  44. +3 −0 src/DotNetOpenAuth/OpenId/XriIdentifier.cs
  45. +1 −1 tools/Sandcastle/Presentation/vs2005/Content/shared_content.xml
@@ -57,4 +57,38 @@
<level value="ALL" />
</logger>
</log4net>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IDataApi" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="">
<extendedProtectionPolicy policyEnforcement="Never" />
</transport>
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" establishSecurityContext="true" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:65169/OAuthServiceProvider/DataApi.svc"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IDataApi"
contract="WcfSampleService.IDataApi" name="WSHttpBinding_IDataApi">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
@@ -20,20 +20,17 @@
/// Interaction logic for Authorize.xaml
/// </summary>
public partial class Authorize : Window {
private DesktopConsumer google;
private DesktopConsumer consumer;
private string requestToken;
internal Authorize(DesktopConsumer consumer) {
internal Authorize(DesktopConsumer consumer, FetchUri fetchUriCallback) {
InitializeComponent();
this.google = consumer;
this.consumer = consumer;
Cursor original = this.Cursor;
this.Cursor = Cursors.Wait;
ThreadPool.QueueUserWorkItem(delegate(object state) {
Uri browserAuthorizationLocation = GoogleConsumer.RequestAuthorization(
this.google,
GoogleConsumer.Applications.Contacts | GoogleConsumer.Applications.Blogger,
out this.requestToken);
Uri browserAuthorizationLocation = fetchUriCallback(this.consumer, out this.requestToken);
System.Diagnostics.Process.Start(browserAuthorizationLocation.AbsoluteUri);
this.Dispatcher.BeginInvoke(new Action(() => {
this.Cursor = original;
@@ -42,10 +39,12 @@ public partial class Authorize : Window {
});
}
internal delegate Uri FetchUri(DesktopConsumer consumer, out string requestToken);
internal string AccessToken { get; set; }
private void finishButton_Click(object sender, RoutedEventArgs e) {
var grantedAccess = this.google.ProcessUserAuthorization(this.requestToken, verifierBox.Text);
var grantedAccess = this.consumer.ProcessUserAuthorization(this.requestToken, verifierBox.Text);
this.AccessToken = grantedAccess.AccessToken;
DialogResult = true;
Close();
@@ -2,49 +2,75 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="DotNetOpenAuth Consumer (sample)" Height="400" Width="442">
<Grid Margin="5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>
<Button Grid.Column="1" Grid.Row="3" Name="beginAuthorizationButton" Click="beginAuthorizationButton_Click">Authorize</Button>
<TabControl Grid.ColumnSpan="2" Grid.Row="4" Name="tabControl1" Margin="0,10,0,0">
<TabItem Header="Gmail Contacts" Name="gmailContactsTab">
<Grid Name="contactsGrid">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
</Grid>
</TabItem>
<TabItem Header="Blogger" Name="bloggerTab">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Label>Blog URL</Label>
<TextBox Grid.Column="1" x:Name="blogUrlBox"/>
<Label Grid.Row="1">Title</Label>
<TextBox Grid.Row="1" Grid.Column="1" x:Name="postTitleBox">OAuth Rocks!</TextBox>
<Label Grid.Row="2">Body</Label>
<TextBox Grid.Row="2" Grid.Column="1" x:Name="postBodyBox" AcceptsReturn="True" AcceptsTab="True" AutoWordSelection="True" TextWrapping="WrapWithOverflow">&lt;p xmlns="http://www.w3.org/1999/xhtml"&gt;Oauth is cool&lt;/p&gt;</TextBox>
<Button x:Name="postButton" Grid.Row="3" Grid.Column="1" Click="postButton_Click" IsEnabled="False">Post</Button>
</Grid>
</TabItem>
</TabControl>
</Grid>
<TabControl Name="outerTabControl" Margin="0,10,0,0">
<TabItem Header="Google" Name="googleTab">
<Grid Margin="5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>
<Button Grid.Column="1" Grid.Row="3" Name="beginAuthorizationButton" Click="beginAuthorizationButton_Click">Authorize</Button>
<TabControl Grid.ColumnSpan="2" Grid.Row="4" Name="tabControl1" Margin="0,10,0,0">
<TabItem Header="Gmail Contacts" Name="gmailContactsTab">
<Grid Name="contactsGrid">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
</Grid>
</TabItem>
<TabItem Header="Blogger" Name="bloggerTab">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Label>Blog URL</Label>
<TextBox Grid.Column="1" x:Name="blogUrlBox"/>
<Label Grid.Row="1">Title</Label>
<TextBox Grid.Row="1" Grid.Column="1" x:Name="postTitleBox">OAuth Rocks!</TextBox>
<Label Grid.Row="2">Body</Label>
<TextBox Grid.Row="2" Grid.Column="1" x:Name="postBodyBox" AcceptsReturn="True" AcceptsTab="True" AutoWordSelection="True" TextWrapping="WrapWithOverflow">&lt;p xmlns="http://www.w3.org/1999/xhtml"&gt;Oauth is cool&lt;/p&gt;</TextBox>
<Button x:Name="postButton" Grid.Row="3" Grid.Column="1" Click="postButton_Click" IsEnabled="False">Post</Button>
</Grid>
</TabItem>
</TabControl>
</Grid>
</TabItem>
<TabItem Header="WCF sample">
<Grid Margin="5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>
<Button Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="0" Name="beginWcfAuthorizationButton" Click="beginWcfAuthorizationButton_Click">Authorize</Button>
<Label Content="Name" Grid.Row="1" />
<Label Grid.Row="1" Grid.Column="1" Name="wcfName" />
<Label Content="Age" Grid.Row="2" />
<Label Grid.Row="2" Grid.Column="1" Name="wcfAge" />
<Label Content="Favorite sites" Grid.Row="3" />
<Label Grid.Row="3" Grid.Column="1" Name="wcfFavoriteSites" />
</Grid>
</TabItem>
</TabControl>
</Window>
@@ -3,7 +3,10 @@
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Net;
using System.Security.Cryptography.X509Certificates;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Text;
using System.Threading;
using System.Windows;
@@ -23,45 +26,78 @@
using DotNetOpenAuth.Messaging;
using DotNetOpenAuth.OAuth;
using DotNetOpenAuth.OAuth.ChannelElements;
using DotNetOpenAuth.Samples.OAuthConsumerWpf.WcfSampleService;
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window {
private InMemoryTokenManager tokenManager = new InMemoryTokenManager();
private InMemoryTokenManager googleTokenManager = new InMemoryTokenManager();
private DesktopConsumer google;
private string accessToken;
private string googleAccessToken;
private InMemoryTokenManager wcfTokenManager = new InMemoryTokenManager();
private DesktopConsumer wcf;
private string wcfAccessToken;
public MainWindow() {
InitializeComponent();
this.InitializeComponent();
this.tokenManager.ConsumerKey = ConfigurationManager.AppSettings["googleConsumerKey"];
this.tokenManager.ConsumerSecret = ConfigurationManager.AppSettings["googleConsumerSecret"];
this.InitializeGoogleConsumer();
this.InitializeWcfConsumer();
}
private void InitializeGoogleConsumer() {
this.googleTokenManager.ConsumerKey = ConfigurationManager.AppSettings["googleConsumerKey"];
this.googleTokenManager.ConsumerSecret = ConfigurationManager.AppSettings["googleConsumerSecret"];
string pfxFile = ConfigurationManager.AppSettings["googleConsumerCertificateFile"];
if (string.IsNullOrEmpty(pfxFile)) {
this.google = new DesktopConsumer(GoogleConsumer.ServiceDescription, this.tokenManager);
this.google = new DesktopConsumer(GoogleConsumer.ServiceDescription, this.googleTokenManager);
} else {
string pfxPassword = ConfigurationManager.AppSettings["googleConsumerCertificatePassword"];
var signingCertificate = new X509Certificate2(pfxFile, pfxPassword);
var service = GoogleConsumer.CreateRsaSha1ServiceDescription(signingCertificate);
this.google = new DesktopConsumer(service, this.tokenManager);
this.google = new DesktopConsumer(service, this.googleTokenManager);
}
}
private void InitializeWcfConsumer() {
this.wcfTokenManager.ConsumerKey = "sampleconsumer";
this.wcfTokenManager.ConsumerSecret = "samplesecret";
MessageReceivingEndpoint oauthEndpoint = new MessageReceivingEndpoint(
new Uri("http://localhost:65169/OAuthServiceProvider/OAuth.ashx"),
HttpDeliveryMethods.PostRequest);
this.wcf = new DesktopConsumer(
new ServiceProviderDescription {
RequestTokenEndpoint = oauthEndpoint,
UserAuthorizationEndpoint = oauthEndpoint,
AccessTokenEndpoint = oauthEndpoint,
TamperProtectionElements = new DotNetOpenAuth.Messaging.ITamperProtectionChannelBindingElement[] {
new HmacSha1SigningBindingElement(),
},
},
this.wcfTokenManager);
}
private void beginAuthorizationButton_Click(object sender, RoutedEventArgs e) {
if (string.IsNullOrEmpty(this.tokenManager.ConsumerKey)) {
if (string.IsNullOrEmpty(this.googleTokenManager.ConsumerKey)) {
MessageBox.Show(this, "You must modify the App.config or OAuthConsumerWpf.exe.config file for this application to include your Google OAuth consumer key first.", "Configuration required", MessageBoxButton.OK, MessageBoxImage.Stop);
return;
}
Authorize auth = new Authorize(this.google);
Authorize auth = new Authorize(
this.google,
(DesktopConsumer consumer, out string requestToken) =>
GoogleConsumer.RequestAuthorization(
consumer,
GoogleConsumer.Applications.Contacts | GoogleConsumer.Applications.Blogger,
out requestToken));
bool? result = auth.ShowDialog();
if (result.HasValue && result.Value) {
this.accessToken = auth.AccessToken;
this.googleAccessToken = auth.AccessToken;
postButton.IsEnabled = true;
XDocument contactsDocument = GoogleConsumer.GetContacts(this.google, this.accessToken);
XDocument contactsDocument = GoogleConsumer.GetContacts(this.google, this.googleAccessToken);
var contacts = from entry in contactsDocument.Root.Elements(XName.Get("entry", "http://www.w3.org/2005/Atom"))
select new { Name = entry.Element(XName.Get("title", "http://www.w3.org/2005/Atom")).Value, Email = entry.Element(XName.Get("email", "http://schemas.google.com/g/2005")).Attribute("address").Value };
contactsGrid.Children.Clear();
@@ -80,7 +116,38 @@ public partial class MainWindow : Window {
private void postButton_Click(object sender, RoutedEventArgs e) {
XElement postBodyXml = XElement.Parse(postBodyBox.Text);
GoogleConsumer.PostBlogEntry(this.google, this.accessToken, blogUrlBox.Text, postTitleBox.Text, postBodyXml);
GoogleConsumer.PostBlogEntry(this.google, this.googleAccessToken, blogUrlBox.Text, postTitleBox.Text, postBodyXml);
}
private void beginWcfAuthorizationButton_Click(object sender, RoutedEventArgs e) {
var requestArgs = new Dictionary<string, string>();
requestArgs["scope"] = "http://tempuri.org/IDataApi/GetName|http://tempuri.org/IDataApi/GetAge|http://tempuri.org/IDataApi/GetFavoriteSites";
Authorize auth = new Authorize(
this.wcf,
(DesktopConsumer consumer, out string requestToken) => consumer.RequestUserAuthorization(requestArgs, null, out requestToken));
bool? result = auth.ShowDialog();
if (result.HasValue && result.Value) {
this.wcfAccessToken = auth.AccessToken;
wcfName.Content = CallService(client => client.GetName());
wcfAge.Content = CallService(client => client.GetAge());
wcfFavoriteSites.Content = CallService(client => string.Join(", ", client.GetFavoriteSites()));
}
}
private T CallService<T>(Func<DataApiClient, T> predicate) {
DataApiClient client = new DataApiClient();
var serviceEndpoint = new MessageReceivingEndpoint(client.Endpoint.Address.Uri, HttpDeliveryMethods.AuthorizationHeaderRequest | HttpDeliveryMethods.PostRequest);
if (this.wcfAccessToken == null) {
throw new InvalidOperationException("No access token!");
}
WebRequest httpRequest = this.wcf.PrepareAuthorizedRequest(serviceEndpoint, this.wcfAccessToken);
HttpRequestMessageProperty httpDetails = new HttpRequestMessageProperty();
httpDetails.Headers[HttpRequestHeader.Authorization] = httpRequest.Headers[HttpRequestHeader.Authorization];
using (OperationContextScope scope = new OperationContextScope(client.InnerChannel)) {
OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = httpDetails;
return predicate(client);
}
}
}
}
Oops, something went wrong.

0 comments on commit 0488ebc

Please sign in to comment.