diff --git a/.github/workflows/pull-request-from-branch-check.yaml b/.github/workflows/pull-request-from-branch-check.yaml index 77d1970..401de61 100644 --- a/.github/workflows/pull-request-from-branch-check.yaml +++ b/.github/workflows/pull-request-from-branch-check.yaml @@ -1,18 +1,18 @@ name: Main Branch Protection -on: - pull_request: - branches: - - main +#on: +# pull_request: +# branches: +# - main -jobs: - check-branch: - runs-on: ubuntu-latest - steps: - - name: Check branch - run: | - if [[ ${GITHUB_HEAD_REF} != development ]] && [[ ${GITHUB_HEAD_REF} != documentation ]] && ! [[ ${GITHUB_HEAD_REF} =~ ^hotfix/ ]]; - then - echo "Error: Pull request must come from 'development', 'documentation' or 'hotfix/' branch" - exit 1 - fi +#jobs: +# check-branch: +# runs-on: ubuntu-latest +# steps: +# - name: Check branch +# run: | +# if [[ ${GITHUB_HEAD_REF} != development ]] && [[ ${GITHUB_HEAD_REF} != documentation ]] && ! [[ ${GITHUB_HEAD_REF} =~ ^hotfix/ ]]; +# then +# echo "Error: Pull request must come from 'development', 'documentation' or 'hotfix/' branch" +# exit 1 +# fi diff --git a/appinfo/info.xml b/appinfo/info.xml index e1dcf26..768b23e 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -13,7 +13,7 @@ The OpenConnector Nextcloud app provides a ESB-framework to work together in an - 🆓 Map and translate API calls ]]> - 0.1.16 + 0.1.20 agpl integration Conduction diff --git a/configurations/sharepoint-woo/mappings/sharepoint-woo-verzoek-to-publications.json b/configurations/sharepoint-woo/mappings/sharepoint-woo-verzoek-to-publications.json index b678dea..a6cdbad 100644 --- a/configurations/sharepoint-woo/mappings/sharepoint-woo-verzoek-to-publications.json +++ b/configurations/sharepoint-woo/mappings/sharepoint-woo-verzoek-to-publications.json @@ -3,9 +3,28 @@ "description": "", "version": "0.0.1", "mapping": { - "title": "Name" - }, - "unset": [], - "cast": [], + "title": "d.woo_x005f_titel", + "description": "d.woo_x005f_beschrijving", + "summary": "d.woo_x005f_samenvatting", + "category": "d.woo_x005f_categorie", + "published": "{% if d['woo_x005f_publicatiedatum']|default %}{{ d['woo_x005f_publicatiedatum']|date('Y-m-d') }}{% endif %}", + "modified": "d.vti_x005f_nexttolasttimemodified", + "attachments": "[ {% for file in fileUrls %} { {% if file['Name']|default %}\"title\": \"{{ file['Name'] }}\",{% endif %}{% if file['d']['document_x005f_label']|default %}\"labels\": [\"{{ file['d']['document_x005f_label'] }}\"],{% endif %}{% if file['__metadata']['uri']|default %}\"downloadUrl\": {\"accessUrl\": \"{{ file['__metadata']['uri']~'/$value' }}\", \"source\": \"1\"}{% endif %} }{{ loop.last ? '' : ',' }} {% endfor %} ]", + "status": "Concept", + "catalog": "", + "publicationType": "" + }, + "unset": [], + "cast": { + "title": "unsetIfValue==d.woo_x005f_titel", + "description": "unsetIfValue==d.woo_x005f_beschrijving", + "summary": "unsetIfValue==d.woo_x005f_samenvatting", + "category": "unsetIfValue==d.woo_x005f_categorie", + "published": "unsetIfValue==", + "modified": "unsetIfValue==d.vti_x005f_nexttolasttimemodified", + "attachments": "jsonToArray", + "publicationType": "unsetIfValue==", + "catalog": "unsetIfValue==" + }, "passThrough": false -} \ No newline at end of file +} diff --git a/configurations/sharepoint-woo/mappings/xxllnc-suite-to-publications.json b/configurations/sharepoint-woo/mappings/xxllnc-suite-to-publications.json index 17e38a8..744823b 100644 --- a/configurations/sharepoint-woo/mappings/xxllnc-suite-to-publications.json +++ b/configurations/sharepoint-woo/mappings/xxllnc-suite-to-publications.json @@ -1,14 +1,26 @@ { "name": "Xxllnc suite to Publication", - "description": "", - "version": "", - "reference": "", + "version": "0.0.1", "mapping": { - "title": "omschrijving", - "summary": "statustoelichting", - "description": "statusomschrijving" - }, - "unset": [], - "cast": [], + "title": "omschrijving", + "summary": "zaaktypeomschrijving", + "description": "zaaktypeomschrijving", + "category": "{% if zaaktypecode|default %}{% set wooVerzoekenEnBesluiten = ['LP00000431', 'B1873', 'cherry'] %}{% set klachtoordelen = ['LP00000091', 'LP00001132', 'LP00000121', 'B0757', 'LP00000832', 'LP00001096'] %}{% if zaaktypecode in wooVerzoekenEnBesluiten %}{{ 'Woo-verzoeken en -besluiten' }}{% elseif zaaktypecode in klachtoordelen %}{{ 'Klachtoordelen' }}{% endif %}{% endif %}", + "published": "startdatum", + "modified": "{{ 'now'|date('H:i:sTm-d-Y') }}", + "attachments": "[{% if files|default %}{% for file in files %} { {% if file['titel']|default %}\"title\": \"{{ file['titel'] }}\",{% endif %}\"labels\": [\"{{ 'Informatieverzoek' }}\"],{% if file['formaat']|default %}\"extension\": \"{{ file['formaat']|split('/')|last }}\",\"type\": \"{{ file['formaat'] }}\",{% endif %}{% if file['inhoud']|default and file['formaat']|default %}\"accessUrl\": \"data:{{ file['formaat'] }};base64,{{ file.inhoud }}\"{% endif %} }{{ loop.last ? '' : ',' }} {% endfor %}{% endif %}]", + "status": "Concept" + }, + "unset": [ + "" + ], + "cast": { + "title": "unsetIfValue==omschrijving", + "summary": "unsetIfValue==zaaktypeomschrijving", + "description": "unsetIfValue==zaaktypeomschrijving", + "category": "unsetIfValue==", + "published": "unsetIfValue==startdatum", + "attachments": "jsonToArray" + }, "passThrough": false } \ No newline at end of file diff --git a/configurations/sharepoint-woo/synchronizations/sharepoint-convenanten-to-publications.json b/configurations/sharepoint-woo/synchronizations/sharepoint-convenanten-to-publications.json index e39deb8..539175c 100644 --- a/configurations/sharepoint-woo/synchronizations/sharepoint-convenanten-to-publications.json +++ b/configurations/sharepoint-woo/synchronizations/sharepoint-convenanten-to-publications.json @@ -7,12 +7,20 @@ "sourceHash": "", "sourceTargetMapping": "1", "sourceConfig": { - "idPosition": "UniqueId", - "resultsPosition": "d.results", - "endpoint": "/Web/GetFolderByServerRelativePath(decodedurl='/WOO/Convenanten')/folders", - "headers": [], - "query": [] - }, + "idPosition": "UniqueId", + "resultsPosition": "d.results", + "endpoint": "\/Web\/GetFolderByServerRelativePath(decodedurl='\/WOO\/Convenanten')\/folders", + "extraDataConfigs.0.dynamicEndpointLocation": "Properties.__deferred.uri", + "extraDataConfigs.0.mergeExtraData": "true", + "extraDataConfigs.1.dynamicEndpointLocation": "Files.__deferred.uri", + "extraDataConfigs.1.mergeExtraData": "true", + "extraDataConfigs.1.keyToSetExtraData": "fileUrls", + "extraDataConfigs.1.resultsLocation": "d.results", + "extraDataConfigs.1.extraDataConfigPerResult.dynamicEndpointLocation": "Properties.__deferred.uri", + "extraDataConfigs.1.extraDataConfigPerResult.mergeExtraData": "true", + "headers": [], + "query": [] + }, "targetId": "1/1", "targetType": "register/schema" } \ No newline at end of file diff --git a/configurations/sharepoint-woo/synchronizations/sharepoint-woo-verzoeken-to-publications.json b/configurations/sharepoint-woo/synchronizations/sharepoint-woo-verzoeken-to-publications.json index 7aa6512..88568b9 100644 --- a/configurations/sharepoint-woo/synchronizations/sharepoint-woo-verzoeken-to-publications.json +++ b/configurations/sharepoint-woo/synchronizations/sharepoint-woo-verzoeken-to-publications.json @@ -7,11 +7,19 @@ "sourceHash": "", "sourceTargetMapping": "1", "sourceConfig": { - "idPosition": "UniqueId", + "idPosition": "UniqueId", "resultsPosition": "d.results", "endpoint": "/Web/GetFolderByServerRelativePath(decodedurl='/WOO/Woo-verzoeken en -besluiten')/folders", - "headers": [], - "query": [] + "extraDataConfigs.0.dynamicEndpointLocation": "Properties.__deferred.uri", + "extraDataConfigs.0.mergeExtraData": "true", + "extraDataConfigs.1.dynamicEndpointLocation": "Files.__deferred.uri", + "extraDataConfigs.1.mergeExtraData": "true", + "extraDataConfigs.1.keyToSetExtraData": "fileUrls", + "extraDataConfigs.1.resultsLocation": "d.results", + "extraDataConfigs.1.extraDataConfigPerResult.dynamicEndpointLocation": "Properties.__deferred.uri", + "extraDataConfigs.1.extraDataConfigPerResult.mergeExtraData": "true", + "headers": [], + "query": [] }, "targetId": "1/1", "targetType": "register/schema" diff --git a/configurations/sharepoint-woo/synchronizations/xxllnc-suite-to-publications.json b/configurations/sharepoint-woo/synchronizations/xxllnc-suite-to-publications.json index 6dfedf8..91922ef 100644 --- a/configurations/sharepoint-woo/synchronizations/xxllnc-suite-to-publications.json +++ b/configurations/sharepoint-woo/synchronizations/xxllnc-suite-to-publications.json @@ -7,13 +7,19 @@ "sourceHash": "", "sourceTargetMapping": "1", "sourceConfig": { - "idPosition": "id", - "resultsPosition": "results", - "endpoint": "/tlb/zaaksysteem/api/v1/zaken", - "headers": [], - "query.startdatum__gte": "2024-07-06", - "query.einddatum__lt": "2024-08-01" - }, + "idPosition": "identificatie", + "resultsPosition": "results", + "endpoint": "\/tlb\/zaaksysteem\/api\/v1\/zaken", + "headers": [], + "query.startdatum__gte": "2024-08-01", + "query.einddatum__lt": "2025-01-01", + "usesPagination": "false", + "extraDataConfigs.0.staticEndpoint": "/tlb/zaaksysteem/api/v1/zaken/{{ originId }}/informatieobjecten", + "extraDataConfigs.0.mergeExtraData": "true", + "extraDataConfigs.0.keyToSetExtraData": "files", + "extraDataConfigs.0.resultsLocation": "results", + "extraDataConfigs.0.extraDataConfigPerResult.staticEndpoint": "/tlb/zaaksysteem/api/v1/informatieobjecten/{{ originId }}" + }, "targetId": "1/1", "targetType": "register/schema" } \ No newline at end of file diff --git a/lib/Cron/ActionTask.php b/lib/Cron/ActionTask.php index a5b3a54..471f186 100644 --- a/lib/Cron/ActionTask.php +++ b/lib/Cron/ActionTask.php @@ -8,6 +8,8 @@ use OCP\BackgroundJob\TimedJob; use OCP\AppFramework\Utility\ITimeFactory; use OCP\BackgroundJob\IJobList; +use OCP\IUserManager; +use OCP\IUserSession; use Psr\Container\ContainerInterface; use Symfony\Component\Uid\Uuid; use DateInterval; @@ -30,7 +32,9 @@ public function __construct( JobMapper $jobMapper, JobLogMapper $jobLogMapper, IJobList $jobList, - ContainerInterface $containerInterface + ContainerInterface $containerInterface, + private IUserSession $userSession, + private IUserManager $userManager, ) { parent::__construct($time); $this->jobMapper = $jobMapper; @@ -80,6 +84,11 @@ public function run($argument) return; } + if(empty($job->getUserId()) === false && $this->userSession->getUser() === null) { + $user = $this->userManager->get($job->getUserId()); + $this->userSession->setUser($user); + } + $time_start = microtime(true); $action = $this->containerInterface->get($job->getJobClass()); @@ -127,6 +136,8 @@ public function run($argument) } } + $this->jobLogMapper->update(entity: $jobLog); + // Let's report back about what we have just done return $jobLog; } diff --git a/lib/Db/Synchronization.php b/lib/Db/Synchronization.php index 208bef2..473524b 100644 --- a/lib/Db/Synchronization.php +++ b/lib/Db/Synchronization.php @@ -65,6 +65,21 @@ public function __construct() { $this->addType(fieldName:'followUps', type: 'json'); } + /** + * Checks through sourceConfig if the source of this sync uses pagination + * + * @return bool true if its uses pagination + */ + public function usesPagination(): bool + { + if (isset($this->sourceConfig['usesPagination']) === true && ($this->sourceConfig['usesPagination'] === false || $this->sourceConfig['usesPagination'] === 'false')) { + return false; + } + + // By default sources use basic pagination. + return true; + } + public function getJsonFields(): array { return array_keys( diff --git a/lib/Migration/Version1Date20241111144800.php b/lib/Migration/Version1Date20241111144800.php index 9eb4651..10a6768 100644 --- a/lib/Migration/Version1Date20241111144800.php +++ b/lib/Migration/Version1Date20241111144800.php @@ -101,7 +101,7 @@ public function postSchemaChange(IOutput $output, Closure $schemaClosure, array && $table->hasColumn('source_id') === true && $table->hasColumn('source_hash') === true ) { $this->connection->executeQuery(" - UPDATE openconnector_synchronization_contracts + UPDATE oc_openconnector_synchronization_contracts SET origin_id = source_id, origin_hash = source_hash WHERE source_id IS NOT NULL "); diff --git a/lib/Service/AuthenticationService.php b/lib/Service/AuthenticationService.php index b59e41b..f604874 100644 --- a/lib/Service/AuthenticationService.php +++ b/lib/Service/AuthenticationService.php @@ -192,6 +192,35 @@ public function fetchOAuthTokens (array $configuration): string return $result['access_token']; } + /** + * Fetch an access token from the DeCOS non-implementation of OAuth 2.0 + * + * @param array $configuration The configuration of the source. + * + * @return string The access token + * + * @throws \GuzzleHttp\Exception\GuzzleException + */ + public function fetchDecosToken(array $configuration): string + { + $url = $configuration['tokenUrl']; + $tokenLocation = $configuration['tokenLocation']; + unset($configuration['tokenUrl']); + + $callConfig['json'] = $configuration; + + $client = new Client(); + $response = $client->post(uri: $url, options: $callConfig); + + $result = json_decode(json: $response->getBody()->getContents(), associative: true); + + if (isset($tokenLocation) === true) { + return $result[$tokenLocation]; + } + + return $result['token']; + } + /** * Get RSA key for RS and PS (asymmetrical) encryption. * @@ -201,7 +230,7 @@ public function fetchOAuthTokens (array $configuration): string private function getRSJWK(array $configuration): ?JWK { $stamp = microtime().getmypid(); - $filename = "privatekey-$stamp"; + $filename = "/var/tmp/privatekey-$stamp"; file_put_contents($filename, base64_decode($configuration['secret'])); $jwk = null; try { diff --git a/lib/Service/CallService.php b/lib/Service/CallService.php index b86d184..e40bc95 100644 --- a/lib/Service/CallService.php +++ b/lib/Service/CallService.php @@ -249,6 +249,8 @@ public function call( $time_end = microtime(true); + $body = $response->getBody()->getContents(); + // Let create the data array $data = [ 'request' => [ @@ -263,7 +265,8 @@ public function call( 'size' => $response->getBody()->getSize(), 'remoteIp' => $response->getHeaderLine('X-Real-IP') ?: $response->getHeaderLine('X-Forwarded-For') ?: null, 'headers' => $response->getHeaders(), - 'body' => $response->getBody()->getContents(), + 'body' => mb_check_encoding(value: $body, encoding: 'UTF-8') !== false ? $body : base64_encode($body), + 'encoding' => mb_check_encoding(value: $body, encoding: 'UTF-8') !== false ? 'UTF-8' : 'base64', ] ]; diff --git a/lib/Service/SynchronizationService.php b/lib/Service/SynchronizationService.php index 8f88250..3f51acc 100644 --- a/lib/Service/SynchronizationService.php +++ b/lib/Service/SynchronizationService.php @@ -47,6 +47,12 @@ class SynchronizationService private ObjectService $objectService; private Source $source; + const EXTRA_DATA_CONFIGS_LOCATION = 'extraDataConfigs'; + const EXTRA_DATA_DYNAMIC_ENDPOINT_LOCATION = 'dynamicEndpointLocation'; + const EXTRA_DATA_STATIC_ENDPOINT_LOCATION = 'staticEndpoint'; + const KEY_FOR_EXTRA_DATA_LOCATION = 'keyToSetExtraData'; + const MERGE_EXTRA_DATA_OBJECT_LOCATION = 'mergeExtraData'; + public function __construct( CallService $callService, @@ -214,6 +220,81 @@ public function getObjectFromSource(Synchronization $synchronization, string $en return json_decode($response['body'], true); } + /** + * Fetches additional data for a given object based on the synchronization configuration. + * + * This method retrieves extra data using either a dynamically determined endpoint from the object + * or a statically defined endpoint in the configuration. The extra data can be merged with the original + * object or returned as-is, based on the provided configuration. + * + * @param Synchronization $synchronization The synchronization instance containing configuration details. + * @param array $extraDataConfig The configuration array specifying how to retrieve and handle the extra data: + * - EXTRA_DATA_DYNAMIC_ENDPOINT_LOCATION: The key to retrieve the dynamic endpoint from the object. + * - EXTRA_DATA_STATIC_ENDPOINT_LOCATION: The statically defined endpoint. + * - KEY_FOR_EXTRA_DATA_LOCATION: The key under which the extra data should be returned. + * - MERGE_EXTRA_DATA_OBJECT_LOCATION: Boolean flag indicating whether to merge the extra data with the object. + * @param array $object The original object for which extra data needs to be fetched. + * + * @return array The original object merged with the extra data, or the extra data itself based on the configuration. + * + * @throws Exception If both dynamic and static endpoint configurations are missing or the endpoint cannot be determined. + */ + private function fetchExtraDataForObject(Synchronization $synchronization, array $extraDataConfig, array $object) + { + if (isset($extraDataConfig[$this::EXTRA_DATA_DYNAMIC_ENDPOINT_LOCATION]) === false && isset($extraDataConfig[$this::EXTRA_DATA_STATIC_ENDPOINT_LOCATION]) === false) { + return $object; + } + + // Get endpoint from earlier fetched object. + if (isset($extraDataConfig[$this::EXTRA_DATA_DYNAMIC_ENDPOINT_LOCATION]) === true) { + $dotObject = new Dot($object); + $endpoint = $dotObject->get($extraDataConfig[$this::EXTRA_DATA_DYNAMIC_ENDPOINT_LOCATION] ?? null); + } + + // Get endpoint static defined in config. + if (isset($extraDataConfig[$this::EXTRA_DATA_STATIC_ENDPOINT_LOCATION]) === true) { + $endpoint = $extraDataConfig[$this::EXTRA_DATA_STATIC_ENDPOINT_LOCATION]; + $endpoint = str_replace(search: '{{ originId }}', replace: $this->getOriginId($synchronization, $object), subject: $endpoint); + $endpoint = str_replace(search: '{{originId}}', replace: $this->getOriginId($synchronization, $object), subject: $endpoint); + } + + if (!$endpoint) { + throw new Exception( + sprintf( + 'Could not get static or dynamic endpoint, object: %s', + json_encode($object) + ) + ); + } + + $extraData = $this->getObjectFromSource($synchronization, $endpoint); + + // Temporary fix, + if (isset($extraDataConfig['extraDataConfigPerResult']) === true) { + $dotObject = new Dot($extraData); + $results = $dotObject->get($extraDataConfig['resultsLocation']); + + foreach ($results as $key => $result) { + $results[$key] = $this->fetchExtraDataForObject($synchronization, $extraDataConfig['extraDataConfigPerResult'], $result); + } + + $extraData = $results; + } + + // Set new key if configured. + if (isset($extraDataConfig[$this::KEY_FOR_EXTRA_DATA_LOCATION]) === true) { + $extraData = [$extraDataConfig[$this::KEY_FOR_EXTRA_DATA_LOCATION] => $extraData]; + } + + // Merge with earlier fetchde object if configured. + if (isset($extraDataConfig[$this::MERGE_EXTRA_DATA_OBJECT_LOCATION]) === true && ($extraDataConfig[$this::MERGE_EXTRA_DATA_OBJECT_LOCATION] === true || $extraDataConfig[$this::MERGE_EXTRA_DATA_OBJECT_LOCATION] === 'true')) { + return array_merge($object, $extraData); + } + + return $extraData; + } + + /** * Synchronize a contract * @@ -230,32 +311,34 @@ public function getObjectFromSource(Synchronization $synchronization, string $en */ public function synchronizeContract(SynchronizationContract $synchronizationContract, Synchronization $synchronization = null, array $object = [], ?bool $isTest = false): SynchronizationContract|Exception|array { + $sourceConfig = $this->callService->applyConfigDot($synchronization->getSourceConfig()); - if ($synchronization !== null && isset($synchronization->getSourceConfig()['singleEndpoint']) === true) { - - // Update endpoint - $endpoint = str_replace(search: '{{ originId }}', replace: $this->getOriginId($synchronization, $object), subject: $synchronization->getSourceConfig()['singleEndpoint']); - $endpoint = str_replace(search: '{{originId}}', replace: $this->getOriginId($synchronization, $object), subject: $endpoint); - - // Get object from source - $object = $this->getObjectFromSource(synchronization: $synchronization, endpoint: $endpoint); + // Check if extra data needs to be fetched + if (isset($sourceConfig[$this::EXTRA_DATA_CONFIGS_LOCATION]) === true) { + foreach ($sourceConfig[$this::EXTRA_DATA_CONFIGS_LOCATION] as $extraDataConfig) { + $object = array_merge($object, $this->fetchExtraDataForObject($synchronization, $extraDataConfig, $object)); + } + } + // @TODO: This should be unset through pre-mapping + if(isset($object['d']['vti_x005f_dirlateststamp']) === true) { + unset($object['d']['vti_x005f_dirlateststamp']); } // Let create a source hash for the object $originHash = md5(serialize($object)); - $synchronizationContract->setSourceLastChecked(new DateTime()); // Let's prevent pointless updates @todo account for omnidirectional sync, unless the config has been updated since last check then we do want to rebuild and check if the tagert object has changed if ($originHash === $synchronizationContract->getOriginHash() && $synchronization->getUpdated() < $synchronizationContract->getSourceLastChecked()) { // The object has not changed and the config has not been updated since last check return $synchronizationContract; } - + // The object has changed, oke let do mappig and bla die bla $synchronizationContract->setOriginHash($originHash); $synchronizationContract->setSourceLastChanged(new DateTime()); + $synchronizationContract->setSourceLastChecked(new DateTime()); // Check if object adheres to conditions. // Take note, JsonLogic::apply() returns a range of return types, so checking it with '=== false' or '!== true' does not work properly. @@ -281,7 +364,6 @@ public function synchronizeContract(SynchronizationContract $synchronizationCont } } - // set the target hash $targetHash = md5(serialize($targetObject)); $synchronizationContract->setTargetHash($targetHash); @@ -472,7 +554,7 @@ public function getAllObjectsFromApi(Synchronization $synchronization, ?bool $is $objects = array_merge($objects, $this->getAllObjectsFromArray($body, $synchronization)); } - if ($useNextEndpoint === false) { + if ($useNextEndpoint === false && $synchronization->usesPagination() === true) { do { $config = $this->getNextPage(config: $config, sourceConfig: $sourceConfig, currentPage: $currentPage); $response = $this->callService->call(source: $source, endpoint: $endpoint, method: 'GET', config: $config)->getResponse(); diff --git a/lib/Settings/OpenConnectorAdmin.php b/lib/Settings/OpenConnectorAdmin.php index e69de29..4e35c3f 100644 --- a/lib/Settings/OpenConnectorAdmin.php +++ b/lib/Settings/OpenConnectorAdmin.php @@ -0,0 +1,43 @@ +config = $config; + $this->l = $l; + } + + /** + * @return TemplateResponse + */ + public function getForm() { + $parameters = [ + 'mySetting' => $this->config->getSystemValue('open_connector_setting', true), + ]; + + return new TemplateResponse('openconnector', 'settings/admin', $parameters, ''); + } + + public function getSection() { + return 'openconnector'; // Name of the previously created section. + } + + /** + * @return int whether the form should be rather on the top or bottom of + * the admin section. The forms are arranged in ascending order of the + * priority values. It is required to return a value between 0 and 100. + * + * E.g.: 70 + */ + public function getPriority() { + return 10; + } +} diff --git a/lib/Twig/AuthenticationExtension.php b/lib/Twig/AuthenticationExtension.php index fed2dfb..a4cc8ec 100644 --- a/lib/Twig/AuthenticationExtension.php +++ b/lib/Twig/AuthenticationExtension.php @@ -11,6 +11,7 @@ public function getFunctions(): array { return [ new TwigFunction(name: 'oauthToken', callable: [AuthenticationRuntime::class, 'oauthToken']), + new TwigFunction(name: 'decosToken', callable: [AuthenticationRuntime::class, 'decosToken']), new TwigFunction(name: 'jwtToken', callable: [AuthenticationRuntime::class, 'jwtToken']), ]; //return parent::getFunctions(); // TODO: Change the autogenerated stub diff --git a/lib/Twig/AuthenticationRuntime.php b/lib/Twig/AuthenticationRuntime.php index 1655229..7534bcf 100644 --- a/lib/Twig/AuthenticationRuntime.php +++ b/lib/Twig/AuthenticationRuntime.php @@ -37,6 +37,25 @@ public function oauthToken(Source $source): string ); } + /** + * Add a decos non-oauth token to the configuration. + * + * @param Source $source + * @return string + * + * @throws GuzzleException + */ + public function decosToken(Source $source): string + { + $configuration = new Dot($source->getConfiguration(), true); + + $authConfig = $configuration->get('authentication'); + + return $this->authService->fetchDecosToken( + configuration: $authConfig + ); + } + /** * Add a jwt token to the configuration. *