summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.OAuth.ServiceProvider/OAuth/ChannelElements/OAuthIdentity.cs
blob: 1f9fbbcb1c79e1ba43e617515e1badc8811d44be (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//-----------------------------------------------------------------------
// <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
	}
}