formapro / FpOpenIdBundle

Symfony2 OpenID security extension
53 stars 31 forks source link

Use a fixed openId provider #58

Closed alex88 closed 11 years ago

alex88 commented 11 years ago

Hello, it would be nice to create a link or a controller action to login using a set openid provider, to create links like "Login with google" etc..

Is that possible?

userfriendly commented 11 years ago

You could simply override the template and replace the text input with a selection of buttons like that. Possibly fed to it from configuration.

alex88 commented 11 years ago

That can be done too, but in some way an user can still override the endpoint, I've seen a possible solution here https://github.com/formapro/FpOpenIdBundle/pull/16 but i don't understand what he means with the GoogleConsumer extending ConsumerInterface

makasim commented 11 years ago

You have to extend relying_party(consumer in previous versions). It could look like:

<?php

namespace YouProject\OpenId;

use  Fp\OpenIdBundle\Bridge\RelyingParty\LightOpenIdRelyingParty;

class GoogleRelyingParty extends LightOpenIdRelyingParty
{
    public function supports(Request $request) 
    {
        if (false == parent::supports($request)) {
            return false;
        }

        if (false == $identity = $request->get('openid_identifier', $request->get('openid_identity'))) {
            return false;
        }

        return preg_match('/https?\:\/\/google\.com/', $identity);
    }
}

I dont test the code use it as a referance. Next add that class as service to your container. After you can use that service name while configuring openid security listener. There is option relying_party(look at the doc https://github.com/formapro/FpOpenIdBundle/blob/master/Resources/doc/configuration_reference.md)

alex88 commented 11 years ago

Oh great, thanks for the tip @makasim