summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.OAuth.ServiceProvider/OAuth/ChannelElements
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2012-02-08 07:49:57 -0800
committerAndrew Arnott <andrewarnott@gmail.com>2012-02-08 17:30:02 -0800
commitdcf7af7bcef6724ba73e5cf952eaf554f4da4e9f (patch)
tree3e097dff0522b75ce3630ca8e017971cfe5724a0 /src/DotNetOpenAuth.OAuth.ServiceProvider/OAuth/ChannelElements
parentbef6c27a1b50519f23a5308547d65b55c8e98868 (diff)
downloadDotNetOpenAuth-dcf7af7bcef6724ba73e5cf952eaf554f4da4e9f.zip
DotNetOpenAuth-dcf7af7bcef6724ba73e5cf952eaf554f4da4e9f.tar.gz
DotNetOpenAuth-dcf7af7bcef6724ba73e5cf952eaf554f4da4e9f.tar.bz2
Added DotNetOpenAuth.OAuth.Common to contain dependencies shared between OAuth 1 and OAuth 2.
Related to and closes #71
Diffstat (limited to 'src/DotNetOpenAuth.OAuth.ServiceProvider/OAuth/ChannelElements')
-rw-r--r--src/DotNetOpenAuth.OAuth.ServiceProvider/OAuth/ChannelElements/OAuth1Principal.cs33
-rw-r--r--src/DotNetOpenAuth.OAuth.ServiceProvider/OAuth/ChannelElements/OAuthIdentity.cs64
-rw-r--r--src/DotNetOpenAuth.OAuth.ServiceProvider/OAuth/ChannelElements/OAuthPrincipal.cs109
3 files changed, 33 insertions, 173 deletions
diff --git a/src/DotNetOpenAuth.OAuth.ServiceProvider/OAuth/ChannelElements/OAuth1Principal.cs b/src/DotNetOpenAuth.OAuth.ServiceProvider/OAuth/ChannelElements/OAuth1Principal.cs
new file mode 100644
index 0000000..03f8030
--- /dev/null
+++ b/src/DotNetOpenAuth.OAuth.ServiceProvider/OAuth/ChannelElements/OAuth1Principal.cs
@@ -0,0 +1,33 @@
+//-----------------------------------------------------------------------
+// <copyright file="OAuth1Principal.cs" company="Outercurve Foundation">
+// Copyright (c) Outercurve Foundation. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOpenAuth.OAuth.ChannelElements {
+ using System;
+ using System.Collections.Generic;
+ using System.Diagnostics.CodeAnalysis;
+ using System.Linq;
+ using System.Runtime.InteropServices;
+ using System.Text;
+
+ /// <summary>
+ /// Represents an OAuth consumer that is impersonating a known user on the system.
+ /// </summary>
+ [SuppressMessage("Microsoft.Interoperability", "CA1409:ComVisibleTypesShouldBeCreatable", Justification = "Not cocreatable.")]
+ [Serializable]
+ [ComVisible(true)]
+ internal class OAuth1Principal : OAuthPrincipal {
+ /// <summary>
+ /// Initializes a new instance of the <see cref="OAuth1Principal"/> class.
+ /// </summary>
+ /// <param name="token">The access token.</param>
+ internal OAuth1Principal(IServiceProviderAccessToken token)
+ : base(token.Username, token.Roles) {
+ Requires.NotNull(token, "token");
+
+ this.AccessToken = token.Token;
+ }
+ }
+}
diff --git a/src/DotNetOpenAuth.OAuth.ServiceProvider/OAuth/ChannelElements/OAuthIdentity.cs b/src/DotNetOpenAuth.OAuth.ServiceProvider/OAuth/ChannelElements/OAuthIdentity.cs
deleted file mode 100644
index 1f9fbbc..0000000
--- a/src/DotNetOpenAuth.OAuth.ServiceProvider/OAuth/ChannelElements/OAuthIdentity.cs
+++ /dev/null
@@ -1,64 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="OAuthIdentity.cs" company="Outercurve Foundation">
-// Copyright (c) Outercurve Foundation. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOpenAuth.OAuth.ChannelElements {
- using System;
- using System.Diagnostics.CodeAnalysis;
- using System.Diagnostics.Contracts;
- using System.Runtime.InteropServices;
- using System.Security.Principal;
- using DotNetOpenAuth.Messaging;
-
- /// <summary>
- /// Represents an OAuth consumer that is impersonating a known user on the system.
- /// </summary>
- [SuppressMessage("Microsoft.Interoperability", "CA1409:ComVisibleTypesShouldBeCreatable", Justification = "Not cocreatable.")]
- [Serializable]
- [ComVisible(true)]
- public class OAuthIdentity : IIdentity {
- /// <summary>
- /// Initializes a new instance of the <see cref="OAuthIdentity"/> class.
- /// </summary>
- /// <param name="username">The username.</param>
- internal OAuthIdentity(string username) {
- Requires.NotNullOrEmpty(username, "username");
- this.Name = username;
- }
-
- #region IIdentity Members
-
- /// <summary>
- /// Gets the type of authentication used.
- /// </summary>
- /// <value>The constant "OAuth"</value>
- /// <returns>
- /// The type of authentication used to identify the user.
- /// </returns>
- public string AuthenticationType {
- get { return "OAuth"; }
- }
-
- /// <summary>
- /// Gets a value indicating whether the user has been authenticated.
- /// </summary>
- /// <value>The value <c>true</c></value>
- /// <returns>true if the user was authenticated; otherwise, false.
- /// </returns>
- public bool IsAuthenticated {
- get { return true; }
- }
-
- /// <summary>
- /// Gets the name of the user who authorized the OAuth token the consumer is using for authorization.
- /// </summary>
- /// <returns>
- /// The name of the user on whose behalf the code is running.
- /// </returns>
- public string Name { get; private set; }
-
- #endregion
- }
-}
diff --git a/src/DotNetOpenAuth.OAuth.ServiceProvider/OAuth/ChannelElements/OAuthPrincipal.cs b/src/DotNetOpenAuth.OAuth.ServiceProvider/OAuth/ChannelElements/OAuthPrincipal.cs
deleted file mode 100644
index 0da4a66..0000000
--- a/src/DotNetOpenAuth.OAuth.ServiceProvider/OAuth/ChannelElements/OAuthPrincipal.cs
+++ /dev/null
@@ -1,109 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="OAuthPrincipal.cs" company="Outercurve Foundation">
-// Copyright (c) Outercurve Foundation. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOpenAuth.OAuth.ChannelElements {
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Diagnostics.CodeAnalysis;
- using System.Diagnostics.Contracts;
- using System.Linq;
- using System.Runtime.InteropServices;
- using System.Security.Principal;
-
- /// <summary>
- /// Represents an OAuth consumer that is impersonating a known user on the system.
- /// </summary>
- [SuppressMessage("Microsoft.Interoperability", "CA1409:ComVisibleTypesShouldBeCreatable", Justification = "Not cocreatable.")]
- [Serializable]
- [ComVisible(true)]
- public class OAuthPrincipal : IPrincipal {
- /// <summary>
- /// The roles this user belongs to.
- /// </summary>
- private ICollection<string> roles;
-
- /// <summary>
- /// Initializes a new instance of the <see cref="OAuthPrincipal"/> class.
- /// </summary>
- /// <param name="userName">The username.</param>
- /// <param name="roles">The roles this user belongs to.</param>
- public OAuthPrincipal(string userName, string[] roles)
- : this(new OAuthIdentity(userName), roles) {
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="OAuthPrincipal"/> class.
- /// </summary>
- /// <param name="token">The access token.</param>
- internal OAuthPrincipal(IServiceProviderAccessToken token)
- : this(token.Username, token.Roles) {
- Requires.NotNull(token, "token");
-
- this.AccessToken = token.Token;
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="OAuthPrincipal"/> class.
- /// </summary>
- /// <param name="identity">The identity.</param>
- /// <param name="roles">The roles this user belongs to.</param>
- internal OAuthPrincipal(OAuthIdentity identity, string[] roles) {
- this.Identity = identity;
- this.roles = roles;
- }
-
- /// <summary>
- /// Gets the access token used to create this principal.
- /// </summary>
- /// <value>A non-empty string.</value>
- public string AccessToken { get; private set; }
-
- /// <summary>
- /// Gets the roles that this principal has as a ReadOnlyCollection.
- /// </summary>
- public ReadOnlyCollection<string> Roles
- {
- get { return new ReadOnlyCollection<string>(this.roles.ToList()); }
- }
-
- #region IPrincipal Members
-
- /// <summary>
- /// Gets the identity of the current principal.
- /// </summary>
- /// <value></value>
- /// <returns>
- /// The <see cref="T:System.Security.Principal.IIdentity"/> object associated with the current principal.
- /// </returns>
- public IIdentity Identity { get; private set; }
-
- /// <summary>
- /// Determines whether the current principal belongs to the specified role.
- /// </summary>
- /// <param name="role">The name of the role for which to check membership.</param>
- /// <returns>
- /// true if the current principal is a member of the specified role; otherwise, false.
- /// </returns>
- /// <remarks>
- /// The role membership check uses <see cref="StringComparer.OrdinalIgnoreCase"/>.
- /// </remarks>
- public bool IsInRole(string role) {
- return this.roles.Contains(role, StringComparer.OrdinalIgnoreCase);
- }
-
- #endregion
-
- /// <summary>
- /// Creates a new instance of GenericPrincipal based on this OAuthPrincipal.
- /// </summary>
- /// <returns>A new instance of GenericPrincipal with a GenericIdentity, having the same username and roles as this OAuthPrincipal and OAuthIdentity</returns>
- public GenericPrincipal CreateGenericPrincipal()
- {
- return new GenericPrincipal(new GenericIdentity(this.Identity.Name), this.roles.ToArray());
- }
- }
-}