summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMicrosoft <aspnet@microsoft.com>2012-04-27 12:07:17 -0700
committerdotnetjunky <me@yahoo.com>2012-04-27 17:04:03 -0700
commite7eeb7b5790f04ed1bb8fc9ee137e58789af0a83 (patch)
tree67f42224344fcda0fd18de976e5c237b8b4de058
parenta6aea8aeeb82e3d35c132e6d09c9cb572efd823d (diff)
downloadDotNetOpenAuth-e7eeb7b5790f04ed1bb8fc9ee137e58789af0a83.zip
DotNetOpenAuth-e7eeb7b5790f04ed1bb8fc9ee137e58789af0a83.tar.gz
DotNetOpenAuth-e7eeb7b5790f04ed1bb8fc9ee137e58789af0a83.tar.bz2
Make changes to OAuth and OpenID to allow web-farm scenario.
-rw-r--r--src/DotNetOpenAuth.AspNet/Clients/OAuth/IOAuthTokenManager.cs38
-rw-r--r--src/DotNetOpenAuth.AspNet/Clients/OAuth/LinkedInClient.cs10
-rw-r--r--src/DotNetOpenAuth.AspNet/Clients/OAuth/OAuthClient.cs3
-rw-r--r--src/DotNetOpenAuth.AspNet/Clients/OAuth/SimpleConsumerTokenManager.cs103
-rw-r--r--src/DotNetOpenAuth.AspNet/Clients/OAuth/TwitterClient.cs16
-rw-r--r--src/DotNetOpenAuth.AspNet/Clients/OAuth2/OAuth2Client.cs19
-rw-r--r--src/DotNetOpenAuth.AspNet/DotNetOpenAuth.AspNet.csproj2
7 files changed, 184 insertions, 7 deletions
diff --git a/src/DotNetOpenAuth.AspNet/Clients/OAuth/IOAuthTokenManager.cs b/src/DotNetOpenAuth.AspNet/Clients/OAuth/IOAuthTokenManager.cs
new file mode 100644
index 0000000..92f1c22
--- /dev/null
+++ b/src/DotNetOpenAuth.AspNet/Clients/OAuth/IOAuthTokenManager.cs
@@ -0,0 +1,38 @@
+//-----------------------------------------------------------------------
+// <copyright file="IOAuthTokenManager.cs" company="Microsoft">
+// Copyright (c) Microsoft. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOpenAuth.AspNet.Clients {
+ /// <summary>
+ /// A token manager for use by a web site in its role as a consumer of
+ /// an individual ServiceProvider.
+ /// </summary>
+ /// <remarks>
+ /// This interface is used by clients of the DotNetOpenAuth.AspNet classes.
+ /// </remarks>
+ public interface IOAuthTokenManager {
+ /// <summary>
+ /// Gets the token secret from the specified token.
+ /// </summary>
+ /// <param name="token">The token.</param>
+ /// <returns>The token's secret</returns>
+ string GetTokenSecret(string token);
+
+ /// <summary>
+ /// Stores the request token together with its secret.
+ /// </summary>
+ /// <param name="requestToken">The request token.</param>
+ /// <param name="requestTokenSecret">The request token secret.</param>
+ void StoreRequestToken(string requestToken, string requestTokenSecret);
+
+ /// <summary>
+ /// Replaces the request token with access token.
+ /// </summary>
+ /// <param name="requestToken">The request token.</param>
+ /// <param name="accessToken">The access token.</param>
+ /// <param name="accessTokenSecret">The access token secret.</param>
+ void ReplaceRequestTokenWithAccessToken(string requestToken, string accessToken, string accessTokenSecret);
+ }
+} \ No newline at end of file
diff --git a/src/DotNetOpenAuth.AspNet/Clients/OAuth/LinkedInClient.cs b/src/DotNetOpenAuth.AspNet/Clients/OAuth/LinkedInClient.cs
index 631636b..d349576 100644
--- a/src/DotNetOpenAuth.AspNet/Clients/OAuth/LinkedInClient.cs
+++ b/src/DotNetOpenAuth.AspNet/Clients/OAuth/LinkedInClient.cs
@@ -59,6 +59,16 @@ namespace DotNetOpenAuth.AspNet.Clients {
public LinkedInClient(string consumerKey, string consumerSecret)
: base("linkedIn", LinkedInServiceDescription, consumerKey, consumerSecret) { }
+ /// <summary>
+ /// Initializes a new instance of the <see cref="LinkedInClient"/> class.
+ /// </summary>
+ /// <param name="consumerKey">The consumer key.</param>
+ /// <param name="consumerSecret">The consumer secret.</param>
+ /// <param name="tokenManager">The token manager.</param>
+ public LinkedInClient(string consumerKey, string consumerSecret, IOAuthTokenManager tokenManager)
+ : base("linkedIn", LinkedInServiceDescription, new SimpleConsumerTokenManager(consumerKey, consumerSecret, tokenManager)) {
+ }
+
#endregion
#region Methods
diff --git a/src/DotNetOpenAuth.AspNet/Clients/OAuth/OAuthClient.cs b/src/DotNetOpenAuth.AspNet/Clients/OAuth/OAuthClient.cs
index 89cefad..3f9e85a 100644
--- a/src/DotNetOpenAuth.AspNet/Clients/OAuth/OAuthClient.cs
+++ b/src/DotNetOpenAuth.AspNet/Clients/OAuth/OAuthClient.cs
@@ -54,7 +54,8 @@ namespace DotNetOpenAuth.AspNet.Clients {
[SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "I don't know how to ensure this rule is followed given this API")]
protected OAuthClient(
string providerName, ServiceProviderDescription serviceDescription, IConsumerTokenManager tokenManager)
- : this(providerName, new DotNetOpenAuthWebConsumer(serviceDescription, tokenManager)) { }
+ : this(providerName, new DotNetOpenAuthWebConsumer(serviceDescription, tokenManager)) {
+ }
/// <summary>
/// Initializes a new instance of the <see cref="OAuthClient"/> class.
diff --git a/src/DotNetOpenAuth.AspNet/Clients/OAuth/SimpleConsumerTokenManager.cs b/src/DotNetOpenAuth.AspNet/Clients/OAuth/SimpleConsumerTokenManager.cs
new file mode 100644
index 0000000..22156e9
--- /dev/null
+++ b/src/DotNetOpenAuth.AspNet/Clients/OAuth/SimpleConsumerTokenManager.cs
@@ -0,0 +1,103 @@
+//-----------------------------------------------------------------------
+// <copyright file="SimpleConsumerTokenManager.cs" company="Microsoft">
+// Copyright (c) Microsoft. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOpenAuth.AspNet.Clients {
+ using System;
+ using DotNetOpenAuth.OAuth.ChannelElements;
+
+ /// <summary>
+ /// Simple wrapper around IConsumerTokenManager
+ /// </summary>
+ public class SimpleConsumerTokenManager : IConsumerTokenManager {
+ /// <summary>
+ /// Store the token manager.
+ /// </summary>
+ private readonly IOAuthTokenManager tokenManager;
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="SimpleConsumerTokenManager"/> class.
+ /// </summary>
+ /// <param name="consumerKey">The consumer key.</param>
+ /// <param name="consumerSecret">The consumer secret.</param>
+ /// <param name="tokenManager">The OAuth token manager.</param>
+ public SimpleConsumerTokenManager(string consumerKey, string consumerSecret, IOAuthTokenManager tokenManager) {
+ Requires.NotNullOrEmpty(consumerKey, "consumerKey");
+ Requires.NotNullOrEmpty(consumerSecret, "consumerSecret");
+ Requires.NotNull(tokenManager, "oAuthTokenManager");
+
+ this.ConsumerKey = consumerKey;
+ this.ConsumerSecret = consumerSecret;
+ this.tokenManager = tokenManager;
+ }
+
+ /// <summary>
+ /// Gets the consumer key.
+ /// </summary>
+ /// <value>
+ /// The consumer key.
+ /// </value>
+ public string ConsumerKey {
+ get;
+ private set;
+ }
+
+ /// <summary>
+ /// Gets the consumer secret.
+ /// </summary>
+ /// <value>
+ /// The consumer secret.
+ /// </value>
+ public string ConsumerSecret {
+ get;
+ private set;
+ }
+
+ /// <summary>
+ /// Gets the Token Secret given a request or access token.
+ /// </summary>
+ /// <param name="token">The request or access token.</param>
+ /// <returns>
+ /// The secret associated with the given token.
+ /// </returns>
+ /// <exception cref="ArgumentException">Thrown if the secret cannot be found for the given token.</exception>
+ public string GetTokenSecret(string token) {
+ return this.tokenManager.GetTokenSecret(token);
+ }
+
+ /// <summary>
+ /// Stores a newly generated unauthorized request token, secret, and optional
+ /// application-specific parameters for later recall.
+ /// </summary>
+ /// <param name="request">The request message that resulted in the generation of a new unauthorized request token.</param>
+ /// <param name="response">The response message that includes the unauthorized request token.</param>
+ /// <exception cref="ArgumentException">Thrown if the consumer key is not registered, or a required parameter was not found in the parameters collection.</exception>
+ public void StoreNewRequestToken(DotNetOpenAuth.OAuth.Messages.UnauthorizedTokenRequest request, DotNetOpenAuth.OAuth.Messages.ITokenSecretContainingMessage response) {
+ this.tokenManager.StoreRequestToken(response.Token, response.TokenSecret);
+ }
+
+ /// <summary>
+ /// Deletes a request token and its associated secret and stores a new access token and secret.
+ /// </summary>
+ /// <param name="consumerKey">The Consumer that is exchanging its request token for an access token.</param>
+ /// <param name="requestToken">The Consumer's request token that should be deleted/expired.</param>
+ /// <param name="accessToken">The new access token that is being issued to the Consumer.</param>
+ /// <param name="accessTokenSecret">The secret associated with the newly issued access token.</param>
+ public void ExpireRequestTokenAndStoreNewAccessToken(string consumerKey, string requestToken, string accessToken, string accessTokenSecret) {
+ this.tokenManager.ReplaceRequestTokenWithAccessToken(requestToken, 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 NotSupportedException();
+ }
+ }
+} \ No newline at end of file
diff --git a/src/DotNetOpenAuth.AspNet/Clients/OAuth/TwitterClient.cs b/src/DotNetOpenAuth.AspNet/Clients/OAuth/TwitterClient.cs
index ceaffd4..0ec0780 100644
--- a/src/DotNetOpenAuth.AspNet/Clients/OAuth/TwitterClient.cs
+++ b/src/DotNetOpenAuth.AspNet/Clients/OAuth/TwitterClient.cs
@@ -28,15 +28,15 @@ namespace DotNetOpenAuth.AspNet.Clients {
public static readonly ServiceProviderDescription TwitterServiceDescription = new ServiceProviderDescription {
RequestTokenEndpoint =
new MessageReceivingEndpoint(
- "http://twitter.com/oauth/request_token",
+ "https://twitter.com/oauth/request_token",
HttpDeliveryMethods.GetRequest | HttpDeliveryMethods.AuthorizationHeaderRequest),
UserAuthorizationEndpoint =
new MessageReceivingEndpoint(
- "http://twitter.com/oauth/authenticate",
+ "https://twitter.com/oauth/authenticate",
HttpDeliveryMethods.GetRequest | HttpDeliveryMethods.AuthorizationHeaderRequest),
AccessTokenEndpoint =
new MessageReceivingEndpoint(
- "http://twitter.com/oauth/access_token",
+ "https://twitter.com/oauth/access_token",
HttpDeliveryMethods.GetRequest | HttpDeliveryMethods.AuthorizationHeaderRequest),
TamperProtectionElements = new ITamperProtectionChannelBindingElement[] { new HmacSha1SigningBindingElement() },
};
@@ -59,6 +59,16 @@ namespace DotNetOpenAuth.AspNet.Clients {
public TwitterClient(string consumerKey, string consumerSecret)
: base("twitter", TwitterServiceDescription, consumerKey, consumerSecret) { }
+ /// <summary>
+ /// Initializes a new instance of the <see cref="TwitterClient"/> class.
+ /// </summary>
+ /// <param name="consumerKey">The consumer key.</param>
+ /// <param name="consumerSecret">The consumer secret.</param>
+ /// <param name="tokenManager">The token manager.</param>
+ public TwitterClient(string consumerKey, string consumerSecret, IOAuthTokenManager tokenManager)
+ : base("twitter", TwitterServiceDescription, new SimpleConsumerTokenManager(consumerKey, consumerSecret, tokenManager)) {
+ }
+
#endregion
#region Methods
diff --git a/src/DotNetOpenAuth.AspNet/Clients/OAuth2/OAuth2Client.cs b/src/DotNetOpenAuth.AspNet/Clients/OAuth2/OAuth2Client.cs
index 016d92e..cac4261 100644
--- a/src/DotNetOpenAuth.AspNet/Clients/OAuth2/OAuth2Client.cs
+++ b/src/DotNetOpenAuth.AspNet/Clients/OAuth2/OAuth2Client.cs
@@ -86,7 +86,20 @@ namespace DotNetOpenAuth.AspNet.Clients {
/// <returns>
/// An instance of <see cref="AuthenticationResult"/> containing authentication result.
/// </returns>
- public virtual AuthenticationResult VerifyAuthentication(HttpContextBase context) {
+ public AuthenticationResult VerifyAuthentication(HttpContextBase context) {
+ Requires.NotNull(this.returnUrl, "this.returnUrl");
+ return VerifyAuthentication(context, this.returnUrl);
+ }
+
+ /// <summary>
+ /// Check if authentication succeeded after user is redirected back from the service provider.
+ /// </summary>
+ /// <param name="context">The context.</param>
+ /// <param name="returnPageUrl">The return URL which should match the value passed to RequestAuthentication() method.</param>
+ /// <returns>
+ /// An instance of <see cref="AuthenticationResult"/> containing authentication result.
+ /// </returns>
+ public virtual AuthenticationResult VerifyAuthentication(HttpContextBase context, Uri returnPageUrl) {
Requires.NotNull(context, "context");
string code = context.Request.QueryString["code"];
@@ -94,7 +107,7 @@ namespace DotNetOpenAuth.AspNet.Clients {
return AuthenticationResult.Failed;
}
- string accessToken = this.QueryAccessToken(this.returnUrl, code);
+ string accessToken = this.QueryAccessToken(returnPageUrl, code);
if (accessToken == null) {
return AuthenticationResult.Failed;
}
@@ -133,7 +146,7 @@ namespace DotNetOpenAuth.AspNet.Clients {
/// <returns>
/// An absolute URL.
/// </returns>
- [SuppressMessage("Microsoft.Naming", "CA1726:UsePreferredTerms", MessageId = "Login",
+ [SuppressMessage("Microsoft.Naming", "CA1726:UsePreferredTerms", MessageId = "Login",
Justification = "Login is used more consistently in ASP.Net")]
protected abstract Uri GetServiceLoginUrl(Uri returnUrl);
diff --git a/src/DotNetOpenAuth.AspNet/DotNetOpenAuth.AspNet.csproj b/src/DotNetOpenAuth.AspNet/DotNetOpenAuth.AspNet.csproj
index f28f96f..f1fbacd 100644
--- a/src/DotNetOpenAuth.AspNet/DotNetOpenAuth.AspNet.csproj
+++ b/src/DotNetOpenAuth.AspNet/DotNetOpenAuth.AspNet.csproj
@@ -42,6 +42,8 @@
<ItemGroup>
<Compile Include="AuthenticationResult.cs" />
<Compile Include="Clients\DictionaryExtensions.cs" />
+ <Compile Include="Clients\OAuth\IOAuthTokenManager.cs" />
+ <Compile Include="Clients\OAuth\SimpleConsumerTokenManager.cs" />
<Compile Include="IAuthenticationClient.cs" />
<Compile Include="Clients\OAuth2\FacebookClient.cs" />
<Compile Include="Clients\OAuth2\FacebookGraphData.cs" />