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

Facebook Provider error when no cpTrigger is defined (headless) #36

Open
Tam opened this issue Jan 27, 2022 · 6 comments
Open

Facebook Provider error when no cpTrigger is defined (headless) #36

Tam opened this issue Jan 27, 2022 · 6 comments

Comments

@Tam
Copy link

Tam commented Jan 27, 2022

Description
The Facebook provider throws Undefined array key "host" when the cpTrigger is not set (when Craft is in headless mode).

Caused by this line in SocialPosterHelper.php:25

$redirectUri = str_replace(Craft::$app->getConfig()->getGeneral()->cpTrigger . '/', '', $redirectUri);

https://github.com/verbb/social-poster/blob/craft-3/src/helpers/SocialPosterHelper.php#L25

@engram-design
Copy link
Member

So this helper function is really only there to generate the redirect URI for OAuth. I'm not sure why the headless config setting has any issue here, as you still need to access the control panel for Craft.

When are you seeing this error exactly?

@Tam
Copy link
Author

Tam commented Jan 28, 2022

@engram-design It's when we try to access the providers index

@engram-design
Copy link
Member

engram-design commented Jan 28, 2022

Strange, I've got headlessMode => true enabled on my install. Are you able to send through the full error with devMode on?

And just to verify headlessMode was working, my front-end is offline (in a traditional Twig setup).

Are you setting baseCpUrl in your config?

@Tam
Copy link
Author

Tam commented Jan 31, 2022

The issue seems to be caused by cpTrigger being set to null (since we're running craft headless on a sub-domain). This then causes the str_replace to see only the / and goes ahead and removes all slashes. This means the redirectUri goes from something like https://github.com/verbb/social-poster/issues/36 to https:github.comverbbsocial-posterissues36

@engram-design
Copy link
Member

Right, gotcha. Setting cpTrigger => null will do this, and not something I've ever seen before. I'll get a setup organised to test that (I get all sorts of errors trying to access the CP with this set to null)

@Tam
Copy link
Author

Tam commented Feb 1, 2022

We normally stick this at the top of our web/index.php if it helps!

if (
    $_SERVER['REQUEST_URI'] !== '/graph' &&
    strpos($_SERVER['REQUEST_URI'], '.xml') === false
) {
    define('CRAFT_CP', true);
}

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

2 participants