diff options
Diffstat (limited to 'src/DotNetOpenAuth.AspNet/Clients')
-rw-r--r-- | src/DotNetOpenAuth.AspNet/Clients/OAuth/AuthenticationOnlyCookieOAuthTokenManager.cs | 96 | ||||
-rw-r--r-- | src/DotNetOpenAuth.AspNet/Clients/OAuth/LinkedInClient.cs | 5 | ||||
-rw-r--r-- | src/DotNetOpenAuth.AspNet/Clients/OAuth/TwitterClient.cs | 11 | ||||
-rw-r--r-- | src/DotNetOpenAuth.AspNet/Clients/OAuth2/FacebookClient.cs | 31 | ||||
-rw-r--r-- | src/DotNetOpenAuth.AspNet/Clients/OAuth2/MicrosoftClient.cs | 176 | ||||
-rw-r--r-- | src/DotNetOpenAuth.AspNet/Clients/OAuth2/MicrosoftClientUserData.cs (renamed from src/DotNetOpenAuth.AspNet/Clients/OAuth2/WindowsLiveUserData.cs) | 4 | ||||
-rw-r--r-- | src/DotNetOpenAuth.AspNet/Clients/OAuth2/OAuth2Client.cs | 10 | ||||
-rw-r--r-- | src/DotNetOpenAuth.AspNet/Clients/OAuth2/WindowsLiveClient.cs | 162 | ||||
-rw-r--r-- | src/DotNetOpenAuth.AspNet/Clients/OpenID/GoogleOpenIdClient.cs | 5 |
9 files changed, 328 insertions, 172 deletions
diff --git a/src/DotNetOpenAuth.AspNet/Clients/OAuth/AuthenticationOnlyCookieOAuthTokenManager.cs b/src/DotNetOpenAuth.AspNet/Clients/OAuth/AuthenticationOnlyCookieOAuthTokenManager.cs new file mode 100644 index 0000000..10cf39d --- /dev/null +++ b/src/DotNetOpenAuth.AspNet/Clients/OAuth/AuthenticationOnlyCookieOAuthTokenManager.cs @@ -0,0 +1,96 @@ +//----------------------------------------------------------------------- +// <copyright file="AuthenticationOnlyCookieOAuthTokenManager.cs" company="Microsoft"> +// Copyright (c) Microsoft. All rights reserved. +// </copyright> +//----------------------------------------------------------------------- + +namespace DotNetOpenAuth.AspNet.Clients { + using System; + using System.Text; + using System.Web; + using System.Web.Security; + + /// <summary> + /// Stores OAuth tokens in the current request's cookie + /// </summary> + public class AuthenticationOnlyCookieOAuthTokenManager : IOAuthTokenManager { + /// <summary> + /// Key used for token cookie + /// </summary> + private const string TokenCookieKey = "OAuthTokenSecret"; + + /// <summary> + /// Primary request context. + /// </summary> + private readonly HttpContextBase primaryContext; + + /// <summary> + /// Initializes a new instance of the <see cref="AuthenticationOnlyCookieOAuthTokenManager"/> class. + /// </summary> + public AuthenticationOnlyCookieOAuthTokenManager() { + } + + /// <summary> + /// Initializes a new instance of the <see cref="AuthenticationOnlyCookieOAuthTokenManager"/> class. + /// </summary> + /// <param name="context">The current request context.</param> + public AuthenticationOnlyCookieOAuthTokenManager(HttpContextBase context) { + this.primaryContext = context; + } + + /// <summary> + /// Gets the effective HttpContext object to use. + /// </summary> + private HttpContextBase Context { + get { + return this.primaryContext ?? new HttpContextWrapper(HttpContext.Current); + } + } + + /// <summary> + /// Gets the token secret from the specified token. + /// </summary> + /// <param name="token">The token.</param> + /// <returns> + /// The token's secret + /// </returns> + public string GetTokenSecret(string token) { + HttpCookie cookie = this.Context.Request.Cookies[TokenCookieKey]; + if (cookie == null || string.IsNullOrEmpty(cookie.Values[token])) { + return null; + } + byte[] cookieBytes = HttpServerUtility.UrlTokenDecode(cookie.Values[token]); + byte[] clearBytes = MachineKeyUtil.Unprotect(cookieBytes, TokenCookieKey, "Token:" + token); + + string secret = Encoding.UTF8.GetString(clearBytes); + 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 void ReplaceRequestTokenWithAccessToken(string requestToken, string accessToken, string accessTokenSecret) { + var cookie = new HttpCookie(TokenCookieKey) { + Value = string.Empty, + Expires = DateTime.UtcNow.AddDays(-5) + }; + this.Context.Response.Cookies.Set(cookie); + } + + /// <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> + public void StoreRequestToken(string requestToken, string requestTokenSecret) { + var cookie = new HttpCookie(TokenCookieKey); + byte[] cookieBytes = Encoding.UTF8.GetBytes(requestTokenSecret); + var secretBytes = MachineKeyUtil.Protect(cookieBytes, TokenCookieKey, "Token:" + requestToken); + cookie.Values[requestToken] = HttpServerUtility.UrlTokenEncode(secretBytes); + this.Context.Response.Cookies.Set(cookie); + } + } +}
\ 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 d349576..ac8186d 100644 --- a/src/DotNetOpenAuth.AspNet/Clients/OAuth/LinkedInClient.cs +++ b/src/DotNetOpenAuth.AspNet/Clients/OAuth/LinkedInClient.cs @@ -48,6 +48,9 @@ namespace DotNetOpenAuth.AspNet.Clients { /// <summary> /// Initializes a new instance of the <see cref="LinkedInClient"/> class. /// </summary> + /// <remarks> + /// Tokens exchanged during the OAuth handshake are stored in cookies. + /// </remarks> /// <param name="consumerKey"> /// The LinkedIn app's consumer key. /// </param> @@ -57,7 +60,7 @@ namespace DotNetOpenAuth.AspNet.Clients { [SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "We can't dispose the object because we still need it through the app lifetime.")] public LinkedInClient(string consumerKey, string consumerSecret) - : base("linkedIn", LinkedInServiceDescription, consumerKey, consumerSecret) { } + : this(consumerKey, consumerSecret, new AuthenticationOnlyCookieOAuthTokenManager()) { } /// <summary> /// Initializes a new instance of the <see cref="LinkedInClient"/> class. diff --git a/src/DotNetOpenAuth.AspNet/Clients/OAuth/TwitterClient.cs b/src/DotNetOpenAuth.AspNet/Clients/OAuth/TwitterClient.cs index 0ec0780..96c1701 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( - "https://twitter.com/oauth/request_token", + "https://api.twitter.com/oauth/request_token", HttpDeliveryMethods.GetRequest | HttpDeliveryMethods.AuthorizationHeaderRequest), UserAuthorizationEndpoint = new MessageReceivingEndpoint( - "https://twitter.com/oauth/authenticate", + "https://api.twitter.com/oauth/authenticate", HttpDeliveryMethods.GetRequest | HttpDeliveryMethods.AuthorizationHeaderRequest), AccessTokenEndpoint = new MessageReceivingEndpoint( - "https://twitter.com/oauth/access_token", + "https://api.twitter.com/oauth/access_token", HttpDeliveryMethods.GetRequest | HttpDeliveryMethods.AuthorizationHeaderRequest), TamperProtectionElements = new ITamperProtectionChannelBindingElement[] { new HmacSha1SigningBindingElement() }, }; @@ -48,6 +48,9 @@ namespace DotNetOpenAuth.AspNet.Clients { /// <summary> /// Initializes a new instance of the <see cref="TwitterClient"/> class with the specified consumer key and consumer secret. /// </summary> + /// <remarks> + /// Tokens exchanged during the OAuth handshake are stored in cookies. + /// </remarks> /// <param name="consumerKey"> /// The consumer key. /// </param> @@ -57,7 +60,7 @@ namespace DotNetOpenAuth.AspNet.Clients { [SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "We can't dispose the object because we still need it through the app lifetime.")] public TwitterClient(string consumerKey, string consumerSecret) - : base("twitter", TwitterServiceDescription, consumerKey, consumerSecret) { } + : this(consumerKey, consumerSecret, new AuthenticationOnlyCookieOAuthTokenManager()) { } /// <summary> /// Initializes a new instance of the <see cref="TwitterClient"/> class. diff --git a/src/DotNetOpenAuth.AspNet/Clients/OAuth2/FacebookClient.cs b/src/DotNetOpenAuth.AspNet/Clients/OAuth2/FacebookClient.cs index f4ad20b..8cb5cc5 100644 --- a/src/DotNetOpenAuth.AspNet/Clients/OAuth2/FacebookClient.cs +++ b/src/DotNetOpenAuth.AspNet/Clients/OAuth2/FacebookClient.cs @@ -76,7 +76,10 @@ namespace DotNetOpenAuth.AspNet.Clients { // Note: Facebook doesn't like us to url-encode the redirect_uri value var builder = new UriBuilder(AuthorizationEndpoint); builder.AppendQueryArgs( - new Dictionary<string, string> { { "client_id", this.appId }, { "redirect_uri", returnUrl.AbsoluteUri }, }); + new Dictionary<string, string> { + { "client_id", this.appId }, + { "redirect_uri", returnUrl.AbsoluteUri } + }); return builder.Uri; } @@ -127,7 +130,7 @@ namespace DotNetOpenAuth.AspNet.Clients { builder.AppendQueryArgs( new Dictionary<string, string> { { "client_id", this.appId }, - { "redirect_uri", returnUrl.AbsoluteUri }, + { "redirect_uri", NormalizeHexEncoding(returnUrl.AbsoluteUri) }, { "client_secret", this.appSecret }, { "code", authorizationCode }, }); @@ -143,6 +146,28 @@ namespace DotNetOpenAuth.AspNet.Clients { } } + /// <summary> + /// Converts any % encoded values in the URL to uppercase. + /// </summary> + /// <param name="url">The URL string to normalize</param> + /// <returns>The normalized url</returns> + /// <example>NormalizeHexEncoding("Login.aspx?ReturnUrl=%2fAccount%2fManage.aspx") returns "Login.aspx?ReturnUrl=%2FAccount%2FManage.aspx"</example> + /// <remarks> + /// There is an issue in Facebook whereby it will rejects the redirect_uri value if + /// the url contains lowercase % encoded values. + /// </remarks> + private static string NormalizeHexEncoding(string url) { + var chars = url.ToCharArray(); + for (int i = 0; i < chars.Length - 2; i++) { + if (chars[i] == '%') { + chars[i + 1] = char.ToUpperInvariant(chars[i + 1]); + chars[i + 2] = char.ToUpperInvariant(chars[i + 2]); + i += 2; + } + } + return new string(chars); + } + #endregion } -} +}
\ No newline at end of file diff --git a/src/DotNetOpenAuth.AspNet/Clients/OAuth2/MicrosoftClient.cs b/src/DotNetOpenAuth.AspNet/Clients/OAuth2/MicrosoftClient.cs new file mode 100644 index 0000000..5ac5591 --- /dev/null +++ b/src/DotNetOpenAuth.AspNet/Clients/OAuth2/MicrosoftClient.cs @@ -0,0 +1,176 @@ +//----------------------------------------------------------------------- +// <copyright file="MicrosoftClient.cs" company="Microsoft"> +// Copyright (c) Microsoft. All rights reserved. +// </copyright> +//----------------------------------------------------------------------- + +namespace DotNetOpenAuth.AspNet.Clients { + using System; + using System.Collections.Generic; + using System.IO; + using System.Net; + using DotNetOpenAuth.Messaging; + + /// <summary> + /// The Microsoft account client. + /// </summary> + public class MicrosoftClient : OAuth2Client { + #region Constants and Fields + + /// <summary> + /// The authorization endpoint. + /// </summary> + private const string AuthorizationEndpoint = "https://oauth.live.com/authorize"; + + /// <summary> + /// The token endpoint. + /// </summary> + private const string TokenEndpoint = "https://oauth.live.com/token"; + + /// <summary> + /// The _app id. + /// </summary> + private readonly string appId; + + /// <summary> + /// The _app secret. + /// </summary> + private readonly string appSecret; + + #endregion + + #region Constructors and Destructors + + /// <summary> + /// Initializes a new instance of the <see cref="MicrosoftClient"/> class. + /// </summary> + /// <param name="appId"> + /// The app id. + /// </param> + /// <param name="appSecret"> + /// The app secret. + /// </param> + public MicrosoftClient(string appId, string appSecret) + : this("microsoft", appId, appSecret) { + } + + /// <summary> + /// Initializes a new instance of the <see cref="MicrosoftClient"/> class. + /// </summary> + /// <param name="providerName">The provider name.</param> + /// <param name="appId">The app id.</param> + /// <param name="appSecret">The app secret.</param> + protected MicrosoftClient(string providerName, string appId, string appSecret) + : base(providerName) { + Requires.NotNullOrEmpty(appId, "appId"); + Requires.NotNullOrEmpty(appSecret, "appSecret"); + + this.appId = appId; + this.appSecret = appSecret; + } + + #endregion + + #region Methods + + /// <summary> + /// Gets the full url pointing to the login page for this client. The url should include the specified return url so that when the login completes, user is redirected back to that url. + /// </summary> + /// <param name="returnUrl">The return URL.</param> + /// <returns> + /// An absolute URL. + /// </returns> + protected override Uri GetServiceLoginUrl(Uri returnUrl) { + var builder = new UriBuilder(AuthorizationEndpoint); + builder.AppendQueryArgs( + new Dictionary<string, string> { + { "client_id", this.appId }, + { "scope", "wl.basic" }, + { "response_type", "code" }, + { "redirect_uri", returnUrl.AbsoluteUri }, + }); + + return builder.Uri; + } + + /// <summary> + /// Given the access token, gets the logged-in user's data. The returned dictionary must include two keys 'id', and 'username'. + /// </summary> + /// <param name="accessToken"> + /// The access token of the current user. + /// </param> + /// <returns> + /// A dictionary contains key-value pairs of user data + /// </returns> + protected override IDictionary<string, string> GetUserData(string accessToken) { + MicrosoftClientUserData graph; + var request = + WebRequest.Create( + "https://apis.live.net/v5.0/me?access_token=" + MessagingUtilities.EscapeUriDataStringRfc3986(accessToken)); + using (var response = request.GetResponse()) { + using (var responseStream = response.GetResponseStream()) { + graph = JsonHelper.Deserialize<MicrosoftClientUserData>(responseStream); + } + } + + var userData = new Dictionary<string, string>(); + userData.AddItemIfNotEmpty("id", graph.Id); + userData.AddItemIfNotEmpty("username", graph.Name); + userData.AddItemIfNotEmpty("name", graph.Name); + userData.AddItemIfNotEmpty("link", graph.Link == null ? null : graph.Link.AbsoluteUri); + userData.AddItemIfNotEmpty("gender", graph.Gender); + userData.AddItemIfNotEmpty("firstname", graph.FirstName); + userData.AddItemIfNotEmpty("lastname", graph.LastName); + return userData; + } + + /// <summary> + /// Queries the access token from the specified authorization code. + /// </summary> + /// <param name="returnUrl"> + /// The return URL. + /// </param> + /// <param name="authorizationCode"> + /// The authorization code. + /// </param> + /// <returns> + /// The query access token. + /// </returns> + protected override string QueryAccessToken(Uri returnUrl, string authorizationCode) { + var entity = + MessagingUtilities.CreateQueryString( + new Dictionary<string, string> { + { "client_id", this.appId }, + { "redirect_uri", returnUrl.AbsoluteUri }, + { "client_secret", this.appSecret }, + { "code", authorizationCode }, + { "grant_type", "authorization_code" }, + }); + + WebRequest tokenRequest = WebRequest.Create(TokenEndpoint); + tokenRequest.ContentType = "application/x-www-form-urlencoded"; + tokenRequest.ContentLength = entity.Length; + tokenRequest.Method = "POST"; + + using (Stream requestStream = tokenRequest.GetRequestStream()) { + var writer = new StreamWriter(requestStream); + writer.Write(entity); + writer.Flush(); + } + + HttpWebResponse tokenResponse = (HttpWebResponse)tokenRequest.GetResponse(); + if (tokenResponse.StatusCode == HttpStatusCode.OK) { + using (Stream responseStream = tokenResponse.GetResponseStream()) { + var tokenData = JsonHelper.Deserialize<OAuth2AccessTokenData>(responseStream); + if (tokenData != null) { + return tokenData.AccessToken; + } + } + } + + return null; + } + + #endregion + } +}
\ No newline at end of file diff --git a/src/DotNetOpenAuth.AspNet/Clients/OAuth2/WindowsLiveUserData.cs b/src/DotNetOpenAuth.AspNet/Clients/OAuth2/MicrosoftClientUserData.cs index 52192c3..3b55f7a 100644 --- a/src/DotNetOpenAuth.AspNet/Clients/OAuth2/WindowsLiveUserData.cs +++ b/src/DotNetOpenAuth.AspNet/Clients/OAuth2/MicrosoftClientUserData.cs @@ -1,5 +1,5 @@ //----------------------------------------------------------------------- -// <copyright file="WindowsLiveUserData.cs" company="Microsoft"> +// <copyright file="MicrosoftClientUserData.cs" company="Microsoft"> // Copyright (c) Microsoft. All rights reserved. // </copyright> //----------------------------------------------------------------------- @@ -17,7 +17,7 @@ namespace DotNetOpenAuth.AspNet.Clients { /// </remarks> [DataContract] [EditorBrowsable(EditorBrowsableState.Never)] - public class WindowsLiveUserData { + public class MicrosoftClientUserData { #region Public Properties /// <summary> diff --git a/src/DotNetOpenAuth.AspNet/Clients/OAuth2/OAuth2Client.cs b/src/DotNetOpenAuth.AspNet/Clients/OAuth2/OAuth2Client.cs index cac4261..138fac2 100644 --- a/src/DotNetOpenAuth.AspNet/Clients/OAuth2/OAuth2Client.cs +++ b/src/DotNetOpenAuth.AspNet/Clients/OAuth2/OAuth2Client.cs @@ -21,11 +21,6 @@ namespace DotNetOpenAuth.AspNet.Clients { /// </summary> private readonly string providerName; - /// <summary> - /// The return url. - /// </summary> - private Uri returnUrl; - #endregion #region Constructors and Destructors @@ -71,8 +66,6 @@ namespace DotNetOpenAuth.AspNet.Clients { Requires.NotNull(context, "context"); Requires.NotNull(returnUrl, "returnUrl"); - this.returnUrl = returnUrl; - string redirectUrl = this.GetServiceLoginUrl(returnUrl).AbsoluteUri; context.Response.Redirect(redirectUrl, endResponse: true); } @@ -87,8 +80,7 @@ namespace DotNetOpenAuth.AspNet.Clients { /// An instance of <see cref="AuthenticationResult"/> containing authentication result. /// </returns> public AuthenticationResult VerifyAuthentication(HttpContextBase context) { - Requires.NotNull(this.returnUrl, "this.returnUrl"); - return VerifyAuthentication(context, this.returnUrl); + throw new InvalidOperationException(WebResources.OAuthRequireReturnUrl); } /// <summary> diff --git a/src/DotNetOpenAuth.AspNet/Clients/OAuth2/WindowsLiveClient.cs b/src/DotNetOpenAuth.AspNet/Clients/OAuth2/WindowsLiveClient.cs index 5e396a1..5441ce5 100644 --- a/src/DotNetOpenAuth.AspNet/Clients/OAuth2/WindowsLiveClient.cs +++ b/src/DotNetOpenAuth.AspNet/Clients/OAuth2/WindowsLiveClient.cs @@ -6,161 +6,23 @@ namespace DotNetOpenAuth.AspNet.Clients { using System; - using System.Collections.Generic; - using System.IO; - using System.Net; - using DotNetOpenAuth.Messaging; /// <summary> - /// The windows live client. + /// The WindowsLive client. /// </summary> - public sealed class WindowsLiveClient : OAuth2Client { - #region Constants and Fields - - /// <summary> - /// The authorization endpoint. - /// </summary> - private const string AuthorizationEndpoint = "https://oauth.live.com/authorize"; - - /// <summary> - /// The token endpoint. - /// </summary> - private const string TokenEndpoint = "https://oauth.live.com/token"; - - /// <summary> - /// The _app id. - /// </summary> - private readonly string appId; - - /// <summary> - /// The _app secret. - /// </summary> - private readonly string appSecret; - - #endregion - - #region Constructors and Destructors - + /// <remarks> + /// The WindowsLive brand is being replaced by Microsoft account brand. + /// We keep this class for backward compatibility only. + /// </remarks> + [Obsolete("Use the MicrosoftClient class.")] + public sealed class WindowsLiveClient : MicrosoftClient { /// <summary> /// Initializes a new instance of the <see cref="WindowsLiveClient"/> class. /// </summary> - /// <param name="appId"> - /// The app id. - /// </param> - /// <param name="appSecret"> - /// The app secret. - /// </param> - public WindowsLiveClient(string appId, string appSecret) - : base("windowslive") { - Requires.NotNullOrEmpty(appId, "appId"); - Requires.NotNullOrEmpty(appSecret, "appSecret"); - - this.appId = appId; - this.appSecret = appSecret; + /// <param name="appId">The app id.</param> + /// <param name="appSecret">The app secret.</param> + public WindowsLiveClient(string appId, string appSecret) : + base("windowslive", appId, appSecret) { } - - #endregion - - #region Methods - - /// <summary> - /// Gets the full url pointing to the login page for this client. The url should include the specified return url so that when the login completes, user is redirected back to that url. - /// </summary> - /// <param name="returnUrl">The return URL.</param> - /// <returns> - /// An absolute URL. - /// </returns> - protected override Uri GetServiceLoginUrl(Uri returnUrl) { - var builder = new UriBuilder(AuthorizationEndpoint); - builder.AppendQueryArgs( - new Dictionary<string, string> { - { "client_id", this.appId }, - { "scope", "wl.basic" }, - { "response_type", "code" }, - { "redirect_uri", returnUrl.AbsoluteUri }, - }); - - return builder.Uri; - } - - /// <summary> - /// Given the access token, gets the logged-in user's data. The returned dictionary must include two keys 'id', and 'username'. - /// </summary> - /// <param name="accessToken"> - /// The access token of the current user. - /// </param> - /// <returns> - /// A dictionary contains key-value pairs of user data - /// </returns> - protected override IDictionary<string, string> GetUserData(string accessToken) { - WindowsLiveUserData graph; - var request = - WebRequest.Create( - "https://apis.live.net/v5.0/me?access_token=" + MessagingUtilities.EscapeUriDataStringRfc3986(accessToken)); - using (var response = request.GetResponse()) { - using (var responseStream = response.GetResponseStream()) { - graph = JsonHelper.Deserialize<WindowsLiveUserData>(responseStream); - } - } - - var userData = new Dictionary<string, string>(); - userData.AddItemIfNotEmpty("id", graph.Id); - userData.AddItemIfNotEmpty("username", graph.Name); - userData.AddItemIfNotEmpty("name", graph.Name); - userData.AddItemIfNotEmpty("link", graph.Link == null ? null : graph.Link.AbsoluteUri); - userData.AddItemIfNotEmpty("gender", graph.Gender); - userData.AddItemIfNotEmpty("firstname", graph.FirstName); - userData.AddItemIfNotEmpty("lastname", graph.LastName); - return userData; - } - - /// <summary> - /// Queries the access token from the specified authorization code. - /// </summary> - /// <param name="returnUrl"> - /// The return URL. - /// </param> - /// <param name="authorizationCode"> - /// The authorization code. - /// </param> - /// <returns> - /// The query access token. - /// </returns> - protected override string QueryAccessToken(Uri returnUrl, string authorizationCode) { - var entity = - MessagingUtilities.CreateQueryString( - new Dictionary<string, string> { - { "client_id", this.appId }, - { "redirect_uri", returnUrl.AbsoluteUri }, - { "client_secret", this.appSecret }, - { "code", authorizationCode }, - { "grant_type", "authorization_code" }, - }); - - WebRequest tokenRequest = WebRequest.Create(TokenEndpoint); - tokenRequest.ContentType = "application/x-www-form-urlencoded"; - tokenRequest.ContentLength = entity.Length; - tokenRequest.Method = "POST"; - - using (Stream requestStream = tokenRequest.GetRequestStream()) { - var writer = new StreamWriter(requestStream); - writer.Write(entity); - writer.Flush(); - } - - HttpWebResponse tokenResponse = (HttpWebResponse)tokenRequest.GetResponse(); - if (tokenResponse.StatusCode == HttpStatusCode.OK) { - using (Stream responseStream = tokenResponse.GetResponseStream()) { - var tokenData = JsonHelper.Deserialize<OAuth2AccessTokenData>(responseStream); - if (tokenData != null) { - return tokenData.AccessToken; - } - } - } - - return null; - } - - #endregion } -} +}
\ No newline at end of file diff --git a/src/DotNetOpenAuth.AspNet/Clients/OpenID/GoogleOpenIdClient.cs b/src/DotNetOpenAuth.AspNet/Clients/OpenID/GoogleOpenIdClient.cs index aedcb80..6b4061a 100644 --- a/src/DotNetOpenAuth.AspNet/Clients/OpenID/GoogleOpenIdClient.cs +++ b/src/DotNetOpenAuth.AspNet/Clients/OpenID/GoogleOpenIdClient.cs @@ -37,8 +37,7 @@ namespace DotNetOpenAuth.AspNet.Clients { if (fetchResponse != null) { var extraData = new Dictionary<string, string>(); extraData.AddItemIfNotEmpty("email", fetchResponse.GetAttributeValue(WellKnownAttributes.Contact.Email)); - extraData.AddItemIfNotEmpty( - "country", fetchResponse.GetAttributeValue(WellKnownAttributes.Contact.HomeAddress.Country)); + extraData.AddItemIfNotEmpty("country", fetchResponse.GetAttributeValue(WellKnownAttributes.Contact.HomeAddress.Country)); extraData.AddItemIfNotEmpty("firstName", fetchResponse.GetAttributeValue(WellKnownAttributes.Name.First)); extraData.AddItemIfNotEmpty("lastName", fetchResponse.GetAttributeValue(WellKnownAttributes.Name.Last)); @@ -67,4 +66,4 @@ namespace DotNetOpenAuth.AspNet.Clients { #endregion } -} +}
\ No newline at end of file |