-
Notifications
You must be signed in to change notification settings - Fork 12
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
Conversation
simplified test see #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
getTokenInfo | ||
} from '../../src/index'; | ||
|
||
chai.use(chaiAsPromised); | ||
const expect = chai.expect; | ||
|
||
const port = '30001'; | ||
const host = `http://127.0.0.1:${30001}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
port
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 ^^
src/oauth-tooling.ts
Outdated
|
||
const promise = new Promise(function(resolve, reject) { | ||
|
||
fetch(accessTokenEndpoint + '?realm=' + realm, { | ||
const queryString = qs.stringify(Object.assign({ realm: realm }, queryParams)); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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."
There was a problem hiding this comment.
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}
);
There was a problem hiding this comment.
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.
test/unit/index.ts
Outdated
redirectUri, queryParams); | ||
|
||
// then | ||
const expected = authorizationEndpoint + |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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();
use spread instead of object.assign see #39
👍 |
1 similar comment
👍 |
close #39