Skip to content

Commit

Permalink
Add support for headlessMode redirect URIs
Browse files Browse the repository at this point in the history
  • Loading branch information
engram-design committed Apr 28, 2024
1 parent a89fc38 commit f2063a2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/Consume.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ private function _registerCpRoutes(): void
$event->rules['consume/clients/oauth/new'] = 'consume/clients/edit-oauth';
$event->rules['consume/clients/oauth/<handle:{handle}>'] = 'consume/clients/edit-oauth';
$event->rules['consume/settings'] = 'consume/plugin/settings';

if (Craft::$app->getConfig()->getGeneral()->headlessMode || !Craft::$app->getConfig()->getGeneral()->cpTrigger) {
$event->rules['consume/auth/callback'] = 'consume/auth/callback';
}
});
}

Expand Down
7 changes: 3 additions & 4 deletions src/base/OAuthClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,13 @@ public function isConnected(): bool

public function getRedirectUri(): ?string
{
$siteId = Craft::$app->getSites()->getCurrentSite()->id ?? Craft::$app->getSites()->getPrimarySite()->id;

// Check for Headless Mode and use the Action URL, or when `cpTrigger` is empty to signify split front/back-end
if (Craft::$app->getConfig()->getGeneral()->headlessMode || !Craft::$app->getConfig()->getGeneral()->cpTrigger) {
return UrlHelper::actionUrl('consume/auth/callback');
return UrlHelper::cpUrl('consume/auth/callback', null, null, $siteId);
}

$siteId = Craft::$app->getSites()->getPrimarySite()->id;

// We should always use the primary site for the redirect
return UrlHelper::siteUrl('consume/auth/callback', null, null, $siteId);
}

Expand Down

0 comments on commit f2063a2

Please sign in to comment.