//----------------------------------------------------------------------- // // 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 { /// /// 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); /// /// 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); } } /// /// 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 user id that is returned from the provider. It is unique only within the Provider's namespace. /// public string ProviderUserId { get; private set; } /// /// Gets an (insecure, non-unique) alias for the user that the user should recognize as himself/herself. /// /// This may take the form of an email address, a URL, or any other value that the user may recognize. /// /// This alias may come from the Provider or may be derived by the relying party if the Provider does not supply one. /// It is not guaranteed to be unique and certainly does not merit any trust in any suggested authenticity. /// public string UserName { get; private set; } } }