phphybridauthhybridauthprovider

How to disable fb login based on some condition in hybridauth


How can we disable FB login based on some condition. For example if the time is between 2am and 4am disable the facebook login ( just an example) . My problem is not with the logic of the condition, I can certainly apply that. but my problem is once the condition is met then how to disable the fb login programmatically in hybridauth

Thank you in advance

Ps. you may wanna look into the code here:https://github.com/hybridauth/hybridauth

http://hybridauth.sourceforge.net/


Solution

  • From the documentation we can see this entry;

    enabled can be true or false; if you don't want to use a specific provider then set it to false

    If you open hybridauth/config.php, you'll see a configuration array, which holds configurations for different authentication methods. Most interestingly, we can see an key named enabled, which we can manipulate.

    Modifying the value directly.

    We can modify the value directly, by using the ternary operator. For example;

    ...
    
    "Facebook" => array ( 
                    "enabled" => (condition ? true : false), //Ternary operator modifying `enabled` value.
                    "keys"    => array ( "id" => "", "secret" => "" ),
                    "trustForwarded" => false
                ),
    ....
    

    However, we can do this by modifying it after the configuration has been loaded.

    Modifying the value later on.

    If you open up examples/social_hub/login.php, you'll see we load the config file and use it. Here is where we can modify that enabled key.

    The configuration is held within the variable $config, so;

    if( condition ) {
      $config['providers']['Facebook']['enabled'] = FALSE;
    }