//----------------------------------------------------------------------- // // Copyright (c) Microsoft. All rights reserved. // //----------------------------------------------------------------------- namespace DotNetOpenAuth.AspNet { using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using DotNetOpenAuth.Messaging; /// /// Represents the result of OAuth or OpenID authentication. /// public class AuthenticationResult { #region Constants and Fields /// /// Returns an instance which indicates failed authentication. /// [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "This type is immutable.")] public static readonly AuthenticationResult Failed = new AuthenticationResult(isSuccessful: false); #endregion #region Constructors and Destructors /// /// Initializes a new instance of the class. /// /// /// if set to true [is successful]. /// public AuthenticationResult(bool isSuccessful) : this(isSuccessful, provider: null, providerUserId: null, userName: null, extraData: null) { } /// /// Initializes a new instance of the class. /// /// /// The exception. /// public AuthenticationResult(Exception exception) : this(isSuccessful: false) { if (exception == null) { throw new ArgumentNullException("exception"); } this.Error = exception; } /// /// Initializes a new instance of the class. /// /// /// if set to true [is successful]. /// /// /// The provider. /// /// /// The provider user id. /// /// /// Name of the user. /// /// /// The extra data. /// public AuthenticationResult( bool isSuccessful, string provider, string providerUserId, string userName, IDictionary extraData) { this.IsSuccessful = isSuccessful; this.Provider = provider; this.ProviderUserId = providerUserId; this.UserName = userName; if (extraData != null) { // wrap extraData in a read-only dictionary this.ExtraData = new ReadOnlyDictionary(extraData); } } #endregion #region Public Properties /// /// Gets the error that may have occured during the authentication process /// public Exception Error { get; private set; } /// /// Gets the optional extra data that may be returned from the provider /// public IDictionary ExtraData { get; private set; } /// /// Gets a value indicating whether the authentication step is successful. /// /// true if authentication is successful; otherwise, false . public bool IsSuccessful { get; private set; } /// /// Gets the provider's name. /// public string Provider { get; private set; } /// /// Gets the unique user id that is returned from the provider. /// public string ProviderUserId { get; private set; } /// /// Gets the user name that is returned from the provider. /// public string UserName { get; private set; } #endregion } }