From 02b9536f54ff1d043bbafe346dab343db15f04bf Mon Sep 17 00:00:00 2001 From: Lars Jacobsson Date: Fri, 21 Aug 2020 17:27:14 +0200 Subject: [PATCH] fixing sha issue --- index.js | 18 ++++++++++++------ package.json | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 5071207..71fbb07 100644 --- a/index.js +++ b/index.js @@ -37,6 +37,10 @@ AWS.SingleSignOnCredentials = AWS.util.inherit(AWS.Credentials, { } AWS.config.update({ region: profile.sso_region }); const sso = new AWS.SSO(); + if (!profile.sso_start_url) { + callback(new Error("No sso_start_url")); + return; + } const fileName = `${sha1(profile.sso_start_url)}.json`; @@ -52,18 +56,20 @@ AWS.SingleSignOnCredentials = AWS.util.inherit(AWS.Credentials, { const cachedFile = fs.readFileSync(cachePath); cacheObj = JSON.parse(cachedFile.toString()); } - const request = { - accessToken: cacheObj.accessToken, - accountId: profile.sso_account_id, - roleName: profile.sso_role_name, - }; - if (!request) { + + if (!cacheObj) { throw AWS.util.error( new Error( `Cached credentials not found under ${cachePath}. Please make sure you log in with 'aws sso login' first` ) ); } + + const request = { + accessToken: cacheObj.accessToken, + accountId: profile.sso_account_id, + roleName: profile.sso_role_name, + }; sso.getRoleCredentials(request, (err, c) => { if (!c) { console.log(err.message); diff --git a/package.json b/package.json index 40e6cc3..9db97d0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@mhlabs/aws-sdk-sso", - "version": "0.0.9", + "version": "0.0.10", "description": "Credentials provider for AWS Single Sign-On", "main": "index.js", "scripts": {