summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.AspNet/Clients/OAuth2/OAuth2Client.cs
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2012-03-01 22:55:03 -0800
committerAndrew Arnott <andrewarnott@gmail.com>2012-03-01 23:19:26 -0800
commit198bffe042a3650095b27bed29d0f8c98bc5c926 (patch)
treebc1b2178b73d4303221ac48d320c758751abe5e9 /src/DotNetOpenAuth.AspNet/Clients/OAuth2/OAuth2Client.cs
parent6bc4c6db7529501e8a2c0b7fa54a24fb8e4dbf42 (diff)
downloadDotNetOpenAuth-198bffe042a3650095b27bed29d0f8c98bc5c926.zip
DotNetOpenAuth-198bffe042a3650095b27bed29d0f8c98bc5c926.tar.gz
DotNetOpenAuth-198bffe042a3650095b27bed29d0f8c98bc5c926.tar.bz2
ReSharper code cleanup to help get this AspNet contribution into StyleCop compliance.
Diffstat (limited to 'src/DotNetOpenAuth.AspNet/Clients/OAuth2/OAuth2Client.cs')
-rw-r--r--src/DotNetOpenAuth.AspNet/Clients/OAuth2/OAuth2Client.cs114
1 files changed, 81 insertions, 33 deletions
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
+}