Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

11 update use fetch api by polling in browser #14

Merged
merged 4 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading