diff options
Diffstat (limited to 'samples/Consumer/App_Code')
-rw-r--r-- | samples/Consumer/App_Code/Constants.cs | 40 | ||||
-rw-r--r-- | samples/Consumer/App_Code/InMemoryTokenManager.cs | 71 | ||||
-rw-r--r-- | samples/Consumer/App_Code/Logging.cs | 20 | ||||
-rw-r--r-- | samples/Consumer/App_Code/TracePageAppender.cs | 11 |
4 files changed, 142 insertions, 0 deletions
diff --git a/samples/Consumer/App_Code/Constants.cs b/samples/Consumer/App_Code/Constants.cs new file mode 100644 index 0000000..ecf76a8 --- /dev/null +++ b/samples/Consumer/App_Code/Constants.cs @@ -0,0 +1,40 @@ +using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Web;
+using DotNetOAuth;
+using DotNetOAuth.ChannelElements;
+using DotNetOAuth.Messaging;
+
+/// <summary>
+/// Service Provider definitions.
+/// </summary>
+public static class Constants {
+ /// <summary>
+ /// The Consumer to use for accessing Google data APIs.
+ /// </summary>
+ public static readonly ServiceProviderDescription GoogleDescription = new ServiceProviderDescription {
+ RequestTokenEndpoint = new MessageReceivingEndpoint("https://www.google.com/accounts/OAuthGetRequestToken", HttpDeliveryMethod.AuthorizationHeaderRequest),
+ UserAuthorizationEndpoint = new MessageReceivingEndpoint("https://www.google.com/accounts/OAuthAuthorizeToken", HttpDeliveryMethod.AuthorizationHeaderRequest),
+ AccessTokenEndpoint = new MessageReceivingEndpoint("https://www.google.com/accounts/OAuthGetAccessToken", HttpDeliveryMethod.AuthorizationHeaderRequest),
+ TamperProtectionElements = new ITamperProtectionChannelBindingElement[] {
+ new HmacSha1SigningBindingElement(),
+ },
+ };
+
+ /// <summary>
+ /// Values of the "scope" parameter that indicates what data streams the Consumer
+ /// wants access to.
+ /// </summary>
+ public static class GoogleScopes {
+ /// <summary>
+ /// Access to the Gmail address book.
+ /// </summary>
+ public const string Contacts = "http://www.google.com/m8/feeds/";
+
+ /// <summary>
+ /// The URI to get contacts once authorization is granted.
+ /// </summary>
+ public static readonly MessageReceivingEndpoint GetContacts = new MessageReceivingEndpoint("http://www.google.com/m8/feeds/contacts/default/full/", HttpDeliveryMethod.GetRequest);
+ }
+}
diff --git a/samples/Consumer/App_Code/InMemoryTokenManager.cs b/samples/Consumer/App_Code/InMemoryTokenManager.cs new file mode 100644 index 0000000..dc80da1 --- /dev/null +++ b/samples/Consumer/App_Code/InMemoryTokenManager.cs @@ -0,0 +1,71 @@ +//-----------------------------------------------------------------------
+// <copyright file="InMemoryTokenManager.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using DotNetOAuth.ChannelElements;
+
+public class InMemoryTokenManager : ITokenManager {
+ private Dictionary<string, string> tokensAndSecrets = new Dictionary<string, string>();
+
+ public InMemoryTokenManager(string consumerKey, string consumerSecret) {
+ this.ConsumerKey = consumerKey;
+ this.ConsumerSecret = consumerSecret;
+ }
+
+ public string ConsumerKey { get; private set; }
+
+ public string ConsumerSecret { get; private set; }
+
+ #region ITokenManager Members
+
+ public string GetConsumerSecret(string consumerKey) {
+ if (consumerKey == this.ConsumerKey) {
+ return this.ConsumerSecret;
+ } else {
+ throw new ArgumentException("Unrecognized consumer key.", "consumerKey");
+ }
+ }
+
+ public string GetTokenSecret(string token) {
+ return this.tokensAndSecrets[token];
+ }
+
+ public void StoreNewRequestToken(string consumerKey, string requestToken, string requestTokenSecret, IDictionary<string, string> parameters) {
+ this.tokensAndSecrets[requestToken] = requestTokenSecret;
+ }
+
+ /// <summary>
+ /// Checks whether a given request token has already been authorized
+ /// by some user for use by the Consumer that requested it.
+ /// </summary>
+ /// <param name="requestToken">The Consumer's request token.</param>
+ /// <returns>
+ /// True if the request token has already been fully authorized by the user
+ /// who owns the relevant protected resources. False if the token has not yet
+ /// been authorized, has expired or does not exist.
+ /// </returns>
+ public bool IsRequestTokenAuthorized(string requestToken) {
+ throw new NotImplementedException();
+ }
+
+ public void ExpireRequestTokenAndStoreNewAccessToken(string consumerKey, string requestToken, string accessToken, string accessTokenSecret) {
+ this.tokensAndSecrets.Remove(requestToken);
+ this.tokensAndSecrets[accessToken] = accessTokenSecret;
+ }
+
+ /// <summary>
+ /// Classifies a token as a request token or an access token.
+ /// </summary>
+ /// <param name="token">The token to classify.</param>
+ /// <returns>Request or Access token, or invalid if the token is not recognized.</returns>
+ public TokenType GetTokenType(string token) {
+ throw new NotImplementedException();
+ }
+
+ #endregion
+}
diff --git a/samples/Consumer/App_Code/Logging.cs b/samples/Consumer/App_Code/Logging.cs new file mode 100644 index 0000000..cba9b4e --- /dev/null +++ b/samples/Consumer/App_Code/Logging.cs @@ -0,0 +1,20 @@ +using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Web;
+
+/// <summary>
+/// Logging tools for this sample.
+/// </summary>
+public static class Logging {
+ /// <summary>
+ /// An application memory cache of recent log messages.
+ /// </summary>
+ public static StringBuilder LogMessages = new StringBuilder();
+
+ /// <summary>
+ /// The logger for this sample to use.
+ /// </summary>
+ public static log4net.ILog Logger = log4net.LogManager.GetLogger("DotNetOAuth.ConsumerSample");
+}
diff --git a/samples/Consumer/App_Code/TracePageAppender.cs b/samples/Consumer/App_Code/TracePageAppender.cs new file mode 100644 index 0000000..b3b539a --- /dev/null +++ b/samples/Consumer/App_Code/TracePageAppender.cs @@ -0,0 +1,11 @@ +using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Web;
+
+public class TracePageAppender : log4net.Appender.AppenderSkeleton {
+ protected override void Append(log4net.Core.LoggingEvent loggingEvent) {
+ StringWriter sw = new StringWriter(Logging.LogMessages);
+ Layout.Format(sw, loggingEvent);
+ }
+}
|