Skip to content

Commit

Permalink
Merge pull request #14 from privacyidea/11-update-use-fetch-api-by-po…
Browse files Browse the repository at this point in the history
…lling-in-browser

11 update use fetch api by polling in browser
  • Loading branch information
nilsbehlen authored Oct 2, 2024
2 parents fa3bf02 + 8e112dc commit 951a08e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 52 deletions.
51 changes: 19 additions & 32 deletions js/pollTransaction.worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,49 +18,36 @@ self.addEventListener('message', function (e)
{
setInterval(function ()
{
const request = new XMLHttpRequest();

request.open("GET", url + "?" + params, false);

request.onload = (e) =>
{
try
fetch(url + "?" + params, {method: 'GET'})
.then(r =>
{
if (request.readyState === 4)
if (r.ok)
{
if (request.status === 200)
r.text().then(result =>
{
const response = JSON.parse(request.response);
if (response['result']['authentication'] === "ACCEPT")
const resultJson = JSON.parse(result);
if (resultJson['result']['authentication'] === "ACCEPT")
{
self.postMessage({
'message': 'Polling in browser: Push message confirmed!',
'status': 'success'
});
self.close();
}
}
else
{
self.postMessage({'message': request.statusText, 'status': 'error'});
self.close();
}
});
}
}
catch (e)
{
self.postMessage({'message': e, 'status': 'error'});
self.close();
}
};

request.onerror = (e) =>
{
self.postMessage({'message': request.statusText, 'status': 'error'});
self.close();
};

request.send();
else
{
self.postMessage({'message': r.statusText, 'status': 'error'});
self.close();
}
})
.catch(e =>
{
self.postMessage({'message': e, 'status': 'error'});
self.close();
}
);
}, 300);
}
break;
Expand Down
37 changes: 20 additions & 17 deletions lib/Provider/PrivacyIDEAProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,31 +91,34 @@ public function getTemplate(IUser $user): Template

if ($authenticationFlow === "piAuthFlowTriggerChallenge")
{
if (!$this->pi->serviceAccountAvailable())
if (!empty($this->pi))
{
$this->log("error", "Service account name or password is not set in config. Cannot trigger the challenges.");
}
else
{
if ($this->session->get("piTriggerChallengeDone") !== true)
if (!$this->pi->serviceAccountAvailable())
{
try
$this->log("error", "Service account name or password is not set in config. Cannot trigger the challenges.");
}
else
{
if ($this->session->get("piTriggerChallengeDone") !== true)
{
$response = $this->pi->triggerChallenge($username, $headers);
$this->session->set("piTriggerChallengeDone", true);
if ($response !== null)
try
{
$this->processPIResponse($response);
$response = $this->pi->triggerChallenge($username, $headers);
$this->session->set("piTriggerChallengeDone", true);
if ($response !== null)
{
$this->processPIResponse($response);
}
else
{
$this->log("error", "No response from privacyIDEA server for triggerchallenge.");
}
}
else
catch (PIBadRequestException $e)
{
$this->log("error", "No response from privacyIDEA server for triggerchallenge.");
$this->handlePIException($e);
}
}
catch (PIBadRequestException $e)
{
$this->handlePIException($e);
}
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
"extends @nextcloud/browserslist-config"
],
"dependencies": {
"@nextcloud/router": "^3.0.1",
"@nextcloud/vue": "^8.11.2",
"vue": "^2.7.16"
"@nextcloud/router": "^3.0.1"
},
"devDependencies": {
"@nextcloud/browserslist-config": "^3.0.1",
Expand Down

0 comments on commit 951a08e

Please sign in to comment.