Skip to content

Commit

Permalink
fix: handle empty client_secret with basic and post client auth (#610)
Browse files Browse the repository at this point in the history
closes #609
  • Loading branch information
Exidex committed Jul 6, 2023
1 parent 7747fd9 commit 402c711
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/helpers/client.js
Expand Up @@ -81,7 +81,7 @@ async function authFor(endpoint, { clientAssertionPayload } = {}) {
case 'none':
return { form: { client_id: this.client_id } };
case 'client_secret_post':
if (!this.client_secret) {
if (typeof this.client_secret !== 'string') {
throw new TypeError(
'client_secret_post client authentication method requires a client_secret',
);
Expand Down Expand Up @@ -120,7 +120,7 @@ async function authFor(endpoint, { clientAssertionPayload } = {}) {
// > Appendix B, and the encoded value is used as the username; the client
// > password is encoded using the same algorithm and used as the
// > password.
if (!this.client_secret) {
if (typeof this.client_secret !== 'string') {
throw new TypeError(
'client_secret_basic client authentication method requires a client_secret',
);
Expand Down
20 changes: 20 additions & 0 deletions test/client/client_instance.test.js
Expand Up @@ -2253,6 +2253,18 @@ describe('Client', () => {
);
});
});

it('allows client_secret to be empty string', async function () {
const issuer = new Issuer();
const client = new issuer.Client({
client_id: 'an:identifier',
client_secret: '',
token_endpoint_auth_method: 'client_secret_post',
});
expect(await clientInternal.authFor.call(client, 'token')).to.eql({
form: { client_id: 'an:identifier', client_secret: '' },
});
});
});

describe('when client_secret_basic', function () {
Expand Down Expand Up @@ -2288,6 +2300,14 @@ describe('Client', () => {
);
});
});

it('allows client_secret to be empty string', async function () {
const issuer = new Issuer();
const client = new issuer.Client({ client_id: 'an:identifier', client_secret: '' });
expect(await clientInternal.authFor.call(client, 'token')).to.eql({
headers: { Authorization: 'Basic YW4lM0FpZGVudGlmaWVyOg==' },
});
});
});

describe('when client_secret_jwt', function () {
Expand Down

0 comments on commit 402c711

Please sign in to comment.