This repository has been archived by the owner on Mar 20, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 732
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #235 from dotnetjunky/v4.1
Fix bug in the LinkedInClient not working Fixes #232
- Loading branch information
Showing
4 changed files
with
112 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
src/DotNetOpenAuth.AspNet/Clients/OAuth/CookieOAuthTokenManager.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
using System.Web; | ||
using System.Web.Security; | ||
|
||
namespace DotNetOpenAuth.AspNet.Clients { | ||
|
||
/// <summary> | ||
/// Stores OAuth tokens in the current request's cookie. | ||
/// </summary> | ||
/// <remarks> | ||
/// This class is different from the <see cref="AuthenticationOnlyCookieOAuthTokenManager"/> in that | ||
/// it also stores the access token after the authentication has succeeded. | ||
/// </remarks> | ||
public class CookieOAuthTokenManager : AuthenticationOnlyCookieOAuthTokenManager { | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="CookieOAuthTokenManager"/> class. | ||
/// </summary> | ||
public CookieOAuthTokenManager() { | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="CookieOAuthTokenManager"/> class. | ||
/// </summary> | ||
/// <param name="context">The current request context.</param> | ||
public CookieOAuthTokenManager(HttpContextBase context) | ||
: base(context) { | ||
} | ||
|
||
/// <summary> | ||
/// Gets the token secret from the specified token. | ||
/// </summary> | ||
/// <param name="token">The token.</param> | ||
/// <returns> | ||
/// The token's secret | ||
/// </returns> | ||
public override string GetTokenSecret(string token) { | ||
string secret = base.GetTokenSecret(token); | ||
if (secret != null) { | ||
return secret; | ||
} | ||
|
||
// The base class checks for cookies in the Request object. | ||
// Here we check in the Response object as well because we | ||
// may have set it earlier in the request life cycle. | ||
HttpCookie cookie = this.Context.Response.Cookies[TokenCookieKey]; | ||
if (cookie == null || string.IsNullOrEmpty(cookie.Values[token])) { | ||
return null; | ||
} | ||
|
||
secret = DecodeAndUnprotectToken(token, cookie.Values[token]); | ||
return secret; | ||
} | ||
|
||
/// <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> | ||
public override void ReplaceRequestTokenWithAccessToken(string requestToken, string accessToken, string accessTokenSecret) { | ||
var cookie = new HttpCookie(TokenCookieKey) { | ||
HttpOnly = true | ||
}; | ||
|
||
if (FormsAuthentication.RequireSSL) { | ||
cookie.Secure = true; | ||
} | ||
|
||
var encryptedToken = ProtectAndEncodeToken(accessToken, accessTokenSecret); | ||
cookie.Values[accessToken] = encryptedToken; | ||
|
||
this.Context.Response.Cookies.Set(cookie); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters