How to disable fb login based on some condition in hybridauth

154 Views Asked by At

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/

2

There are 2 best solutions below

0
ʰᵈˑ On BEST ANSWER

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;
}
0
Andy On

In your super simplified example you could just add logic to build a configuration array on the fly as appropriate and then inject that into your hybridauth instance. This could be achieved by loading in the standard config array and then manipulating according to whatever business logic rules you have.

You could always extend Hybridauth but that seems overkill for the relatively simple example that you have provided.