Skip to content

Commit

Permalink
Make edusign_endpoint configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
mickenordin committed Aug 6, 2024
1 parent ec702a7 commit 2afa4d1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 14 deletions.
25 changes: 15 additions & 10 deletions edusign/lib/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class ApiController extends Controller
private LoggerInterface $logger;
private IRootFolder $rootFolder;
private IURLGenerator $urlGenerator;
private string $edusignEndpoint;
private IAppConfig $config;
private IUserManager $userManager;

Expand All @@ -44,7 +43,6 @@ public function __construct(
$this->appName = $appName;
$this->client = new Client();
$this->config = $config;
$this->edusignEndpoint = "https://dev.edusign.sunet.se/api/v1";
$this->logger = $logger;
$this->rootFolder = $rootFolder;
$this->urlGenerator = $urlGenerator;
Expand Down Expand Up @@ -79,6 +77,7 @@ private function getPersonalData(string $uid, string $return_url): array
$display_name = $user->getDisplayName($uid);
$mail = $user->getEMailAddress();
$personal_data = (array) $this->query()->getData();
unset($personal_data["edusign_endpoint"]);
$personal_data["eppn"] = $uid;
$personal_data["display_name"] = $display_name;
$personal_data["mail"] = array($mail);
Expand All @@ -90,16 +89,18 @@ private function getPersonalData(string $uid, string $return_url): array

/**
* @NoCSRFRequired
* @NoAdminRequired
*
* @return DataResponse
**/
public function query(): DataResponse
{
$response = array(
"idp" => $this->getAppValue("idp"),
"assurance" => array($this->getAppValue("assurance")),
"authn_context" => $this->getAppValue("authn_context"),
"edusign_endpoint" => $this->getAppValue('edusign_endpoint'),
"idp" => $this->getAppValue("idp"),
"organization" => $this->getAppValue("organization"),
"assurance" => array($this->getAppValue("assurance")),
"registration_authority" => $this->getAppValue("registration_authority"),
"saml_attr_schema" => $this->getAppValue("saml_attr_schema"),
);
Expand All @@ -113,18 +114,21 @@ public function query(): DataResponse
public function register(): DataResponse
{
$params = $this->request->getParams();
$idp = $params['idp'];
$assurance = $params['assurance'];
$authn_context = $params['authn_context'];
$edusign_endpoint = $params['edusign_endpoint'];
$idp = $params['idp'];
$organization = $params['organization'];
$assurance = $params['assurance'];
$registration_authority = $params['registration_authority'];
$saml_attr_schema = $params['saml_attr_schema'];
$this->setAppValue("idp", $idp);
$this->setAppValue("assurance", $assurance);
$this->setAppValue("authn_context", $authn_context);
$this->setAppValue("edusign_endpoint", $edusign_endpoint);
$this->setAppValue("idp", $idp);
$this->setAppValue("organization", $organization);
$this->setAppValue("assurance", $assurance);
$this->setAppValue("registration_authority", $registration_authority);
$this->setAppValue("saml_attr_schema", $saml_attr_schema);

$response = array("status" => "success");
return new DataResponse($response);
}
Expand All @@ -137,6 +141,7 @@ public function remove(): DataResponse
{
$this->deleteAppValue("idp");
$this->deleteAppValue("authn_context");
$this->deleteAppValue("edusign_endpoint");
$this->deleteAppValue("organization");
$this->deleteAppValue("assurance");
$this->deleteAppValue("registration_authority");
Expand Down Expand Up @@ -186,7 +191,7 @@ public function request(): JSONResponse
return new JSONResponse(json_encode($error_response));
}

$edusign_endpoint = $this->edusignEndpoint . "/create-sign-request";
$edusign_endpoint = $this->getAppValue('edusign_endpoint') . "/create-sign-request";
$uuid = $this->generate_uuid();
$this->setAppValue('eduid-path-' . $uuid, $path);
$this->setAppValue('eduid-redirect-uri-' . $uuid, $redirect_uri);
Expand Down Expand Up @@ -250,7 +255,7 @@ public function request(): JSONResponse
**/
public function response(): RedirectResponse
{
$edusign_endpoint = $this->edusignEndpoint . "/get-signed";
$edusign_endpoint = $this->getAppValue('edusign_endpoint') . "/get-signed";
$params = $this->request->getParams();
$relay_state = $params['RelayState'];
$sign_response = $params['EidSignResponse'];
Expand Down
13 changes: 11 additions & 2 deletions edusign/src/components/AdminSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
<NcSettingsSection name="eduSign" description="eduSign signature engine."
doc-url="https://github.com/SUNET/nextcloud-edusign" @default="populate">
<div class="external-label">
<label for="IDP">IDP</label>
<NcTextField id="IDP" :value.sync="idp" :label-outside="true" placeholder="IDP" @update:value="check" />
<label for="EdusignEndpoint">eduSign Endpoint</label>
<NcTextField id="EdusignEndpoint" :value.sync="edusign_endpoint" :label-outside="true" placeholder="eduSign Endpoint" @update:value="check" />
</div>
<div class="external-label">
<label for="IdP">IdP</label>
<NcTextField id="IdP" :value.sync="idp" :label-outside="true" placeholder="IdP (entity id)" @update:value="check" />
</div>
<div class="external-label">
<label for="AuthnContext">Authn Context</label>
Expand Down Expand Up @@ -95,6 +99,7 @@ export default {
return {
idp: "",
authn_context: "",
edusign_endpoint: "",
organization: "",
assurance: "",
registration_authority: "",
Expand All @@ -106,6 +111,7 @@ export default {
axios.get(url).then((result) => {
this.idp = result.data.idp || "";
this.authn_context = result.data.authn_context || "";
this.edusign_endpoint = result.data.edusign_endpoint || "";
this.organization = result.data.organization || "";
this.assurance = result.data.assurance[0] || "";
this.registration_authority = result.data.registration_authority || "";
Expand All @@ -119,6 +125,7 @@ export default {
if (
this.idp != "" &&
this.authn_context != "" &&
this.edusign_endpoint != "" &&
this.organization != "" &&
this.assurance != "" &&
this.registration_authority != "" &&
Expand All @@ -136,6 +143,7 @@ export default {
if (res.data.status == "success") {
this.idp = "";
this.authn_context = "";
this.edusign_endpoint = "";
this.organization = "";
this.assurance = "";
this.registration_authority = "";
Expand All @@ -147,6 +155,7 @@ export default {
var payload = {
'idp': this.idp,
'authn_context': this.authn_context,
'edusign_endpoint': this.edusign_endpoint,
'organization': this.organization,
'assurance': this.assurance,
'registration_authority': this.registration_authority,
Expand Down
6 changes: 4 additions & 2 deletions edusign/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ const requestSignatureAction = new FileAction({
if (!OCA.Edusign.configured) {
const url = generateUrl('/index.php/apps/edusign/query');
axios.get(url).then(result => {
OCA.Edusign.configured = result.data.idp != ""
OCA.Edusign.configured =
result.data.assurance != ""
&& result.data.authn_context != ""
&& result.data.edusign_endpoint != ""
&& result.data.idp != ""
&& result.data.organization != ""
&& result.data.assurance != ""
&& result.data.registration_authority != ""
&& result.data.saml_attr_schema != "";
});
Expand Down

0 comments on commit 2afa4d1

Please sign in to comment.