summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.AspNet/Clients/OAuth2
diff options
context:
space:
mode:
Diffstat (limited to 'src/DotNetOpenAuth.AspNet/Clients/OAuth2')
-rw-r--r--src/DotNetOpenAuth.AspNet/Clients/OAuth2/FacebookClient.cs137
-rw-r--r--src/DotNetOpenAuth.AspNet/Clients/OAuth2/FacebookGraphData.cs62
-rw-r--r--src/DotNetOpenAuth.AspNet/Clients/OAuth2/JsonHelper.cs19
-rw-r--r--src/DotNetOpenAuth.AspNet/Clients/OAuth2/OAuth2AccessTokenData.cs19
-rw-r--r--src/DotNetOpenAuth.AspNet/Clients/OAuth2/OAuth2Client.cs114
-rw-r--r--src/DotNetOpenAuth.AspNet/Clients/OAuth2/WindowsLiveClient.cs150
-rw-r--r--src/DotNetOpenAuth.AspNet/Clients/OAuth2/WindowsLiveUserData.cs66
7 files changed, 366 insertions, 201 deletions
diff --git a/src/DotNetOpenAuth.AspNet/Clients/OAuth2/FacebookClient.cs b/src/DotNetOpenAuth.AspNet/Clients/OAuth2/FacebookClient.cs
index b98989a..5745bad 100644
--- a/src/DotNetOpenAuth.AspNet/Clients/OAuth2/FacebookClient.cs
+++ b/src/DotNetOpenAuth.AspNet/Clients/OAuth2/FacebookClient.cs
@@ -13,65 +13,98 @@ namespace DotNetOpenAuth.AspNet.Clients {
using DotNetOpenAuth.AspNet.Resources;
using DotNetOpenAuth.Messaging;
+ /// <summary>
+ /// The facebook client.
+ /// </summary>
public sealed class FacebookClient : OAuth2Client {
+ #region Constants and Fields
+
+ /// <summary>
+ /// The authorization endpoint.
+ /// </summary>
private const string AuthorizationEndpoint = "https://www.facebook.com/dialog/oauth";
+
+ /// <summary>
+ /// The token endpoint.
+ /// </summary>
private const string TokenEndpoint = "https://graph.facebook.com/oauth/access_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="FacebookClient"/> class.
+ /// </summary>
+ /// <param name="appId">
+ /// The app id.
+ /// </param>
+ /// <param name="appSecret">
+ /// The app secret.
+ /// </param>
+ /// <exception cref="ArgumentException">
+ /// </exception>
+ /// <exception cref="ArgumentException">
+ /// </exception>
public FacebookClient(string appId, string appSecret)
: base("facebook") {
- if (String.IsNullOrEmpty(appId)) {
+ if (string.IsNullOrEmpty(appId)) {
throw new ArgumentException(
- String.Format(CultureInfo.CurrentCulture, WebResources.Argument_Cannot_Be_Null_Or_Empty, "appId"),
- "appId");
+ string.Format(CultureInfo.CurrentCulture, WebResources.Argument_Cannot_Be_Null_Or_Empty, "appId"), "appId");
}
- if (String.IsNullOrEmpty("appSecret")) {
+ if (string.IsNullOrEmpty("appSecret")) {
throw new ArgumentException(
- String.Format(CultureInfo.CurrentCulture, WebResources.Argument_Cannot_Be_Null_Or_Empty, "appSecret"),
- "appSecret");
+ string.Format(CultureInfo.CurrentCulture, WebResources.Argument_Cannot_Be_Null_Or_Empty, "appSecret"), "appSecret");
}
- _appId = appId;
- _appSecret = appSecret;
+ this._appId = appId;
+ this._appSecret = appSecret;
}
+ #endregion
+
+ #region Methods
+
+ /// <summary>
+ /// The get service login url.
+ /// </summary>
+ /// <param name="returnUrl">
+ /// The return url.
+ /// </param>
+ /// <returns>
+ /// </returns>
protected override Uri GetServiceLoginUrl(Uri returnUrl) {
// 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", _appId },
- { "redirect_uri", returnUrl.AbsoluteUri },
- });
+ builder.AppendQueryArgs(
+ new Dictionary<string, string> { { "client_id", this._appId }, { "redirect_uri", returnUrl.AbsoluteUri }, });
return builder.Uri;
}
- protected override string QueryAccessToken(Uri returnUrl, string authorizationCode) {
- // Note: Facebook doesn't like us to url-encode the redirect_uri value
- var builder = new UriBuilder(TokenEndpoint);
- builder.AppendQueryArgs(new Dictionary<string, string> {
- { "client_id", _appId },
- { "redirect_uri", returnUrl.AbsoluteUri },
- { "client_secret", _appSecret },
- { "code", authorizationCode },
- });
-
- using (WebClient client = new WebClient()) {
- string data = client.DownloadString(builder.Uri);
- if (String.IsNullOrEmpty(data)) {
- return null;
- }
-
- var parsedQueryString = HttpUtility.ParseQueryString(data);
- return parsedQueryString["access_token"];
- }
- }
-
+ /// <summary>
+ /// The get user data.
+ /// </summary>
+ /// <param name="accessToken">
+ /// The access token.
+ /// </param>
+ /// <returns>
+ /// </returns>
protected override IDictionary<string, string> GetUserData(string accessToken) {
FacebookGraphData graphData;
- var request = WebRequest.Create("https://graph.facebook.com/me?access_token=" + MessagingUtilities.EscapeUriDataStringRfc3986(accessToken));
+ var request =
+ WebRequest.Create(
+ "https://graph.facebook.com/me?access_token=" + MessagingUtilities.EscapeUriDataStringRfc3986(accessToken));
using (var response = request.GetResponse()) {
using (var responseStream = response.GetResponseStream()) {
graphData = JsonHelper.Deserialize<FacebookGraphData>(responseStream);
@@ -88,5 +121,41 @@ namespace DotNetOpenAuth.AspNet.Clients {
userData.AddItemIfNotEmpty("birthday", graphData.Birthday);
return userData;
}
+
+ /// <summary>
+ /// The query access token.
+ /// </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) {
+ // Note: Facebook doesn't like us to url-encode the redirect_uri value
+ var builder = new UriBuilder(TokenEndpoint);
+ builder.AppendQueryArgs(
+ new Dictionary<string, string> {
+ { "client_id", this._appId },
+ { "redirect_uri", returnUrl.AbsoluteUri },
+ { "client_secret", this._appSecret },
+ { "code", authorizationCode },
+ });
+
+ using (WebClient client = new WebClient()) {
+ string data = client.DownloadString(builder.Uri);
+ if (string.IsNullOrEmpty(data)) {
+ return null;
+ }
+
+ var parsedQueryString = HttpUtility.ParseQueryString(data);
+ return parsedQueryString["access_token"];
+ }
+ }
+
+ #endregion
}
}
diff --git a/src/DotNetOpenAuth.AspNet/Clients/OAuth2/FacebookGraphData.cs b/src/DotNetOpenAuth.AspNet/Clients/OAuth2/FacebookGraphData.cs
index 80c42b7..53c2797 100644
--- a/src/DotNetOpenAuth.AspNet/Clients/OAuth2/FacebookGraphData.cs
+++ b/src/DotNetOpenAuth.AspNet/Clients/OAuth2/FacebookGraphData.cs
@@ -6,71 +6,61 @@
namespace DotNetOpenAuth.AspNet.Clients {
using System;
- using System.Runtime.Serialization;
using System.ComponentModel;
+ using System.Runtime.Serialization;
/// <summary>
/// Contains data of a Facebook user.
/// </summary>
/// <remarks>
- /// Technically, this class doesn't need to be public, but because we want to make it serializable
- /// in medium trust, it has to be public.
+ /// Technically, this class doesn't need to be public, but because we want to make it serializable in medium trust, it has to be public.
/// </remarks>
[DataContract]
[EditorBrowsable(EditorBrowsableState.Never)]
public class FacebookGraphData {
+ #region Public Properties
+
/// <summary>
- /// Gets or sets the id.
+ /// Gets or sets the birthday.
/// </summary>
- /// <value>
- /// The id.
- /// </value>
- [DataMember(Name = "id")]
- public string Id { get; set; }
+ /// <value> The birthday. </value>
+ [DataMember(Name = "birthday")]
+ public string Birthday { get; set; }
/// <summary>
/// Gets or sets the email.
/// </summary>
- /// <value>
- /// The email.
- /// </value>
+ /// <value> The email. </value>
[DataMember(Name = "email")]
public string Email { get; set; }
/// <summary>
- /// Gets or sets the name.
+ /// Gets or sets the gender.
/// </summary>
- /// <value>
- /// The name.
- /// </value>
- [DataMember(Name = "name")]
- public string Name { get; set; }
+ /// <value> The gender. </value>
+ [DataMember(Name = "gender")]
+ public string Gender { get; set; }
/// <summary>
- /// Gets or sets the link.
+ /// Gets or sets the id.
/// </summary>
- /// <value>
- /// The link.
- /// </value>
- [DataMember(Name = "link")]
- public Uri Link { get; set; }
+ /// <value> The id. </value>
+ [DataMember(Name = "id")]
+ public string Id { get; set; }
/// <summary>
- /// Gets or sets the gender.
+ /// Gets or sets the link.
/// </summary>
- /// <value>
- /// The gender.
- /// </value>
- [DataMember(Name = "gender")]
- public string Gender { get; set; }
+ /// <value> The link. </value>
+ [DataMember(Name = "link")]
+ public Uri Link { get; set; }
/// <summary>
- /// Gets or sets the birthday.
+ /// Gets or sets the name.
/// </summary>
- /// <value>
- /// The birthday.
- /// </value>
- [DataMember(Name = "birthday")]
- public string Birthday { get; set; }
+ /// <value> The name. </value>
+ [DataMember(Name = "name")]
+ public string Name { get; set; }
+ #endregion
}
}
diff --git a/src/DotNetOpenAuth.AspNet/Clients/OAuth2/JsonHelper.cs b/src/DotNetOpenAuth.AspNet/Clients/OAuth2/JsonHelper.cs
index 7a2da18..ddb8879 100644
--- a/src/DotNetOpenAuth.AspNet/Clients/OAuth2/JsonHelper.cs
+++ b/src/DotNetOpenAuth.AspNet/Clients/OAuth2/JsonHelper.cs
@@ -9,7 +9,24 @@ namespace DotNetOpenAuth.AspNet.Clients {
using System.IO;
using System.Runtime.Serialization.Json;
+ /// <summary>
+ /// The json helper.
+ /// </summary>
internal static class JsonHelper {
+ #region Public Methods and Operators
+
+ /// <summary>
+ /// The deserialize.
+ /// </summary>
+ /// <param name="stream">
+ /// The stream.
+ /// </param>
+ /// <typeparam name="T">
+ /// </typeparam>
+ /// <returns>
+ /// </returns>
+ /// <exception cref="ArgumentNullException">
+ /// </exception>
public static T Deserialize<T>(Stream stream) where T : class {
if (stream == null) {
throw new ArgumentNullException("stream");
@@ -18,5 +35,7 @@ namespace DotNetOpenAuth.AspNet.Clients {
var serializer = new DataContractJsonSerializer(typeof(T));
return (T)serializer.ReadObject(stream);
}
+
+ #endregion
}
}
diff --git a/src/DotNetOpenAuth.AspNet/Clients/OAuth2/OAuth2AccessTokenData.cs b/src/DotNetOpenAuth.AspNet/Clients/OAuth2/OAuth2AccessTokenData.cs
index d17b452..5da24dd 100644
--- a/src/DotNetOpenAuth.AspNet/Clients/OAuth2/OAuth2AccessTokenData.cs
+++ b/src/DotNetOpenAuth.AspNet/Clients/OAuth2/OAuth2AccessTokenData.cs
@@ -12,40 +12,35 @@ namespace DotNetOpenAuth.AspNet.Clients {
/// </summary>
[DataContract]
public class OAuth2AccessTokenData {
+ #region Public Properties
+
/// <summary>
/// Gets or sets the access token.
/// </summary>
- /// <value>
- /// The access token.
- /// </value>
+ /// <value> The access token. </value>
[DataMember(Name = "access_token")]
public string AccessToken { get; set; }
/// <summary>
/// Gets or sets the refresh token.
/// </summary>
- /// <value>
- /// The refresh token.
- /// </value>
+ /// <value> The refresh token. </value>
[DataMember(Name = "refresh_token")]
public string RefreshToken { get; set; }
/// <summary>
/// Gets or sets the scope.
/// </summary>
- /// <value>
- /// The scope.
- /// </value>
+ /// <value> The scope. </value>
[DataMember(Name = "scope")]
public string Scope { get; set; }
/// <summary>
/// Gets or sets the type of the token.
/// </summary>
- /// <value>
- /// The type of the token.
- /// </value>
+ /// <value> The type of the token. </value>
[DataMember(Name = "token_type")]
public string TokenType { get; set; }
+ #endregion
}
}
diff --git a/src/DotNetOpenAuth.AspNet/Clients/OAuth2/OAuth2Client.cs b/src/DotNetOpenAuth.AspNet/Clients/OAuth2/OAuth2Client.cs
index 7570b4d..9003bc0 100644
--- a/src/DotNetOpenAuth.AspNet/Clients/OAuth2/OAuth2Client.cs
+++ b/src/DotNetOpenAuth.AspNet/Clients/OAuth2/OAuth2Client.cs
@@ -14,33 +14,62 @@ namespace DotNetOpenAuth.AspNet.Clients {
/// Represents the base class for OAuth 2.0 clients
/// </summary>
public abstract class OAuth2Client : IAuthenticationClient {
+ #region Constants and Fields
+
+ /// <summary>
+ /// The _provider name.
+ /// </summary>
private readonly string _providerName;
+
+ /// <summary>
+ /// The _return url.
+ /// </summary>
private Uri _returnUrl;
+ #endregion
+
+ #region Constructors and Destructors
+
/// <summary>
/// Initializes a new instance of the <see cref="OAuth2Client"/> class with the specified provider name.
/// </summary>
- /// <param name="providerName">Name of the provider.</param>
+ /// <param name="providerName">
+ /// Name of the provider.
+ /// </param>
protected OAuth2Client(string providerName) {
if (providerName == null) {
throw new ArgumentNullException("providerName");
}
- _providerName = providerName;
+ this._providerName = providerName;
}
+ #endregion
+
+ #region Public Properties
+
/// <summary>
/// Gets the name of the provider which provides authentication service.
/// </summary>
public string ProviderName {
- get { return _providerName; }
+ get {
+ return this._providerName;
+ }
}
+ #endregion
+
+ #region Public Methods and Operators
+
/// <summary>
- /// Attempts to authenticate users by forwarding them to an external website, and
- /// upon succcess or failure, redirect users back to the specified url.
+ /// Attempts to authenticate users by forwarding them to an external website, and upon succcess or failure, redirect users back to the specified url.
/// </summary>
- /// <param name="returnUrl">The return url after users have completed authenticating against external website.</param>
+ /// <param name="context">
+ /// The context.
+ /// </param>
+ /// <param name="returnUrl">
+ /// The return url after users have completed authenticating against external website.
+ /// </param>
public virtual void RequestAuthentication(HttpContextBase context, Uri returnUrl) {
if (context == null) {
throw new ArgumentNullException("context");
@@ -50,17 +79,20 @@ namespace DotNetOpenAuth.AspNet.Clients {
throw new ArgumentNullException("returnUrl");
}
- _returnUrl = returnUrl;
+ this._returnUrl = returnUrl;
- string redirectUrl = GetServiceLoginUrl(returnUrl).AbsoluteUri;
+ string redirectUrl = this.GetServiceLoginUrl(returnUrl).AbsoluteUri;
context.Response.Redirect(redirectUrl, endResponse: true);
}
/// <summary>
/// Check if authentication succeeded after user is redirected back from the service provider.
/// </summary>
+ /// <param name="context">
+ /// The context.
+ /// </param>
/// <returns>
- /// An instance of <see cref="AuthenticationResult"/> containing authentication result.
+ /// An instance of <see cref="AuthenticationResult"/> containing authentication result.
/// </returns>
public virtual AuthenticationResult VerifyAuthentication(HttpContextBase context) {
if (context == null) {
@@ -68,21 +100,23 @@ namespace DotNetOpenAuth.AspNet.Clients {
}
string code = context.Request.QueryString["code"];
- if (String.IsNullOrEmpty(code)) {
+ if (string.IsNullOrEmpty(code)) {
return AuthenticationResult.Failed;
}
- string accessToken = QueryAccessToken(_returnUrl, code);
+ string accessToken = this.QueryAccessToken(this._returnUrl, code);
if (accessToken == null) {
return AuthenticationResult.Failed;
}
- IDictionary<string, string> userData = GetUserData(accessToken);
+ IDictionary<string, string> userData = this.GetUserData(accessToken);
if (userData == null) {
return AuthenticationResult.Failed;
}
+
string id = userData["id"];
string name;
+
// Some oAuth providers do not return value for the 'username' attribute.
// In that case, try the 'name' attribute. If it's still unavailable, fall back to 'id'
if (!userData.TryGetValue("username", out name) && !userData.TryGetValue("name", out name)) {
@@ -93,36 +127,50 @@ namespace DotNetOpenAuth.AspNet.Clients {
userData["accesstoken"] = accessToken;
return new AuthenticationResult(
- isSuccessful: true,
- provider: ProviderName,
- providerUserId: id,
- userName: name,
- extraData: userData);
+ isSuccessful: true, provider: this.ProviderName, providerUserId: id, userName: name, extraData: userData);
}
+ #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.
+ /// 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>
- [SuppressMessage("Microsoft.Naming", "CA1726:UsePreferredTerms", MessageId = "Login", Justification = "Login is used more consistently in ASP.Net")]
+ /// <param name="returnUrl">
+ /// The return URL.
+ /// </param>
+ /// <returns>
+ /// An absolute URL.
+ /// </returns>
+ [SuppressMessage("Microsoft.Naming", "CA1726:UsePreferredTerms", MessageId = "Login",
+ Justification = "Login is used more consistently in ASP.Net")]
protected abstract Uri GetServiceLoginUrl(Uri returnUrl);
/// <summary>
- /// Queries the access token from the specified authorization code.
+ /// Given the access token, gets the logged-in user's data. The returned dictionary must include two keys 'id', and 'username'.
/// </summary>
- /// <param name="returnUrl">The return URL.</param>
- /// <param name="authorizationCode">The authorization code.</param>
- /// <returns>The access token</returns>
- protected abstract string QueryAccessToken(Uri returnUrl, string authorizationCode);
+ /// <param name="accessToken">
+ /// The access token of the current user.
+ /// </param>
+ /// <returns>
+ /// A dictionary contains key-value pairs of user data
+ /// </returns>
+ protected abstract IDictionary<string, string> GetUserData(string accessToken);
/// <summary>
- /// Given the access token, gets the logged-in user's data. The returned dictionary must include
- /// two keys 'id', and 'username'.
+ /// Queries the access token from the specified authorization code.
/// </summary>
- /// <param name="accessToken">The access token of the current user.</param>
- /// <returns>A dictionary contains key-value pairs of user data</returns>
- protected abstract IDictionary<string, string> GetUserData(string accessToken);
+ /// <param name="returnUrl">
+ /// The return URL.
+ /// </param>
+ /// <param name="authorizationCode">
+ /// The authorization code.
+ /// </param>
+ /// <returns>
+ /// The access token
+ /// </returns>
+ protected abstract string QueryAccessToken(Uri returnUrl, string authorizationCode);
+ #endregion
}
-} \ No newline at end of file
+}
diff --git a/src/DotNetOpenAuth.AspNet/Clients/OAuth2/WindowsLiveClient.cs b/src/DotNetOpenAuth.AspNet/Clients/OAuth2/WindowsLiveClient.cs
index 548d6bd..dced87f 100644
--- a/src/DotNetOpenAuth.AspNet/Clients/OAuth2/WindowsLiveClient.cs
+++ b/src/DotNetOpenAuth.AspNet/Clients/OAuth2/WindowsLiveClient.cs
@@ -9,60 +9,140 @@ namespace DotNetOpenAuth.AspNet.Clients {
using System.Collections.Generic;
using System.IO;
using System.Net;
- using System.Text;
using DotNetOpenAuth.Messaging;
+ /// <summary>
+ /// The windows live client.
+ /// </summary>
public sealed class WindowsLiveClient : OAuth2Client {
- private const string TokenEndpoint = "https://oauth.live.com/token";
+ #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="WindowsLiveClient"/> class.
+ /// </summary>
+ /// <param name="appId">
+ /// The app id.
+ /// </param>
+ /// <param name="appSecret">
+ /// The app secret.
+ /// </param>
+ /// <exception cref="ArgumentNullException">
+ /// </exception>
+ /// <exception cref="ArgumentNullException">
+ /// </exception>
public WindowsLiveClient(string appId, string appSecret)
: base("windowslive") {
- if (String.IsNullOrEmpty(appId)) {
+ if (string.IsNullOrEmpty(appId)) {
throw new ArgumentNullException("appId");
}
- if (String.IsNullOrEmpty("appSecret")) {
+ if (string.IsNullOrEmpty("appSecret")) {
throw new ArgumentNullException("appSecret");
}
- _appId = appId;
- _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.
+ /// 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>
+ /// <param name="returnUrl">
+ /// The return URL.
+ /// </param>
protected override Uri GetServiceLoginUrl(Uri returnUrl) {
var builder = new UriBuilder(AuthorizationEndpoint);
- builder.AppendQueryArgs(new Dictionary<string, string> {
- { "client_id", _appId },
- { "scope", "wl.basic" },
- { "response_type", "code" },
- { "redirect_uri", returnUrl.AbsoluteUri },
+ 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>
+ /// <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", _appId },
- { "redirect_uri", returnUrl.AbsoluteUri },
- { "client_secret", _appSecret },
- { "code", authorizationCode },
- { "grant_type", "authorization_code" },
+ { "client_id", this._appId },
+ { "redirect_uri", returnUrl.AbsoluteUri },
+ { "client_secret", this._appSecret },
+ { "code", authorizationCode },
+ { "grant_type", "authorization_code" },
});
WebRequest tokenRequest = WebRequest.Create(TokenEndpoint);
@@ -89,32 +169,6 @@ namespace DotNetOpenAuth.AspNet.Clients {
return null;
}
- /// <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;
- }
+ #endregion
}
}
diff --git a/src/DotNetOpenAuth.AspNet/Clients/OAuth2/WindowsLiveUserData.cs b/src/DotNetOpenAuth.AspNet/Clients/OAuth2/WindowsLiveUserData.cs
index 5c16269..52192c3 100644
--- a/src/DotNetOpenAuth.AspNet/Clients/OAuth2/WindowsLiveUserData.cs
+++ b/src/DotNetOpenAuth.AspNet/Clients/OAuth2/WindowsLiveUserData.cs
@@ -6,71 +6,61 @@
namespace DotNetOpenAuth.AspNet.Clients {
using System;
- using System.Runtime.Serialization;
using System.ComponentModel;
+ using System.Runtime.Serialization;
/// <summary>
/// Contains data of a Windows Live user.
/// </summary>
/// <remarks>
- /// Technically, this class doesn't need to be public, but because we want to make it serializable
- /// in medium trust, it has to be public.
+ /// Technically, this class doesn't need to be public, but because we want to make it serializable in medium trust, it has to be public.
/// </remarks>
[DataContract]
[EditorBrowsable(EditorBrowsableState.Never)]
public class WindowsLiveUserData {
- /// <summary>
- /// Gets or sets the id.
- /// </summary>
- /// <value>
- /// The id.
- /// </value>
- [DataMember(Name = "id")]
- public string Id { get; set; }
+ #region Public Properties
/// <summary>
- /// Gets or sets the name.
- /// </summary>
- /// <value>
- /// The name.
- /// </value>
- [DataMember(Name = "name")]
- public string Name { get; set; }
-
- /// <summary>
- /// Gets or sets the link.
+ /// Gets or sets the first name.
/// </summary>
- /// <value>
- /// The link.
- /// </value>
- [DataMember(Name = "link")]
- public Uri Link { get; set; }
+ /// <value> The first name. </value>
+ [DataMember(Name = "first_name")]
+ public string FirstName { get; set; }
/// <summary>
/// Gets or sets the gender.
/// </summary>
- /// <value>
- /// The gender.
- /// </value>
+ /// <value> The gender. </value>
[DataMember(Name = "gender")]
public string Gender { get; set; }
/// <summary>
- /// Gets or sets the first name.
+ /// Gets or sets the id.
/// </summary>
- /// <value>
- /// The first name.
- /// </value>
- [DataMember(Name = "first_name")]
- public string FirstName { get; set; }
+ /// <value> The id. </value>
+ [DataMember(Name = "id")]
+ public string Id { get; set; }
/// <summary>
/// Gets or sets the last name.
/// </summary>
- /// <value>
- /// The last name.
- /// </value>
+ /// <value> The last name. </value>
[DataMember(Name = "last_name")]
public string LastName { get; set; }
+
+ /// <summary>
+ /// Gets or sets the link.
+ /// </summary>
+ /// <value> The link. </value>
+ [DataMember(Name = "link")]
+ public Uri Link { get; set; }
+
+ /// <summary>
+ /// Gets or sets the name.
+ /// </summary>
+ /// <value> The name. </value>
+ [DataMember(Name = "name")]
+ public string Name { get; set; }
+ #endregion
}
}