diff --git a/src/clientAuth/clientAuth.js b/src/clientAuth/clientAuth.js new file mode 100644 index 0000000..fbc067d --- /dev/null +++ b/src/clientAuth/clientAuth.js @@ -0,0 +1,34 @@ +/** + * @fileoverview Adds authentication information to a request and validates + * client info. + */ + +const OICCli = require('../init.js').OICCli; +const utf8 = require('utf8'); +const base64url = require('base64url'); + +/** + * ClientAuthnMethod + * Basic Client Authentication Method class. + * @class + * @constructor + */ +class ClientAuthnMethod { + constructor() {} + + construct(params) { + throw new Error('Unsupported Operation Exception'); + } +} + +function validServiceContext(serviceContext, when) { + let eta = serviceContext['client_secret_expires_at'] || 0; + let now = when || Date.now(); + if (eta !== 0 && eta < now) { + return false; + } + return true; +} + +module.exports.ClientAuthnMethod = ClientAuthnMethod; +module.exports.validServiceContext = validServiceContext; \ No newline at end of file diff --git a/test/clientAuth-test.js b/test/clientAuth-test.js new file mode 100644 index 0000000..56941c9 --- /dev/null +++ b/test/clientAuth-test.js @@ -0,0 +1,19 @@ +const assert = require('chai').assert; +const validServiceContext = require('../src/clientAuth/clientAuth').validServiceContext; + +describe('Test valid client info', function() { + let now = 123456; + + it('test valid client info works', function() { + assert.isTrue(validServiceContext({}, now)); + assert.isTrue( + validServiceContext({'client_id': 'test', 'client_secret': 'secret'}, now)); + assert.isTrue(validServiceContext({'client_secret_expires_at': 0}, now)); + assert.isTrue(validServiceContext({'client_secret_expires_at': 123460}, now)); + assert.isTrue(validServiceContext( + {'client_id': 'test', 'client_secret_expires_at': 123460}, now)); + assert.isFalse(validServiceContext({'client_secret_expires_at': 1}, now)); + assert.isFalse(validServiceContext( + {'client_id': 'test', 'client_secret_expires_at': 123455}, now)); + }); +}); \ No newline at end of file