Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

redirect_params how to dynamically pass parameters to the check route #103

Closed
db306 opened this issue Jun 5, 2018 · 5 comments
Closed

Comments

@db306
Copy link

db306 commented Jun 5, 2018

Hi there,

I'm using symfony 4.1 and I've multiple domains with optional prefixes, which makes it very difficult to configure things like this bundle. I've been searching for some info regarding how to pass extra parameters to Facebook or find a different solution. I've looked at issue #73 but seems like there is probably a simpler way of achieving this ?

Currently I have theese routes, few years ago they were talking about doing something like /({prefix}/)/connect/facebook but seems like that never actually happened so I'm stuck with making double routes.

connect_facebook:
    path: /connect/facebook
    controller: App\Controller\FacebookController::connect

connect_facebook_prefix:
    path: /{prefix}/connect/facebook
    controller: App\Controller\FacebookController::connect
    requirements:
        prefix: 'be-fr|be-nl|ch-fr|ch-de|ch-it|int|usa'

connect_facebook_check:
    path: /connect/facebook/check
    controller: App\Controller\FacebookController::connectCheck

connect_facebook_check_prefix:
    path: /{prefix}/connect/facebook/check
    controller: App\Controller\FacebookController::connectCheck
    requirements:
        prefix: 'be-fr|be-nl|ch-fr|ch-de|ch-it|int|usa'

My issue comes from my FacebookController connect function as I attempt to get the Client, it can't form the route /{prefix}/connect/facebook/check as it requires the prefix. So I would have loved to do something like $this->clientRegistry->getClient($client, ['prefix' => $prefix])->redirect();

public function connect(Request $request)
    {

        $client = 'facebook_main';

        if(!is_null($request->attributes->get('prefix'))){
            $client = 'facebook_main_prefix';
        }

        return $this->clientRegistry
            ->getClient($client)// key used in config.yml
            ->redirect();
    }

The only way I can insert the prefix is via the yaml configuration so I'm sort of stuck in doing a provider for each prefix which is completelly mad

        facebook_main_prefix:
            type: facebook
            client_id: '%env(FB_APP_ID)%'
            client_secret: '%env(FB_APP_SECRET)%'
            redirect_route: connect_facebook_check_prefix
            redirect_params:
                prefix: be-fr
            graph_api_version: v2.12

Is there a way to do this differenlty ?

@db306
Copy link
Author

db306 commented Jul 18, 2018

Ended up creating 2 facebook providers. Works. But my eyes bleed everytime I look at it.

@db306 db306 closed this as completed Jul 18, 2018
@weaverryan
Copy link
Member

weaverryan commented Jul 18, 2018

Hey @db306!

Sorry for missing this originally :). The problem is that the provider classes themselves (provided by the Facebook League library) want the redirectUri to be passed into the constructor. However, you can also pass a redirect_uri option when you call the redirect method. I haven't tried this, but tracing through the code, this should work:

$client = $this->clientRegistry->getClient('facebook');
return $client->redirect(
    [], // scopes
    ['redirect_uri' => $this->generateUrl('...')]
);

I hope this helps clean things up!

@db306
Copy link
Author

db306 commented Jul 18, 2018

Thanks Ryan I'll have a look at it :)

@WouterCypers
Copy link

I tried this, but that doesn't seem to work. See: #313

@ctsDevel
Copy link

@WouterCypers is right, it does not work on Google with parameters.

I have an Oauth with Google working perfectly but when I try to generate an URL with parameters (absolute URL). There is a Error 400: redirect_uri_mismatch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants