summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--samples/DotNetOpenAuth.ApplicationBlock/DotNetOpenAuth.ApplicationBlock.csproj2
-rw-r--r--src/DotNetOpenAuth/DotNetOpenAuth.csproj2
-rw-r--r--src/DotNetOpenAuth/OAuth/ChannelElements/OAuthIdentity.cs (renamed from samples/DotNetOpenAuth.ApplicationBlock/OAuthIdentity.cs)12
-rw-r--r--src/DotNetOpenAuth/OAuth/ChannelElements/OAuthPrincipal.cs (renamed from samples/DotNetOpenAuth.ApplicationBlock/OAuthPrincipal.cs)30
4 files changed, 34 insertions, 12 deletions
diff --git a/samples/DotNetOpenAuth.ApplicationBlock/DotNetOpenAuth.ApplicationBlock.csproj b/samples/DotNetOpenAuth.ApplicationBlock/DotNetOpenAuth.ApplicationBlock.csproj
index 9aae9ca..976a325 100644
--- a/samples/DotNetOpenAuth.ApplicationBlock/DotNetOpenAuth.ApplicationBlock.csproj
+++ b/samples/DotNetOpenAuth.ApplicationBlock/DotNetOpenAuth.ApplicationBlock.csproj
@@ -59,8 +59,6 @@
<Compile Include="CustomExtensions\AcmeRequest.cs" />
<Compile Include="CustomExtensions\AcmeResponse.cs" />
<Compile Include="GoogleConsumer.cs" />
- <Compile Include="OAuthIdentity.cs" />
- <Compile Include="OAuthPrincipal.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TwitterConsumer.cs" />
<Compile Include="Util.cs" />
diff --git a/src/DotNetOpenAuth/DotNetOpenAuth.csproj b/src/DotNetOpenAuth/DotNetOpenAuth.csproj
index 20e2869..50a9932 100644
--- a/src/DotNetOpenAuth/DotNetOpenAuth.csproj
+++ b/src/DotNetOpenAuth/DotNetOpenAuth.csproj
@@ -249,6 +249,8 @@
<Compile Include="OAuth\ChannelElements\ITokenGenerator.cs" />
<Compile Include="OAuth\ChannelElements\ITokenManager.cs" />
<Compile Include="OAuth\ChannelElements\OAuthHttpMethodBindingElement.cs" />
+ <Compile Include="OAuth\ChannelElements\OAuthIdentity.cs" />
+ <Compile Include="OAuth\ChannelElements\OAuthPrincipal.cs" />
<Compile Include="OAuth\ChannelElements\PlaintextSigningBindingElement.cs" />
<Compile Include="OAuth\ChannelElements\HmacSha1SigningBindingElement.cs" />
<Compile Include="OAuth\ChannelElements\IServiceProviderRequestToken.cs" />
diff --git a/samples/DotNetOpenAuth.ApplicationBlock/OAuthIdentity.cs b/src/DotNetOpenAuth/OAuth/ChannelElements/OAuthIdentity.cs
index ea9ec0b..0de2c15 100644
--- a/samples/DotNetOpenAuth.ApplicationBlock/OAuthIdentity.cs
+++ b/src/DotNetOpenAuth/OAuth/ChannelElements/OAuthIdentity.cs
@@ -4,26 +4,26 @@
// </copyright>
//-----------------------------------------------------------------------
-namespace DotNetOpenAuth.ApplicationBlock {
+namespace DotNetOpenAuth.OAuth.ChannelElements {
using System;
+ 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>
[Serializable]
[ComVisible(true)]
- internal class OAuthIdentity : IIdentity {
+ 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) {
- if (String.IsNullOrEmpty(username)) {
- throw new ArgumentNullException("username");
- }
-
+ Contract.Requires(!String.IsNullOrEmpty(username));
+ ErrorUtilities.VerifyNonZeroLength(username, "username");
this.Name = username;
}
diff --git a/samples/DotNetOpenAuth.ApplicationBlock/OAuthPrincipal.cs b/src/DotNetOpenAuth/OAuth/ChannelElements/OAuthPrincipal.cs
index 88f3b83..689c388 100644
--- a/samples/DotNetOpenAuth.ApplicationBlock/OAuthPrincipal.cs
+++ b/src/DotNetOpenAuth/OAuth/ChannelElements/OAuthPrincipal.cs
@@ -4,8 +4,10 @@
// </copyright>
//-----------------------------------------------------------------------
-namespace DotNetOpenAuth.ApplicationBlock {
+namespace DotNetOpenAuth.OAuth.ChannelElements {
using System;
+ using System.Collections.Generic;
+ using System.Diagnostics.Contracts;
using System.Linq;
using System.Runtime.InteropServices;
using System.Security.Principal;
@@ -15,11 +17,22 @@ namespace DotNetOpenAuth.ApplicationBlock {
/// </summary>
[Serializable]
[ComVisible(true)]
- internal class OAuthPrincipal : IPrincipal {
+ public class OAuthPrincipal : IPrincipal {
/// <summary>
/// The roles this user belongs to.
/// </summary>
- private string[] roles;
+ private ICollection<string> 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) {
+ Contract.Requires(token != null);
+
+ this.AccessToken = token.Token;
+ }
/// <summary>
/// Initializes a new instance of the <see cref="OAuthPrincipal"/> class.
@@ -40,6 +53,12 @@ namespace DotNetOpenAuth.ApplicationBlock {
: this(new OAuthIdentity(username), roles) {
}
+ /// <summary>
+ /// Gets the access token used to create this principal.
+ /// </summary>
+ /// <value>A non-empty string.</value>
+ public string AccessToken { get; private set; }
+
#region IPrincipal Members
/// <summary>
@@ -58,8 +77,11 @@ namespace DotNetOpenAuth.ApplicationBlock {
/// <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);
+ return this.roles.Contains(role, StringComparer.OrdinalIgnoreCase);
}
#endregion