Skip to content

Commit

Permalink
refactor: rename client.userinfo() verb parameter to method
Browse files Browse the repository at this point in the history
BREAKING CHANGE: `client.userinfo()` `verb` parameter was renamed to
`method`
  • Loading branch information
panva committed Sep 8, 2020
1 parent a007c9d commit 4cb21a4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
5 changes: 2 additions & 3 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -1053,13 +1053,12 @@ module.exports = (issuer, aadIssValidation = false) => class Client extends Base
* @api public
*/
async userinfo(accessToken, {
verb = 'GET', via = 'header', tokenType, params,
method = 'GET', via = 'header', tokenType, params,
} = {}) {
// TODO: in v4.x remove verb in favour of method
assertIssuerConfiguration(this.issuer, 'userinfo_endpoint');
const options = {
tokenType,
method: String(verb).toUpperCase(),
method: String(method).toUpperCase(),
};

if (options.method !== 'GET' && options.method !== 'POST') {
Expand Down
14 changes: 7 additions & 7 deletions test/client/client_instance.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1060,7 +1060,7 @@ describe('Client', () => {
const issuer = new Issuer({ userinfo_endpoint: 'https://op.example.com/me' });
const client = new issuer.Client({ client_id: 'identifier', token_endpoint_auth_method: 'none' });

return client.userinfo('tokenValue', { verb: 'PUT' }).then(fail, (error) => {
return client.userinfo('tokenValue', { method: 'PUT' }).then(fail, (error) => {
expect(error).to.be.instanceof(TypeError);
expect(error.message).to.eql('#userinfo() verb can only be POST or a GET');
});
Expand Down Expand Up @@ -1170,7 +1170,7 @@ describe('Client', () => {
.matchHeader('Content-Type', '')
.post('/me').reply(200, {});

return client.userinfo('tokenValue', { verb: 'POST' }).then(() => {
return client.userinfo('tokenValue', { method: 'POST' }).then(() => {
expect(nock.isDone()).to.be.true;
});
});
Expand All @@ -1189,7 +1189,7 @@ describe('Client', () => {
.post('/me', () => true) // to make sure filteringRequestBody works
.reply(200, {});

return client.userinfo('tokenValue', { verb: 'POST', via: 'body' }).then(() => {
return client.userinfo('tokenValue', { method: 'POST', via: 'body' }).then(() => {
expect(nock.isDone()).to.be.true;
});
});
Expand All @@ -1210,7 +1210,7 @@ describe('Client', () => {
.reply(200, {});

return client.userinfo('tokenValue', {
verb: 'POST',
method: 'POST',
via: 'body',
params: { foo: 'bar' },
}).then(() => {
Expand All @@ -1234,7 +1234,7 @@ describe('Client', () => {
.reply(200, {});

return client.userinfo('tokenValue', {
verb: 'POST',
method: 'POST',
params: { foo: 'bar' },
}).then(() => {
expect(nock.isDone()).to.be.true;
Expand All @@ -1261,7 +1261,7 @@ describe('Client', () => {
const issuer = new Issuer({ userinfo_endpoint: 'https://op.example.com/me' });
const client = new issuer.Client({ client_id: 'identifier', token_endpoint_auth_method: 'none' });

return client.userinfo('tokenValue', { via: 'body', verb: 'get' }).then(fail, ({ message }) => {
return client.userinfo('tokenValue', { via: 'body', method: 'get' }).then(fail, ({ message }) => {
expect(message).to.eql('can only send body on POST');
});
});
Expand All @@ -1284,7 +1284,7 @@ describe('Client', () => {
const issuer = new Issuer({ userinfo_endpoint: 'https://op.example.com/me' });
const client = new issuer.Client({ client_id: 'identifier', token_endpoint_auth_method: 'none' });

return client.userinfo('tokenValue', { via: 'query', verb: 'post' }).then(fail, ({ message }) => {
return client.userinfo('tokenValue', { via: 'query', method: 'post' }).then(fail, ({ message }) => {
expect(message).to.eql('userinfo endpoints will only parse query strings for GET requests');
});
});
Expand Down
2 changes: 1 addition & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ export class Client {
* will be used automatically.
* @param options Options for the UserInfo request.
*/
userinfo(accessToken: TokenSet | string, options?: { verb?: 'GET' | 'POST', via?: 'header' | 'body' | 'query', tokenType?: string, params?: object }): Promise<UserinfoResponse>;
userinfo(accessToken: TokenSet | string, options?: { method?: 'GET' | 'POST', via?: 'header' | 'body' | 'query', tokenType?: string, params?: object }): Promise<UserinfoResponse>;

/**
* Fetches an arbitrary resource with the provided Access Token in an Authorization header.
Expand Down

0 comments on commit 4cb21a4

Please sign in to comment.