Skip to content

Commit

Permalink
Clean up clientflow code
Browse files Browse the repository at this point in the history
  • Loading branch information
tsdicloud committed Nov 21, 2023
1 parent 4150f62 commit ae1df93
Showing 1 changed file with 31 additions and 32 deletions.
63 changes: 31 additions & 32 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,12 @@ public function boot(IBootContext $context): void {
* This is the automatic redirect exclusively for Nextcloud/Magentacloud clients
* completely skipping consent layer
*/
private function registerNmcClientFlow(IRequest $request,
IURLGenerator $urlGenerator,
ProviderMapper $providerMapper,
ISession $session,
ISecureRandom $random): void {

$providers = $this->getCachedProviders($providerMapper);
private function registerNmcClientFlow(IRequest $request,
IURLGenerator $urlGenerator,
ProviderMapper $providerMapper,
ISession $session,
ISecureRandom $random): void {
$providers = $this->getCachedProviders($providerMapper);

// Handle immediate redirect on client first-time login
$isClientLoginFlow = false;
Expand All @@ -125,33 +124,33 @@ private function registerNmcClientFlow(IRequest $request,
return strtolower($p->getIdentifier()) === "telekom";
}));
if (count($tproviders) == 0) {
// always show normal login flow as error fallback
return;
}

$stateToken = $random->generate(
64,
ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_DIGITS
);
$session->set('client.flow.state.token', $stateToken);
// always show normal login flow as error fallback
return;
}

$stateToken = $random->generate(
64,
ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_DIGITS
);
$session->set('client.flow.state.token', $stateToken);

// call the service to get the params, but suppress the template
// compute grant redirect Url to go directly to Telekom login
$redirectUrl = $urlGenerator->linkToRoute('core.ClientFlowLogin.grantPage', [
'stateToken' => $stateToken,
// grantPage service operation is deriving oauth2 client name (again),
// so we simply pass on clientIdentifier or empty string
'clientIdentifier' => $request->getParam('clientIdentifier', ''),
'direct' => $request->getParam('direct', '0')
]);
if ($redirectUrl === null) {
// always show normal login flow as error fallback
return;
}

// direct login, consent layer later
// call the service to get the params, but suppress the template
// compute grant redirect Url to go directly to Telekom login
$redirectUrl = $urlGenerator->linkToRoute('core.ClientFlowLogin.grantPage', [
'stateToken' => $stateToken,
// grantPage service operation is deriving oauth2 client name (again),
// so we simply pass on clientIdentifier or empty string
'clientIdentifier' => $request->getParam('clientIdentifier', ''),
'direct' => $request->getParam('direct', '0')
]);
if ($redirectUrl === null) {
// always show normal login flow as error fallback
return;
}

// direct login, consent layer later
$targetUrl = $urlGenerator->linkToRoute(self::APP_ID . '.login.login', [
'providerId' => $tproviders[0]->getId(),
'providerId' => $tproviders[0]->getId(),
'redirectUrl' => $redirectUrl
]);
header('Location: ' . $targetUrl);
Expand Down

0 comments on commit ae1df93

Please sign in to comment.