//----------------------------------------------------------------------- // // 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 & 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); /// /// 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; } /// /// Gets the optional extra data that may be returned from the provider /// public IDictionary ExtraData { get; private set; } /// /// Gets the error that may have occured during the authentication process /// public Exception Error { get; private set; } /// /// 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"); } 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) { IsSuccessful = isSuccessful; Provider = provider; ProviderUserId = providerUserId; UserName = userName; if (extraData != null) { // wrap extraData in a read-only dictionary ExtraData = new ReadOnlyDictionary(extraData); } } } }