Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsProvidersProvidersDNN Custom Authentication provider not displaying if default Auth provider is disabledDNN Custom Authentication provider not displaying if default Auth provider is disabled
Previous
 
Next
New Post
8/28/2013 3:13 AM
 
I followed this guide as a template to creating my custom authentication provider

DotNetNuke Tips and Tricks #12: Creating your own Authentication Provider


In that guide he creates his own authentication configuration class so that it does not share configuration with the default provider (which he built his custom provider off) which I converted to c#.

    [Serializable()]
        public class ScanToLoginAuthConfig
        {
            #region "Private Members"

            private bool _Enabled = true;

            private int _portalId;
            private const string CACHEKEY = "Authentication.ScanToLogin.DNN";

            private const string ENABLED_SETTING_KEY = "DNN_ScanToLogin_Enabled";

            #endregion

            #region "Constructor(s)"

            protected ScanToLoginAuthConfig(int portalID)
            {
                _portalId = portalID;

                try
                {
                    string setting = Null.NullString;
                    if (PortalController.GetPortalSettingsDictionary(portalID)
                                        .TryGetValue(ENABLED_SETTING_KEY, out setting))
                    {
                        _Enabled = bool.Parse(setting);
                    }
                    setting = Null.NullString;
                }
                catch
                {
                }
            }

            #endregion

            #region "Public Properties"

            public bool Enabled
            {
                get { return _Enabled; }
                set { _Enabled = value; }
            }

            [Browsable(false)]
            public int PortalId
            {
                get { return _portalId; }
                set { _portalId = value; }
            }

            #endregion

            #region "Public SHared Methods"

            public static void ClearConfig(int portalId)
            {
                string key = CACHEKEY + "_" + portalId.ToString();
                DataCache.RemoveCache(key);
            }

            public static ScanToLoginAuthConfig GetConfig(int portalId)
            {

                string key = CACHEKEY + "_" + portalId.ToString();
                ScanToLoginAuthConfig config = (ScanToLoginAuthConfig) DataCache.GetCache(key);

                if (config == null)
                {
                    config = new ScanToLoginAuthConfig(portalId);
                    DataCache.SetCache(key, config);
                }
                return config;
            }

            public static void UpdateConfig(ScanToLoginAuthConfig config)
            {
                PortalController.UpdatePortalSetting(config.PortalId, "DNN_Enabled", config.Enabled.ToString());
                ClearConfig(config.PortalId);
            }

            #endregion

        }

This works in so far as I con toggle my authentication provider as enabled or disabled independently of the default provider, however, my provider does not load if the default provider is not enabled.

    if (PortalController.GetPortalSettingsDictionary(portalID)
                                    .TryGetValue(ENABLED_SETTING_KEY, out setting))
                {
                    _Enabled = bool.Parse(setting);
                }

When I go in to modify the settings the above code fires, but it never finds the value specified by "ENABLED_SETTING_KEY" ("DNN_ScanToLogin_Enabled"). The portal settings dictionary (for that portal ID) contains 14 items and "DNN_ScanToLogin_Enabled" is not in there. Can anyone tell me why that is, PLEASE!

Maybe I am on the wrong track anyway, and this is NOT the reason for the module not displaying if the default provider is not enabled. If the default provider is enabled, then my provider displays in a tab and works fine. I don't want the default provider to display however.

 
New Post
8/28/2013 5:12 AM
 
EDIT I've modified things somewhat

public static void ClearConfig(int portalId)
{
string key = CACHEKEY + "_" + portalId.ToString();
DataCache.RemoveCache(key);
}
and

public static ScanToLoginAuthConfig GetConfig(int portalId)
{

string key = CACHEKEY + "_" + portalId.ToString();
Have become

public static void UpdateConfig(ScanToLoginAuthConfig config)
{
PortalController.UpdatePortalSetting(config.PortalId, "DNN_ScanToLogin_Enabled", config.Enabled.ToString());
ClearConfig(config.PortalId);
}
and

public static ScanToLoginAuthConfig GetConfig(int portalId)
{
string key = CACHEKEY;// +"_" + portalId.ToString();
Respectively. So now the keys seem to update and set correctly (for my unspecified definition of correctly...) However when I disable the default authentication provider and enable my authentication provider, it still does not display my provider and instead shows the default. When both default and mine are enabled, then both display, tabbed.

I also updated the following to include the key's name as it is defined at the top of the code.

public static void UpdateConfig(ScanToLoginAuthConfig config)
{
PortalController.UpdatePortalSetting(config.PortalId, "DNN_ScanToLogin_Enabled", config.Enabled.ToString());
ClearConfig(config.PortalId);
}

 
New Post
8/28/2013 5:23 AM
 

EDIT I've modified things somewhat

public static void ClearConfig(int portalId) { string key = CACHEKEY + "_" + portalId.ToString(); DataCache.RemoveCache(key); } 

and

public static ScanToLoginAuthConfig GetConfig(int portalId) { string key = CACHEKEY + "_" + portalId.ToString(); 

Have become

public static void UpdateConfig(ScanToLoginAuthConfig config) { PortalController.UpdatePortalSetting(config.PortalId, "DNN_ScanToLogin_Enabled", config.Enabled.ToString()); ClearConfig(config.PortalId); } 

and

public static ScanToLoginAuthConfig GetConfig(int portalId) { string key = CACHEKEY;// +"_" + portalId.ToString(); 

Respectively. So now the keys seem to update and set correctly (for my unspecified definition of correctly...) However when I disable the default authentication provider and enable my authentication provider, it still does not display my provider and instead shows the default. When both default and mine are enabled, then both display, tabbed.

I also updated the following to include the key's name as it is defined at the top of the code.

public static void UpdateConfig(ScanToLoginAuthConfig config) { PortalController.UpdatePortalSetting(config.PortalId, "DNN_ScanToLogin_Enabled", config.Enabled.ToString()); ClearConfig(config.PortalId); }
 
Previous
 
Next
HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsProvidersProvidersDNN Custom Authentication provider not displaying if default Auth provider is disabledDNN Custom Authentication provider not displaying if default Auth provider is disabled


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out