heiglandreas / HybridAuth

Integrates SocialConnect as SIMPLE authentication-backend into the ZendFramework 3
https://hybridauth.heigl.org
21 stars 8 forks source link

Example to use it correct with multi provider? #27

Open Dexus opened 8 years ago

Dexus commented 8 years ago

Is it possible to get a example how to use this with multiple providers?

I get only the link from twitter (with full html) how i can disable it?

heiglandreas commented 8 years ago

Have a look at the config-file at https://github.com/heiglandreas/HybridAuth/blob/master/config/autoload/module.orgHeiglHybridAuth.test.php#L37.

You'll need one entry in that array per used authentication backend.

That line is an integration of the configuration-array from https://github.com/hybridauth/hybridauth/blob/3.0.0/example/config.php. So that might help you in getting more than one provider up and running.

Dexus commented 8 years ago

I have in the copy of the root config/autoload/module.orgHeiglHybridAuth.global.php

namespace OrgHeiglHybridAuth;

return array('OrgHeiglHybridAuth' => array(
    'hybrid_auth' => array( 
        'base_url' => 'http://clouddev.devel/auth/backend',
        'providers' => array(
            // google
            "Google" => array ( // 'id' is your google client id
               "enabled" => true,
               "keys" => array ( "id" => "", "secret" => "" ),
            ),

            // facebook
            "Facebook" => array ( // 'id' is your facebook application id
               "enabled" => true,
               "keys" => array ( "id" => "", "secret" => "" ),
               "scope" => "email, user_about_me, user_birthday, user_hometown" // optional
            ),

            // twitter
            "Twitter" => array ( // 'key' is your twitter application consumer key
               "enabled" => true,
               "keys" => array ( "key" => "", "secret" => "" )
            ),

            // github
            "Github" => array ( // 'key' is your twitter application consumer key
               "enabled" => true,
               "keys" => array ( "key" => "", "secret" => "" )
            ),

            "OpenID" => array (
                "enabled" => true
            )
        ),
        'debug_mode' => true,
        // For some reason Hybrid_Auth doesn't create file in a specified folder, be sure that it exists
        'debug_file' => __DIR__ . '/hybrid_auth.log',
    ),
    'session_name' => 'orgheiglhybridauth',
));

So an other question: how i use a fix Provider for OpenID?

In the View login.phtml

<?php echo $this->hybridauthinfo('Facebook'); ?>
<?php echo $this->hybridauthinfo('OpenID'); ?>
<a class="btn btn-block btn-lg btn-social btn-facebook" href="<?php echo $this->hybridauthinfo('Facebook'); ?>">
    <span class="fa fa-facebook"></span> Sign in with Facebook
</a>
<a class="btn btn-block btn-lg btn-social btn-google" href="<?php echo $this->hybridauthinfo('Google'); ?>">
    <span class="fa fa-google"></span> Sign in with Google
</a>
<a class="btn btn-block btn-lg btn-social btn-bitbucket " href="<?php echo $this->hybridauthinfo('Bitbucket'); ?>">
    <span class="fa fa-bitbucket "></span> Sign in with Bitbucket
</a>
<a class="btn btn-block btn-lg btn-social btn-github" href="<?php echo $this->hybridauthinfo('Github'); ?>">
    <span class="fa fa-github"></span> Sign in with Github
</a>
<a class="btn btn-block btn-lg btn-social btn-openid" href="<?php echo $this->hybridauthinfo('OpenID'); ?>">
    <span class="fa fa-openid"></span> Sign in with OpenStackID
</a>

How i can create only the link without the html stuff? And what can i do to use multiple fixed OpenID provider?

But have only one "Twitter" link for all...

Dexus commented 8 years ago

Looks like the config for the ViewHelper is loaded from the vendor module.config.php

heiglandreas commented 8 years ago

I've added a config-example to the READMEs Usage-section (Point 2). That also shows how to adapt the output of the view-helper.

Does that help you?

Regarding multiple OpenID-Providers: I didn't think of that at the time I created that module! I'll have to think about that! Gimme a day and I'll ping you back how to solve that! The different OpenID-Providers have to be passed in at a later point as is described at http://hybridauth.github.io/hybridauth/userguide/IDProvider_info_OpenID.html

heiglandreas commented 8 years ago

And for getting only the link without any fancy stuff around you'll have to add the following code to the ViewHelper around line 111:

    $backendList = $this->getBackends($providers); // already exists

    if (null !== $provider && isset($backendList[$provider])) {
        return $urlHelper(
            'hybridauth/login',
            array('redirect' => $currentRoute, 'provider' => $backendList[$provider])
        );
    }

    if (1 == count($backendList)) { // already exists

I'll add that to the module but I won't be able to release that until the weekend, so if you want to use it before that you'll need to add that. Sorry for the inconvenience!