Skip to content

Commit

Permalink
Merge pull request #714 from nextcloud/enh/noid/extract-idp-from-jwt
Browse files Browse the repository at this point in the history
extract idp from jwt in globalscale
  • Loading branch information
blizzz authored May 22, 2023
2 parents 52dc06d + c7fc204 commit 109ef78
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions lib/Controller/SAMLController.php
Original file line number Diff line number Diff line change
Expand Up @@ -446,23 +446,30 @@ public function singleLogoutService() {
}

$isFromIDP = !$isFromGS && !empty($_GET['SAMLRequest']);

$idp = null;
if ($isFromIDP) {
// requests comes from the IDP so let it manage the logout
// (or raise Error if request is invalid)
$pass = true ;
} elseif ($isFromGS) {
// Request is from master GlobalScale
// Request validity is check via a JSON Web Token
$jwt = $this->request->getParam('jwt', '');
$pass = $this->isValidJwt($jwt);

try {
$key = $this->config->getSystemValue('gss.jwt.key', '');
$decoded = (array)JWT::decode($jwt, new Key($key, 'HS256'));

$idp = $decoded['idp'] ?? null;
$pass = true;
} catch (\Exception $e) {
}
} else {
// standard request : need read CRSF check
$pass = $this->request->passesCSRFCheck();
}

if ($pass) {
$idp = $this->session->get('user_saml.Idp');
$idp = ($idp !== null) ? (int)$idp : $this->session->get('user_saml.Idp');
$stay = true; // $auth will return the redirect URL but won't perform the redirect himself
if ($isFromIDP) {
[$targetUrl, $auth] = $this->tryProcessSLOResponse($idp);
Expand Down Expand Up @@ -665,18 +672,6 @@ private function getDirectLoginUrl($redirectUrl) {
return $directUrl;
}


private function isValidJwt($jwt): bool {
try {
$key = $this->config->getSystemValue('gss.jwt.key', '');
JWT::decode($jwt, new Key($key, 'HS256'));
} catch (\Exception $e) {
return false;
}

return true;
}

/**
* @PublicPage
* @NoCSRFRequired
Expand Down

0 comments on commit 109ef78

Please sign in to comment.