Signed-off-by: Vincent Petry <vincent@nextcloud.com> Co-Authored-by: Carl Schwan <carl@carlschwan.eu>tags/v24.0.0beta2
* @PublicPage | * @PublicPage | ||||
* @NoCSRFRequired | * @NoCSRFRequired | ||||
* @UseSession | * @UseSession | ||||
* | |||||
* @param string $clientIdentifier | |||||
* | |||||
* @return StandaloneTemplateResponse | |||||
*/ | */ | ||||
public function showAuthPickerPage($clientIdentifier = '', $user = '') { | |||||
public function showAuthPickerPage(string $clientIdentifier = '', string $user = '', int $direct = 0): StandaloneTemplateResponse { | |||||
$clientName = $this->getClientName(); | $clientName = $this->getClientName(); | ||||
$client = null; | $client = null; | ||||
if ($clientIdentifier !== '') { | if ($clientIdentifier !== '') { | ||||
'serverHost' => $this->getServerPath(), | 'serverHost' => $this->getServerPath(), | ||||
'oauthState' => $this->session->get('oauth.state'), | 'oauthState' => $this->session->get('oauth.state'), | ||||
'user' => $user, | 'user' => $user, | ||||
'direct' => $direct, | |||||
], | ], | ||||
'guest' | 'guest' | ||||
); | ); | ||||
* @NoCSRFRequired | * @NoCSRFRequired | ||||
* @NoSameSiteCookieRequired | * @NoSameSiteCookieRequired | ||||
* @UseSession | * @UseSession | ||||
* | |||||
* @param string $stateToken | |||||
* @param string $clientIdentifier | |||||
* @return StandaloneTemplateResponse | |||||
*/ | */ | ||||
public function grantPage($stateToken = '', | |||||
$clientIdentifier = '') { | |||||
public function grantPage(string $stateToken = '', | |||||
string $clientIdentifier = '', | |||||
int $direct = 0): StandaloneTemplateResponse { | |||||
if (!$this->isValidToken($stateToken)) { | if (!$this->isValidToken($stateToken)) { | ||||
return $this->stateTokenForbiddenResponse(); | return $this->stateTokenForbiddenResponse(); | ||||
} | } | ||||
'stateToken' => $stateToken, | 'stateToken' => $stateToken, | ||||
'serverHost' => $this->getServerPath(), | 'serverHost' => $this->getServerPath(), | ||||
'oauthState' => $this->session->get('oauth.state'), | 'oauthState' => $this->session->get('oauth.state'), | ||||
'direct' => $direct, | |||||
], | ], | ||||
'guest' | 'guest' | ||||
); | ); |
<br/> | <br/> | ||||
<p id="redirect-link"> | <p id="redirect-link"> | ||||
<a href="<?php p($urlGenerator->linkToRoute('core.ClientFlowLogin.grantPage', ['stateToken' => $_['stateToken'], 'clientIdentifier' => $_['clientIdentifier'], 'oauthState' => $_['oauthState'], 'user' => $_['user']])) ?>"> | |||||
<a href="<?php p($urlGenerator->linkToRoute('core.ClientFlowLogin.grantPage', ['stateToken' => $_['stateToken'], 'clientIdentifier' => $_['clientIdentifier'], 'oauthState' => $_['oauthState'], 'user' => $_['user'], 'direct' => $_['direct']])) ?>"> | |||||
<input type="submit" class="login primary icon-confirm-white" value="<?php p($l->t('Log in')) ?>"> | <input type="submit" class="login primary icon-confirm-white" value="<?php p($l->t('Log in')) ?>"> | ||||
</a> | </a> | ||||
</p> | </p> | ||||
</p> | </p> | ||||
<input type="hidden" name="stateToken" value="<?php p($_['stateToken']) ?>" /> | <input type="hidden" name="stateToken" value="<?php p($_['stateToken']) ?>" /> | ||||
<input type="hidden" name="requesttoken" value="<?php p($_['requesttoken']) ?>"> | <input type="hidden" name="requesttoken" value="<?php p($_['requesttoken']) ?>"> | ||||
<?php if ($_['direct'] !== 0) { ?> | |||||
<input type="hidden" name="direct" value="<?php p($_['direct']) ?>"> | |||||
<?php } ?> | |||||
<input id="submit-app-token-login" type="submit" class="login primary icon-confirm-white" value="<?php p($l->t('Grant access')) ?>"> | <input id="submit-app-token-login" type="submit" class="login primary icon-confirm-white" value="<?php p($l->t('Grant access')) ?>"> | ||||
</form> | </form> | ||||
<br/> | <br/> | ||||
<p id="redirect-link"> | <p id="redirect-link"> | ||||
<form method="POST" action="<?php p($urlGenerator->linkToRouteAbsolute('core.ClientFlowLogin.generateAppPassword')) ?>"> | |||||
<input type="hidden" name="clientIdentifier" value="<?php p($_['clientIdentifier']) ?>" /> | |||||
<input type="hidden" name="requesttoken" value="<?php p($_['requesttoken']) ?>" /> | |||||
<input type="hidden" name="stateToken" value="<?php p($_['stateToken']) ?>" /> | |||||
<input type="hidden" name="oauthState" value="<?php p($_['oauthState']) ?>" /> | |||||
<form method="POST" action="<?php p($urlGenerator->linkToRouteAbsolute('core.ClientFlowLogin.generateAppPassword')) ?>"> | |||||
<input type="hidden" name="clientIdentifier" value="<?php p($_['clientIdentifier']) ?>" /> | |||||
<input type="hidden" name="requesttoken" value="<?php p($_['requesttoken']) ?>" /> | |||||
<input type="hidden" name="stateToken" value="<?php p($_['stateToken']) ?>" /> | |||||
<input type="hidden" name="oauthState" value="<?php p($_['oauthState']) ?>" /> | |||||
<?php if (p($_['direct'])) { ?> | |||||
<input type="hidden" name="direct" value="1" /> | |||||
<?php } ?> | |||||
<div id="submit-wrapper"> | <div id="submit-wrapper"> | ||||
<input type="submit" class="login primary icon-confirm-white" title="" value="<?php p($l->t('Grant access')); ?>" /> | <input type="submit" class="login primary icon-confirm-white" title="" value="<?php p($l->t('Grant access')); ?>" /> | ||||
</div> | |||||
</div> | |||||
</form> | </form> | ||||
</p> | </p> | ||||
</div> | </div> |
if ($usernamePrefill !== '') { | if ($usernamePrefill !== '') { | ||||
$params['user'] = $usernamePrefill; | $params['user'] = $usernamePrefill; | ||||
} | } | ||||
if ($this->request->getParam('direct')) { | |||||
$params['direct'] = 1; | |||||
} | |||||
$url = $this->urlGenerator->linkToRoute('core.login.showLoginForm', $params); | $url = $this->urlGenerator->linkToRoute('core.login.showLoginForm', $params); | ||||
$response = new RedirectResponse($url); | $response = new RedirectResponse($url); | ||||
} else { | } else { |
'serverHost' => 'https://example.com', | 'serverHost' => 'https://example.com', | ||||
'oauthState' => 'OauthStateToken', | 'oauthState' => 'OauthStateToken', | ||||
'user' => '', | 'user' => '', | ||||
'direct' => 0 | |||||
], | ], | ||||
'guest' | 'guest' | ||||
); | ); | ||||
'serverHost' => 'https://example.com', | 'serverHost' => 'https://example.com', | ||||
'oauthState' => 'OauthStateToken', | 'oauthState' => 'OauthStateToken', | ||||
'user' => '', | 'user' => '', | ||||
'direct' => 0 | |||||
], | ], | ||||
'guest' | 'guest' | ||||
); | ); |