Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"clientScopes": "",
"keyId": "",
"tokenUrl": "https://matls-sso.openbanking.org.uk/as/token.oauth2",
"tppTestUrl": "https://matls-api.openbanking.org.uk/scim/v2/OBThirdPartyProviders",
"testUrl": "https://matls-api.openbanking.org.uk/scim/v2/OBThirdPartyProviders",
"aud": "https://matls-sso.openbanking.org.uk/as/token.oauth2"
}
}
43 changes: 26 additions & 17 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,13 @@ const transportKey = fs.readFileSync(`${__dirname}/config/privateKeyTransport.ke
const trustedCa = [
`${__dirname}/config/root.pem`,
`${__dirname}/config/issuingca.pem`,
`${__dirname}/config/signingca.pem`
];

const claims = {
iss: config.softwareStatementId,
sub: config.softwareStatementId,
scope: config.clientScopes,
aud: config.aud
iss: config.softwareStatementId,
sub: config.softwareStatementId,
scope: config.clientScopes,
aud: config.aud
};

const created_jwt = nJwt.create(claims, signingKey, 'RS256');
Expand Down Expand Up @@ -88,28 +87,38 @@ request(tokenRequestSpec)
console.log();

// Configure the request for test endpoint - list of TPPs
const tppRequestSpec = {
url: config.tppTestUrl,
httpsAgent: httpsAgent,
const testRequestSpec = {
url: config.testUrl,
httpsAgent: httpsAgent,
method: "GET",
headers: {
"Authorization": `Bearer ${response.data.access_token}`
}
};

return request(tppRequestSpec);
return request(testRequestSpec);

})
.then((response) => {
console.log();
console.log(chalk.bold.yellow("Response Headers"), response.headers);

// Test request to get the list of TPPs
response.data.Resources.forEach((tpp) => {
const org = tpp['urn:openbanking:organisation:1.0'];
const auth = tpp['urn:openbanking:competentauthorityclaims:1.0'];
const authorisation =tpp['urn:openbanking:accountservicepaymentserviceprovider:1.0'];
console.log();
console.log(chalk.bold.yellow("Response Body"), response.data);

console.log("-", org.OrganisationCommonName, "-", auth.Authorisations);
});
if (response.headers['content-type'] == 'application/jwt') {
console.log();
console.log(chalk.bold.yellow("Response was a JWT..."));

let jwt_bits = response.data.toString().split('.');
let decoded_header = new Buffer(jwt_bits[0], 'base64').toString('utf-8');
let decoded_claims = new Buffer(jwt_bits[1], 'base64').toString('utf-8');

console.log();
console.log(chalk.bold.yellow("JWT Header"), JSON.stringify(JSON.parse(decoded_header), null, 2));

console.log();
console.log(chalk.bold.yellow("JWT Claims"), JSON.stringify(JSON.parse(decoded_claims), null, 2));
}
})
.catch(errorHandler);
.catch(errorHandler);