Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

39 query param support #47

Merged
merged 4 commits into from
Apr 26, 2017
Merged

39 query param support #47

merged 4 commits into from
Apr 26, 2017

Conversation

bzums
Copy link
Collaborator

@bzums bzums commented Apr 25, 2017

close #39

When requesting an access token (via `TokenCache` or via
`getAccessToken`) one can now specify an object `queryParams`
in the `OAuthConfig`. The given key-value pairs will be added
to the reuqest as query parameters.

`createAuthCodeRequestUri` accepts an optional parameter
`queryParams`. The given key-value pairs will be added to the
returned url string as query parameters.

close #39
@bzums bzums self-assigned this Apr 25, 2017
@bzums bzums requested review from ISO50 and Retro64 April 25, 2017 06:10
getTokenInfo
} from '../../src/index';

chai.use(chaiAsPromised);
const expect = chai.expect;

const port = '30001';
const host = `http://127.0.0.1:${30001}`;
Copy link
Collaborator

Choose a reason for hiding this comment

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

port ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

👍 ^^


const promise = new Promise(function(resolve, reject) {

fetch(accessTokenEndpoint + '?realm=' + realm, {
const queryString = qs.stringify(Object.assign({ realm: realm }, queryParams));
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is safe if queryParams is not set?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is, see examples in https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign

"[...]null and undefined will be ignored."

Copy link
Collaborator

Choose a reason for hiding this comment

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

Object.assign({ realm }, queryParams));

or with spread:

const x = { 
   ...{ realm },
   ...queryParams}
);

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point, will tackle that.

redirectUri, queryParams);

// then
const expected = authorizationEndpoint +
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we use template strings?

Copy link
Collaborator Author

@bzums bzums Apr 25, 2017

Choose a reason for hiding this comment

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

Yes you are right, I would suggest this solution:

      const expected = `${authorizationEndpoint}` +
        `?client_id=${clientId}` +
        `&redirect_uri=${redirectUri}` +
        `&response_type=code` +
        `&realm=${EMPLOYEES_REALM}` +
        `&foo=bar`;

cause with multi line template strings we have the problem that
whitespaces are not ignored. So that would destroy the formatting, right?

Copy link
Collaborator

@ISO50 ISO50 Apr 25, 2017

Choose a reason for hiding this comment

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

True, alternative idea:

const expected = [
  ``,
   ``
].join();

@ISO50
Copy link
Collaborator

ISO50 commented Apr 26, 2017

👍

1 similar comment
@bzums
Copy link
Collaborator Author

bzums commented Apr 26, 2017

👍

@bzums bzums merged commit 7b6889d into master Apr 26, 2017
@bzums bzums deleted the 39-query-param-support branch April 26, 2017 08:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide possibility to add arbitrary query parameters to token request
2 participants