diff options
author | Microsoft <aspnet@microsoft.com> | 2011-12-20 17:52:24 -0800 |
---|---|---|
committer | Andrew Arnott <andrewarnott@gmail.com> | 2012-03-01 19:36:32 -0800 |
commit | 1197a5c95f0af0ced8339ae07ef6b3980532c8d7 (patch) | |
tree | b771327d73f970665e28c9679b2baf6c2e0a9b67 /src/DotNetOpenAuth.AspNet/AuthenticationResult.cs | |
parent | 67e1a42ffe2ed7ac2bf99c703f17e4406cc35921 (diff) | |
download | DotNetOpenAuth-1197a5c95f0af0ced8339ae07ef6b3980532c8d7.zip DotNetOpenAuth-1197a5c95f0af0ced8339ae07ef6b3980532c8d7.tar.gz DotNetOpenAuth-1197a5c95f0af0ced8339ae07ef6b3980532c8d7.tar.bz2 |
Make changes per discussion. Remove the DNOA.WebPages project. Rename DNOA.Web to DNOA.AspNet.
Diffstat (limited to 'src/DotNetOpenAuth.AspNet/AuthenticationResult.cs')
-rw-r--r-- | src/DotNetOpenAuth.AspNet/AuthenticationResult.cs | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/src/DotNetOpenAuth.AspNet/AuthenticationResult.cs b/src/DotNetOpenAuth.AspNet/AuthenticationResult.cs new file mode 100644 index 0000000..b1e4dbf --- /dev/null +++ b/src/DotNetOpenAuth.AspNet/AuthenticationResult.cs @@ -0,0 +1,108 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using DotNetOpenAuth.Messaging; + +namespace DotNetOpenAuth.AspNet +{ + /// <summary> + /// Represents the result of OAuth & OpenId authentication + /// </summary> + public class AuthenticationResult + { + /// <summary> + /// Returns an instance which indicates failed authentication. + /// </summary> + [SuppressMessage( + "Microsoft.Security", + "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", + Justification = "This type is immutable.")] + public static readonly AuthenticationResult Failed = new AuthenticationResult(isSuccessful: false); + + /// <summary> + /// Gets a value indicating whether the authentication step is successful. + /// </summary> + /// <value> + /// <c>true</c> if authentication is successful; otherwise, <c>false</c>. + /// </value> + public bool IsSuccessful { get; private set; } + + /// <summary> + /// Gets the provider's name. + /// </summary> + public string Provider { get; private set; } + + /// <summary> + /// Gets the unique user id that is returned from the provider. + /// </summary> + public string ProviderUserId { get; private set; } + + /// <summary> + /// Gets the user name that is returned from the provider. + /// </summary> + public string UserName { get; private set; } + + /// <summary> + /// Gets the optional extra data that may be returned from the provider + /// </summary> + public IDictionary<string, string> ExtraData { get; private set; } + + /// <summary> + /// Gets the error that may have occured during the authentication process + /// </summary> + public Exception Error { get; private set; } + + /// <summary> + /// Initializes a new instance of the <see cref="AuthenticationResult"/> class. + /// </summary> + /// <param name="isSuccessful">if set to <c>true</c> [is successful].</param> + public AuthenticationResult(bool isSuccessful) : + this(isSuccessful, + provider: null, + providerUserId: null, + userName: null, + extraData: null) + { + } + + /// <summary> + /// Initializes a new instance of the <see cref="AuthenticationResult"/> class. + /// </summary> + /// <param name="exception">The exception.</param> + public AuthenticationResult(Exception exception) : this(isSuccessful: false) + { + if (exception == null) + { + throw new ArgumentNullException("exception"); + } + + Error = exception; + } + + /// <summary> + /// Initializes a new instance of the <see cref="AuthenticationResult"/> class. + /// </summary> + /// <param name="isSuccessful">if set to <c>true</c> [is successful].</param> + /// <param name="provider">The provider.</param> + /// <param name="providerUserId">The provider user id.</param> + /// <param name="userName">Name of the user.</param> + /// <param name="extraData">The extra data.</param> + public AuthenticationResult( + bool isSuccessful, + string provider, + string providerUserId, + string userName, + IDictionary<string, string> extraData) + { + IsSuccessful = isSuccessful; + Provider = provider; + ProviderUserId = providerUserId; + UserName = userName; + if (extraData != null) + { + // wrap extraData in a read-only dictionary + ExtraData = new ReadOnlyDictionary<string, string>(extraData); + } + } + } +}
\ No newline at end of file |