diff --git a/config/config.json b/config/config.json index 5e35a07..89d1684 100644 --- a/config/config.json +++ b/config/config.json @@ -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" -} \ No newline at end of file +} diff --git a/index.js b/index.js index 641217c..150f571 100644 --- a/index.js +++ b/index.js @@ -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'); @@ -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); \ No newline at end of file +.catch(errorHandler);