From b605853f764bd7925d03f909e32085a52819d3f9 Mon Sep 17 00:00:00 2001 From: Daniel Kendell Date: Thu, 26 Jul 2018 17:38:29 +0100 Subject: [PATCH 1/5] support both json and jwt responses --- index.js | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/index.js b/index.js index 641217c..934ac96 100644 --- a/index.js +++ b/index.js @@ -26,7 +26,6 @@ const transportKey = fs.readFileSync(`${__dirname}/config/privateKeyTransport.ke const trustedCa = [ `${__dirname}/config/root.pem`, `${__dirname}/config/issuingca.pem`, - `${__dirname}/config/signingca.pem` ]; const claims = { @@ -89,8 +88,8 @@ request(tokenRequestSpec) // Configure the request for test endpoint - list of TPPs const tppRequestSpec = { - url: config.tppTestUrl, - httpsAgent: httpsAgent, + url: config.testUrl, + httpsAgent: httpsAgent, method: "GET", headers: { "Authorization": `Bearer ${response.data.access_token}` @@ -101,15 +100,22 @@ request(tokenRequestSpec) }) .then((response) => { + console.log(); + console.log(chalk.bold.yellow("Response Headers"), response.headers); + + console.log(); + console.log(chalk.bold.yellow("Response Body"), response.data); - // 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']; + if (response.headers['content-type'] == 'application/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("-", org.OrganisationCommonName, "-", auth.Authorisations); - }); + 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); From 5fad5009a1f86c9a40ee0d79ca0bd6b00de6b7b4 Mon Sep 17 00:00:00 2001 From: Daniel Kendell Date: Fri, 27 Jul 2018 10:16:52 +0100 Subject: [PATCH 2/5] updated config file with new test URL config key. it's no longer tied to SCIM or TPPs --- config/config.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 +} From 3a84949562bbf1edb06569dd0368b01b5faa1830 Mon Sep 17 00:00:00 2001 From: Daniel Kendell Date: Fri, 27 Jul 2018 10:19:51 +0100 Subject: [PATCH 3/5] renamed tppRequestSpec to testRequestSpec --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 934ac96..fbeedf2 100644 --- a/index.js +++ b/index.js @@ -87,7 +87,7 @@ request(tokenRequestSpec) console.log(); // Configure the request for test endpoint - list of TPPs - const tppRequestSpec = { + const testRequestSpec = { url: config.testUrl, httpsAgent: httpsAgent, method: "GET", @@ -96,7 +96,7 @@ request(tokenRequestSpec) } }; - return request(tppRequestSpec); + return request(testRequestSpec); }) .then((response) => { From 35b5a2ff1a346c086f8954051b92fc6cbad16207 Mon Sep 17 00:00:00 2001 From: Daniel Kendell Date: Fri, 27 Jul 2018 10:20:09 +0100 Subject: [PATCH 4/5] indentation --- index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index fbeedf2..855bd03 100644 --- a/index.js +++ b/index.js @@ -29,10 +29,10 @@ const trustedCa = [ ]; 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'); From 51eb1749080c0d4b882c9620afe8a4a4b0e3173a Mon Sep 17 00:00:00 2001 From: Daniel Kendell Date: Fri, 27 Jul 2018 10:31:43 +0100 Subject: [PATCH 5/5] console.log that the response was a JWT --- index.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/index.js b/index.js index 855bd03..150f571 100644 --- a/index.js +++ b/index.js @@ -107,6 +107,9 @@ request(tokenRequestSpec) console.log(chalk.bold.yellow("Response Body"), response.data); 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');