Webiant Logo Webiant Logo
  1. No results found.

    Try your search with a different keyword or use * as a wildcard.

AuthenticationPluginManager.cs

using Nop.Core.Domain.Customers;
using Nop.Services.Customers;
using Nop.Services.Plugins;

namespace Nop.Services.Authentication.External;

/// 
/// Represents an authentication plugin manager implementation
/// 
public partial class AuthenticationPluginManager : PluginManager, IAuthenticationPluginManager
{
    #region Fields

    protected readonly ExternalAuthenticationSettings _externalAuthenticationSettings;

    #endregion

    #region Ctor

    public AuthenticationPluginManager(ExternalAuthenticationSettings externalAuthenticationSettings,
        ICustomerService customerService,
        IPluginService pluginService) : base(customerService, pluginService)
    {
        _externalAuthenticationSettings = externalAuthenticationSettings;
    }

    #endregion

    #region Methods

    /// 
    /// Load active authentication methods
    /// 
    /// Filter by customer; pass null to load all plugins
    /// Filter by store; pass 0 to load all plugins
    /// 
    /// A task that represents the asynchronous operation
    /// The task result contains the list of active authentication methods
    /// 
    public virtual async Task> LoadActivePluginsAsync(Customer customer = null, int storeId = 0)
    {
        return await LoadActivePluginsAsync(_externalAuthenticationSettings.ActiveAuthenticationMethodSystemNames, customer, storeId);
    }

    /// 
    /// Check whether the passed authentication method is active
    /// 
    /// Authentication method to check
    /// Result
    public virtual bool IsPluginActive(IExternalAuthenticationMethod authenticationMethod)
    {
        return IsPluginActive(authenticationMethod, _externalAuthenticationSettings.ActiveAuthenticationMethodSystemNames);
    }

    /// 
    /// Check whether the authentication method with the passed system name is active
    /// 
    /// System name of authentication method to check
    /// Filter by customer; pass null to load all plugins
    /// Filter by store; pass 0 to load all plugins
    /// 
    /// A task that represents the asynchronous operation
    /// The task result contains the result
    /// 
    public virtual async Task IsPluginActiveAsync(string systemName, Customer customer = null, int storeId = 0)
    {
        var authenticationMethod = await LoadPluginBySystemNameAsync(systemName, customer, storeId);
        return IsPluginActive(authenticationMethod);
    }

    #endregion
}