diff --git a/lib/authentication.js b/lib/authentication.js index 3b4054a..19fe9d9 100644 --- a/lib/authentication.js +++ b/lib/authentication.js @@ -29,12 +29,10 @@ function getAuthData(type) { async function fetchTrustedSubject(endpoint) { try { - // TODO: Implement fetching trusted subject from UCL endpoint Logger.log('TrustedSubjectService:', endpoint); - return null; - // const resp = await fetch(endpoint); - // const jsonBody = (await resp.json()); - // return jsonBody.certSubject; + const resp = await fetch(endpoint); + const jsonBody = (await resp.json()); + return jsonBody.certSubject; } catch (error) { Logger.error('TrustedSubjectService:', error.message); return null; diff --git a/lib/plugin.js b/lib/plugin.js index c5cadb9..cd84ba0 100644 --- a/lib/plugin.js +++ b/lib/plugin.js @@ -5,11 +5,12 @@ const { authenticate, getTrustedSubjects } = require("./authentication"); cds.on("bootstrap", async (app) => { try { // TODO: Renewal of trustedSubjects every N days ?? - const trustedSubjects = await getTrustedSubjects(); - cds.context = { - ...cds.context, - trustedSubjects, // TODO: Store trusted subjects in context ?? - }; + if (!cds.context) { + cds.context = cds.context || {}; + } + if (!cds.context.trustedSubjects) { + cds.context.trustedSubjects = await getTrustedSubjects();// TODO: Store trusted subjects in context or somewhere else?? + } } catch (error) { Logger.error(error, 'Error while loading service'); } diff --git a/xmpl/default-env.json b/xmpl/default-env.json index d0185c4..7991336 100644 --- a/xmpl/default-env.json +++ b/xmpl/default-env.json @@ -4,13 +4,11 @@ "ORD_BASE_URL": "http://localhost:8080", "ORD_SOURCE_TYPE": "local", "ORD_DIRECTORY": "./example", - "ORD_AUTH": "basic", + "ORD_AUTH": "ucl-mtls", "APP_USERS": { "admin": "secret" }, "UCL_MTLS_ENDPOINTS": [ - "https://endpoint1.example.com/v1/info", - "https://endpoint2.example.com/v1/info", "https://compass-gateway.mps.kyma.cloud.sap/v1/info" ] }