Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/clientAuth/clientAuth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* @fileoverview Adds authentication information to a request and validates
* client info.
*/

const OICCli = require('../init.js').OICCli;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused constant. Please remove for now.

const utf8 = require('utf8');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused constant. Please remove for now.

const base64url = require('base64url');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused constant. Please remove for now.


/**
* ClientAuthnMethod
* Basic Client Authentication Method class.
* @class
* @constructor
*/
class ClientAuthnMethod {
constructor() {}

construct(params) {
throw new Error('Unsupported Operation Exception');
}
}

function validServiceContext(serviceContext, when) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name of this function and what it does is not really intuitive. At first I thought it will give a valid ServiceContext object, but when I looked at the code it's checking whether client_secret_expires_at is set and still before the given time.

How about changing the name into something more meaningful? E.g. isValidServiceContext or isServiceContextValid?

It also might make sense to move this function into the ServiceContext class or is there a reason to have it here?

let eta = serviceContext['client_secret_expires_at'] || 0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to have client_secret_expires_at defined as a member in ServiceContext, and access it like `serviceContext.client_secret_expires_at? Or is there a reason to access it like it is now?

let now = when || Date.now();
if (eta !== 0 && eta < now) {
return false;
}
return true;
}

module.exports.ClientAuthnMethod = ClientAuthnMethod;
module.exports.validServiceContext = validServiceContext;
19 changes: 19 additions & 0 deletions test/clientAuth-test.js
Original file line number Diff line number Diff line change
@@ -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));
});
});