summaryrefslogtreecommitdiffstats
path: root/samples
diff options
context:
space:
mode:
Diffstat (limited to 'samples')
-rw-r--r--samples/DotNetOpenAuth.ApplicationBlock/GoogleConsumer.cs26
-rw-r--r--samples/DotNetOpenAuth.ApplicationBlock/TwitterConsumer.cs28
-rw-r--r--samples/OAuthConsumer/App_Code/InMemoryTokenManager.cs2
-rw-r--r--samples/OAuthConsumer/GoogleAddressBook.aspx.cs5
-rw-r--r--samples/OAuthConsumer/SampleWcf.aspx.cs4
-rw-r--r--samples/OAuthConsumer/Twitter.aspx.cs9
-rw-r--r--samples/OAuthConsumerWpf/InMemoryTokenManager.cs6
-rw-r--r--samples/OAuthConsumerWpf/MainWindow.xaml.cs3
-rw-r--r--samples/OAuthServiceProvider/App_Code/CustomOAuthTypeProvider.cs2
-rw-r--r--samples/OAuthServiceProvider/App_Code/DatabaseTokenManager.cs8
10 files changed, 23 insertions, 70 deletions
diff --git a/samples/DotNetOpenAuth.ApplicationBlock/GoogleConsumer.cs b/samples/DotNetOpenAuth.ApplicationBlock/GoogleConsumer.cs
index c6f2b89..83196db 100644
--- a/samples/DotNetOpenAuth.ApplicationBlock/GoogleConsumer.cs
+++ b/samples/DotNetOpenAuth.ApplicationBlock/GoogleConsumer.cs
@@ -26,7 +26,7 @@ namespace DotNetOpenAuth.ApplicationBlock {
/// <summary>
/// The Consumer to use for accessing Google data APIs.
/// </summary>
- private static readonly ServiceProviderDescription GoogleDescription = new ServiceProviderDescription {
+ public static readonly ServiceProviderDescription ServiceDescription = new ServiceProviderDescription {
RequestTokenEndpoint = new MessageReceivingEndpoint("https://www.google.com/accounts/OAuthGetRequestToken", HttpDeliveryMethods.AuthorizationHeaderRequest | HttpDeliveryMethods.GetRequest),
UserAuthorizationEndpoint = new MessageReceivingEndpoint("https://www.google.com/accounts/OAuthAuthorizeToken", HttpDeliveryMethods.AuthorizationHeaderRequest | HttpDeliveryMethods.GetRequest),
AccessTokenEndpoint = new MessageReceivingEndpoint("https://www.google.com/accounts/OAuthGetAccessToken", HttpDeliveryMethods.AuthorizationHeaderRequest | HttpDeliveryMethods.GetRequest),
@@ -69,30 +69,6 @@ namespace DotNetOpenAuth.ApplicationBlock {
}
/// <summary>
- /// Initializes a new instance of the <see cref="WebConsumer"/> class that is prepared to communicate with Google.
- /// </summary>
- /// <param name="tokenManager">The token manager.</param>
- /// <param name="consumerKey">The consumer key.</param>
- /// <returns>The newly instantiated <see cref="WebConsumer"/>.</returns>
- public static WebConsumer CreateWebConsumer(ITokenManager tokenManager, string consumerKey) {
- return new WebConsumer(GoogleDescription, tokenManager) {
- ConsumerKey = consumerKey,
- };
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="DesktopConsumer"/> class that is prepared to communicate with Google.
- /// </summary>
- /// <param name="tokenManager">The token manager.</param>
- /// <param name="consumerKey">The consumer key.</param>
- /// <returns>The newly instantiated <see cref="DesktopConsumer"/>.</returns>
- public static DesktopConsumer CreateDesktopConsumer(ITokenManager tokenManager, string consumerKey) {
- return new DesktopConsumer(GoogleDescription, tokenManager) {
- ConsumerKey = consumerKey,
- };
- }
-
- /// <summary>
/// Requests authorization from Google to access data from a set of Google applications.
/// </summary>
/// <param name="consumer">The Google consumer previously constructed using <see cref="CreateWebConsumer"/> or <see cref="CreateDesktopConsumer"/>.</param>
diff --git a/samples/DotNetOpenAuth.ApplicationBlock/TwitterConsumer.cs b/samples/DotNetOpenAuth.ApplicationBlock/TwitterConsumer.cs
index cd90365..2a98ffe 100644
--- a/samples/DotNetOpenAuth.ApplicationBlock/TwitterConsumer.cs
+++ b/samples/DotNetOpenAuth.ApplicationBlock/TwitterConsumer.cs
@@ -21,7 +21,7 @@ namespace DotNetOpenAuth.ApplicationBlock {
/// <summary>
/// The description of Twitter's OAuth protocol URIs.
/// </summary>
- private static readonly ServiceProviderDescription TwitterDescription = new ServiceProviderDescription {
+ public static readonly ServiceProviderDescription ServiceDescription = new ServiceProviderDescription {
RequestTokenEndpoint = new MessageReceivingEndpoint("http://twitter.com/oauth/request_token", HttpDeliveryMethods.GetRequest | HttpDeliveryMethods.AuthorizationHeaderRequest),
UserAuthorizationEndpoint = new MessageReceivingEndpoint("http://twitter.com/oauth/authorize", HttpDeliveryMethods.GetRequest | HttpDeliveryMethods.AuthorizationHeaderRequest),
AccessTokenEndpoint = new MessageReceivingEndpoint("http://twitter.com/oauth/access_token", HttpDeliveryMethods.GetRequest | HttpDeliveryMethods.AuthorizationHeaderRequest),
@@ -38,32 +38,6 @@ namespace DotNetOpenAuth.ApplicationBlock {
/// </summary>
private static readonly MessageReceivingEndpoint GetFriendTimelineStatusEndpoint = new MessageReceivingEndpoint("http://twitter.com/statuses/friends_timeline.xml", HttpDeliveryMethods.GetRequest);
- /// <summary>
- /// Initializes a new instance of the <see cref="WebConsumer"/> class that is
- /// prepared to communicate with Twitter.
- /// </summary>
- /// <param name="tokenManager">The token manager.</param>
- /// <param name="consumerKey">The consumer key.</param>
- /// <returns>The newly instantiated <see cref="WebConsumer"/>.</returns>
- public static WebConsumer CreateWebConsumer(ITokenManager tokenManager, string consumerKey) {
- return new WebConsumer(TwitterDescription, tokenManager) {
- ConsumerKey = consumerKey,
- };
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="DesktopConsumer"/> class that is
- /// prepared to communicate with Twitter.
- /// </summary>
- /// <param name="tokenManager">The token manager.</param>
- /// <param name="consumerKey">The consumer key.</param>
- /// <returns>The newly instantiated <see cref="DesktopConsumer"/>.</returns>
- public static DesktopConsumer CreateDesktopConsumer(ITokenManager tokenManager, string consumerKey) {
- return new DesktopConsumer(TwitterDescription, tokenManager) {
- ConsumerKey = consumerKey,
- };
- }
-
public static XDocument GetUpdates(ConsumerBase twitter, string accessToken) {
IncomingWebResponse response = twitter.PrepareAuthorizedRequestAndSend(GetFriendTimelineStatusEndpoint, accessToken);
return XDocument.Load(XmlReader.Create(response.GetResponseReader()));
diff --git a/samples/OAuthConsumer/App_Code/InMemoryTokenManager.cs b/samples/OAuthConsumer/App_Code/InMemoryTokenManager.cs
index f36a396..e2b2876 100644
--- a/samples/OAuthConsumer/App_Code/InMemoryTokenManager.cs
+++ b/samples/OAuthConsumer/App_Code/InMemoryTokenManager.cs
@@ -10,7 +10,7 @@ using System.Diagnostics;
using DotNetOpenAuth.OAuth.ChannelElements;
using DotNetOpenAuth.OAuth.Messages;
-public class InMemoryTokenManager : ITokenManager {
+public class InMemoryTokenManager : IConsumerTokenManager {
private Dictionary<string, string> tokensAndSecrets = new Dictionary<string, string>();
public InMemoryTokenManager(string consumerKey, string consumerSecret) {
diff --git a/samples/OAuthConsumer/GoogleAddressBook.aspx.cs b/samples/OAuthConsumer/GoogleAddressBook.aspx.cs
index 838b286..f4aa090 100644
--- a/samples/OAuthConsumer/GoogleAddressBook.aspx.cs
+++ b/samples/OAuthConsumer/GoogleAddressBook.aspx.cs
@@ -6,6 +6,7 @@ using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Linq;
using DotNetOpenAuth.ApplicationBlock;
+using DotNetOpenAuth.OAuth;
/// <summary>
/// A page to demonstrate downloading a Gmail address book using OAuth.
@@ -15,7 +16,7 @@ public partial class GoogleAddressBook : System.Web.UI.Page {
if (!IsPostBack) {
if (Session["TokenManager"] != null) {
InMemoryTokenManager tokenManager = (InMemoryTokenManager)Session["TokenManager"];
- var google = GoogleConsumer.CreateWebConsumer(tokenManager, tokenManager.ConsumerKey);
+ var google = new WebConsumer(GoogleConsumer.ServiceDescription, tokenManager);
var accessTokenResponse = google.ProcessUserAuthorization();
if (accessTokenResponse != null) {
@@ -51,7 +52,7 @@ public partial class GoogleAddressBook : System.Web.UI.Page {
InMemoryTokenManager tokenManager = new InMemoryTokenManager(consumerKeyBox.Text, consumerSecretBox.Text);
Session["TokenManager"] = tokenManager;
- var google = GoogleConsumer.CreateWebConsumer(tokenManager, consumerKeyBox.Text);
+ var google = new WebConsumer(GoogleConsumer.ServiceDescription, tokenManager);
GoogleConsumer.RequestAuthorization(google, GoogleConsumer.Applications.Contacts);
}
}
diff --git a/samples/OAuthConsumer/SampleWcf.aspx.cs b/samples/OAuthConsumer/SampleWcf.aspx.cs
index e733970..7572dd8 100644
--- a/samples/OAuthConsumer/SampleWcf.aspx.cs
+++ b/samples/OAuthConsumer/SampleWcf.aspx.cs
@@ -109,9 +109,7 @@ public partial class SampleWcf : System.Web.UI.Page {
new HmacSha1SigningBindingElement(),
},
},
- tokenManager) {
- ConsumerKey = consumerKey,
- };
+ tokenManager);
return consumer;
}
diff --git a/samples/OAuthConsumer/Twitter.aspx.cs b/samples/OAuthConsumer/Twitter.aspx.cs
index 354fe69..550ed4a 100644
--- a/samples/OAuthConsumer/Twitter.aspx.cs
+++ b/samples/OAuthConsumer/Twitter.aspx.cs
@@ -9,6 +9,7 @@ using System.Web.UI.WebControls;
using System.Xml.Linq;
using System.Xml.XPath;
using DotNetOpenAuth.ApplicationBlock;
+using DotNetOpenAuth.OAuth;
public partial class Twitter : System.Web.UI.Page {
private string AccessToken {
@@ -34,9 +35,9 @@ public partial class Twitter : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
if (!IsPostBack) {
- if (TokenManager != null) {
+ if (this.TokenManager != null) {
InMemoryTokenManager tokenManager = (InMemoryTokenManager)Session["TokenManager"];
- var twitter = TwitterConsumer.CreateWebConsumer(tokenManager, tokenManager.ConsumerKey);
+ var twitter = new WebConsumer(TwitterConsumer.ServiceDescription, tokenManager);
var accessTokenResponse = twitter.ProcessUserAuthorization();
if (accessTokenResponse != null) {
@@ -56,12 +57,12 @@ public partial class Twitter : System.Web.UI.Page {
return;
}
- var twitter = TwitterConsumer.CreateWebConsumer(this.TokenManager, this.TokenManager.ConsumerKey);
+ var twitter = new WebConsumer(TwitterConsumer.ServiceDescription, this.TokenManager);
twitter.Channel.Send(twitter.PrepareRequestUserAuthorization());
}
protected void downloadUpdates_Click(object sender, EventArgs e) {
- var twitter = TwitterConsumer.CreateWebConsumer(this.TokenManager, this.TokenManager.ConsumerKey);
+ var twitter = new WebConsumer(TwitterConsumer.ServiceDescription, this.TokenManager);
XPathDocument updates = new XPathDocument(TwitterConsumer.GetUpdates(twitter, AccessToken).CreateReader());
XPathNavigator nav = updates.CreateNavigator();
var parsedUpdates = from status in nav.Select("/statuses/status").OfType<XPathNavigator>()
diff --git a/samples/OAuthConsumerWpf/InMemoryTokenManager.cs b/samples/OAuthConsumerWpf/InMemoryTokenManager.cs
index b4692f1..faa485f 100644
--- a/samples/OAuthConsumerWpf/InMemoryTokenManager.cs
+++ b/samples/OAuthConsumerWpf/InMemoryTokenManager.cs
@@ -11,15 +11,15 @@ namespace DotNetOpenAuth.Samples.OAuthConsumerWpf {
using DotNetOpenAuth.OAuth.ChannelElements;
using DotNetOpenAuth.OAuth.Messages;
- internal class InMemoryTokenManager : ITokenManager {
+ internal class InMemoryTokenManager : IConsumerTokenManager {
private Dictionary<string, string> tokensAndSecrets = new Dictionary<string, string>();
internal InMemoryTokenManager() {
}
- internal string ConsumerKey { get; set; }
+ public string ConsumerKey { get; internal set; }
- internal string ConsumerSecret { get; set; }
+ public string ConsumerSecret { get; internal set; }
#region ITokenManager Members
diff --git a/samples/OAuthConsumerWpf/MainWindow.xaml.cs b/samples/OAuthConsumerWpf/MainWindow.xaml.cs
index b57589a..bf65431 100644
--- a/samples/OAuthConsumerWpf/MainWindow.xaml.cs
+++ b/samples/OAuthConsumerWpf/MainWindow.xaml.cs
@@ -34,13 +34,12 @@
public MainWindow() {
InitializeComponent();
- this.google = GoogleConsumer.CreateDesktopConsumer(this.tokenManager, string.Empty);
+ this.google = new DesktopConsumer(GoogleConsumer.ServiceDescription, this.tokenManager);
}
private void beginAuthorizationButton_Click(object sender, RoutedEventArgs e) {
this.tokenManager.ConsumerKey = consumerKeyBox.Text;
this.tokenManager.ConsumerSecret = consumerSecretBox.Text;
- this.google.ConsumerKey = consumerKeyBox.Text;
Cursor original = this.Cursor;
this.Cursor = Cursors.Wait;
diff --git a/samples/OAuthServiceProvider/App_Code/CustomOAuthTypeProvider.cs b/samples/OAuthServiceProvider/App_Code/CustomOAuthTypeProvider.cs
index a4397c1..9fdbf29 100644
--- a/samples/OAuthServiceProvider/App_Code/CustomOAuthTypeProvider.cs
+++ b/samples/OAuthServiceProvider/App_Code/CustomOAuthTypeProvider.cs
@@ -15,7 +15,7 @@ public class CustomOAuthMessageFactory : OAuthServiceProviderMessageFactory {
/// Initializes a new instance of the <see cref="CustomOAuthMessageFactory"/> class.
/// </summary>
/// <param name="tokenManager">The token manager instance to use.</param>
- public CustomOAuthMessageFactory(ITokenManager tokenManager) : base(tokenManager) {
+ public CustomOAuthMessageFactory(IServiceProviderTokenManager tokenManager) : base(tokenManager) {
}
public override IDirectedProtocolMessage GetNewRequestMessage(MessageReceivingEndpoint recipient, IDictionary<string, string> fields) {
diff --git a/samples/OAuthServiceProvider/App_Code/DatabaseTokenManager.cs b/samples/OAuthServiceProvider/App_Code/DatabaseTokenManager.cs
index b5d8fdd..d922901 100644
--- a/samples/OAuthServiceProvider/App_Code/DatabaseTokenManager.cs
+++ b/samples/OAuthServiceProvider/App_Code/DatabaseTokenManager.cs
@@ -11,8 +11,8 @@ using System.Linq;
using DotNetOpenAuth.OAuth.ChannelElements;
using DotNetOpenAuth.OAuth.Messages;
-public class DatabaseTokenManager : ITokenManager {
- #region ITokenManager Members
+public class DatabaseTokenManager : IServiceProviderTokenManager {
+ #region IServiceProviderTokenManager
public string GetConsumerSecret(string consumerKey) {
var consumerRow = Global.DataContext.OAuthConsumers.SingleOrDefault(
@@ -24,6 +24,10 @@ public class DatabaseTokenManager : ITokenManager {
return consumerRow.ConsumerSecret;
}
+ #endregion
+
+ #region ITokenManager Members
+
public string GetTokenSecret(string token) {
var tokenRow = Global.DataContext.OAuthTokens.SingleOrDefault(
tokenCandidate => tokenCandidate.Token == token);