Skip to content

Commit

Permalink
Merge pull request #47 from mojaloop/feature/MBXSDK-9
Browse files Browse the repository at this point in the history
Add OAuth2.0 periodic token refresh functionality
  • Loading branch information
bushjames committed Sep 12, 2019
2 parents bf461e6 + d908361 commit 799061e
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 7 deletions.
11 changes: 9 additions & 2 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ let DEFAULTS = {
host: 'localhost',
port: 6379
},
enableTestFeatures: false
enableTestFeatures: false,
wso2Auth: {
refreshSeconds: 3600,
}
};

let config = {};
Expand Down Expand Up @@ -149,7 +152,11 @@ const setConfig = async cfg => {

config.enableTestFeatures = cfg.ENABLE_TEST_FEATURES.toLowerCase() === 'true' ? true : false;

config.wso2BearerToken = cfg.WS02_BEARER_TOKEN;
config.wso2Auth.staticToken = cfg.WS02_BEARER_TOKEN;
config.wso2Auth.tokenEndpoint = cfg.OAUTH_TOKEN_ENDPOINT;
config.wso2Auth.clientKey = cfg.OAUTH_CLIENT_KEY;
config.wso2Auth.clientSecret = cfg.OAUTH_CLIENT_SECRET;
config.wso2Auth.refreshSeconds = cfg.OAUTH_REFRESH_SECONDS;
};

const getConfig = () => {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/model/inboundModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class InboundTransfersModel {
tls: config.tls,
jwsSign: config.jwsSign,
jwsSigningKey: config.jwsSigningKey,
wso2BearerToken: config.wso2BearerToken
wso2Auth: config.wso2Auth
});

this.backendRequests = new BackendRequests({
Expand Down
2 changes: 1 addition & 1 deletion src/lib/model/outboundModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class OutboundTransfersModel {
tls: config.tls,
jwsSign: config.jwsSign,
jwsSigningKey: config.jwsSigningKey,
wso2BearerToken: config.wso2BearerToken
wso2Auth: config.wso2Auth
});

this.ilp = new Ilp({
Expand Down
6 changes: 6 additions & 0 deletions src/local.env
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,9 @@ ENABLE_TEST_FEATURES=false

# WS02 Bearer Token specific to golden-fsp instance and environment
WS02_BEARER_TOKEN=7718fa9b-be13-3fe7-87f0-a12cf1628168

# OAuth2 data used to obtain WSO2 bearer token
OAUTH_TOKEN_ENDPOINT=
OAUTH_CLIENT_KEY
OAUTH_CLIENT_SECRET
OAUTH_REFRESH_SECONDS=3600
2 changes: 1 addition & 1 deletion src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"@internal/randomphrase": "file:lib/randomphrase",
"@internal/router": "file:lib/router",
"@internal/validate": "file:lib/validate",
"@mojaloop/sdk-standard-components": "^7.4.0",
"@mojaloop/sdk-standard-components": "^7.5.1",
"co-body": "^6.0.0",
"dotenv": "^6.2.0",
"koa": "^2.6.2",
Expand Down
7 changes: 5 additions & 2 deletions src/test/unit/config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ describe('config', () => {
host: 'localhost',
port: 6379
},
enableTestFeatures: false
enableTestFeatures: false,
wso2Auth: {
refreshSeconds: 3600,
},
};
});

Expand Down Expand Up @@ -132,7 +135,7 @@ describe('config', () => {
expect(retrievedConfig.cacheConfig.host).toBe(process.env.CACHE_HOST);
expect(retrievedConfig.cacheConfig.port).toBe(process.env.CACHE_PORT);
expect(retrievedConfig.enableTestFeatures).toBe(process.env.ENABLE_TEST_FEATURES === 'true');
expect(retrievedConfig.wso2BearerToken).toBe(process.env.WS02_BEARER_TOKEN);
expect(retrievedConfig.wso2Auth.staticToken).toBe(process.env.WS02_BEARER_TOKEN);
expect(retrievedConfig.jwsVerificationKeysDirectory).toBe(process.env.JWS_VERIFICATION_KEYS_DIRECTORY);
expect(Buffer.isBuffer(retrievedConfig.jwsSigningKey)).toBe(true);
expect(typeof(retrievedConfig.jwsVerificationKeys)).toBe('object');
Expand Down

0 comments on commit 799061e

Please sign in to comment.