diff --git a/.coordinator.env b/.coordinator.env index 34f17a7..5c2e093 100644 --- a/.coordinator.env +++ b/.coordinator.env @@ -7,7 +7,7 @@ # default is false # ENABLE_ACCESS_LOGGING=true # default is false -# ENABLE_STATUS_SERVICE=true +ENABLE_STATUS_SERVICE=true # set the service endpoints # defaults are as follows diff --git a/.gitignore b/.gitignore index 2903e0b..3d1c3a8 100644 --- a/.gitignore +++ b/.gitignore @@ -71,6 +71,9 @@ typings/ # dotenv environment variables file .env .env.test +.signing-service.env +.coordinator.env +.status-service.env # parcel-bundler cache (https://parceljs.org/) .cache diff --git a/.status-service.env b/.status-service.env index 0b80e67..91b90fd 100644 --- a/.status-service.env +++ b/.status-service.env @@ -9,6 +9,6 @@ CRED_STATUS_REPO_OWNER=jchartrand CRED_STATUS_REPO_NAME=status-test-three CRED_STATUS_META_REPO_NAME=status-test-meta-three -CRED_STATUS_ACCESS_TOKEN=add-your-token-here +CRED_STATUS_ACCESS_TOKEN=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 # replace the following did seed with your own CRED_STATUS_DID_SEED=z1AackbUm8U69ohKnihoRRFkXcXJd4Ra1PkAboQ2ZRy1ngB diff --git a/src/app.js b/src/app.js index 4c2705b..0268a75 100644 --- a/src/app.js +++ b/src/app.js @@ -55,11 +55,8 @@ export async function build(opts = {}) { }); app.get('/seedgen', async (req, res, next) => { - const reponse = await axios.get(`http://${signingServiceEndpoint}/seedgen`) - return res.json(res.body) - - // const newSeed = await generateSeed() - // res.send(newSeed) + const response = await axios.get(`http://${signingServiceEndpoint}/seedgen`) + return res.json(response.data) }); app.post("/instance/:tenantName/credentials/issue", diff --git a/src/config.js b/src/config.js index dc77995..5e9d054 100644 --- a/src/config.js +++ b/src/config.js @@ -8,10 +8,6 @@ const defaultTenantToken = "UNPROTECTED" const defaultStatusServiceEndpoint = "STATUS:4008" const defaultSigningServiceEndpoint = "SIGNER:4006" -//const defaultStatusServiceEndpoint = "localhost:4008" -//const defaultSigningServiceEndpoint = "localhost:4006" - - // we set a default tenant // It will be overwritten by whatever value is set for default in .env const TENANT_ACCESS_TOKENS = {} @@ -33,8 +29,6 @@ function parseTenantTokens() { const tenantName = key.slice(13).toLowerCase() TENANT_ACCESS_TOKENS[tenantName] = value } - console.log("tenant tokens:") - console.log(TENANT_ACCESS_TOKENS) } @@ -66,8 +60,6 @@ export function getTenantToken(tenantName) { if (! Object.keys(TENANT_ACCESS_TOKENS).length) { parseTenantTokens() } - console.log("the token list:") - console.log(TENANT_ACCESS_TOKENS) if (TENANT_ACCESS_TOKENS.hasOwnProperty(tenantName)) { return TENANT_ACCESS_TOKENS[tenantName]; } else { diff --git a/src/verifyAuthHeader.js b/src/verifyAuthHeader.js index ae79341..493be8b 100644 --- a/src/verifyAuthHeader.js +++ b/src/verifyAuthHeader.js @@ -7,31 +7,26 @@ function AuthorizationException(code, message) { export default async function verifyAuthHeader(authHeader, tenantName) { + const tenantToken = getTenantToken(tenantName) + if (!tenantToken) { + throw new AuthorizationException(404, "Tenant does not exist.") + } - console.log("tenant name: ") - console.log(tenantName) - const tenantToken = getTenantToken(tenantName) - console.log("tenantToken") - console.log(tenantToken) - if (!tenantToken) { - throw new AuthorizationException(404, "Tenant does not exist.") - } + if (tenantToken === 'UNPROTECTED') return true // no tenant token has been set so no auth required - if (tenantToken === 'UNPROTECTED') return true // no tenant token has been set so no auth required + if (!authHeader) { + throw new AuthorizationException(401, 'No authorization header was provided.') + } + const [scheme, accessToken] = authHeader.split(' '); - if (!authHeader) { - throw new AuthorizationException(401, 'No authorization header was provided.') - } - const [scheme, accessToken] = authHeader.split(' '); + if (!(scheme === 'Bearer')) { + throw new AuthorizationException(401, 'Access header must be of type Bearer.') + } - if (!(scheme === 'Bearer')) { - throw new AuthorizationException(401, 'Access header must be of type Bearer.') - } + if (tenantToken !== accessToken) { + throw new AuthorizationException(403, 'You provided a token that is not authorized or may have changed.') + } - if (tenantToken !== accessToken) { - throw new AuthorizationException(403, 'You provided a token that is not authorized or may have changed.') - } + return true - return true - } \ No newline at end of file