Skip to content

Commit

Permalink
fix seedgen endpoint
Browse files Browse the repository at this point in the history
fix seedgen
  • Loading branch information
jchartrand committed Aug 15, 2023
1 parent b7acefd commit 11cc7c1
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .coordinator.env
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .status-service.env
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 2 additions & 5 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 0 additions & 8 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand All @@ -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)
}


Expand Down Expand Up @@ -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 {
Expand Down
37 changes: 16 additions & 21 deletions src/verifyAuthHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

}

0 comments on commit 11cc7c1

Please sign in to comment.