Skip to content
This repository was archived by the owner on Jan 20, 2024. It is now read-only.

Commit 75af020

Browse files
authored
Merge pull request #153 from mulesoft/i144_auth_url_with_parameters
Preserve query string params in authorizationUri
2 parents b2f7174 + b9567df commit 75af020

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

src/client-oauth2.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,9 @@ function createUri (options, tokenType) {
161161
// Check the required parameters are set.
162162
expects(options, 'clientId', 'authorizationUri')
163163

164-
return options.authorizationUri + '?' + Querystring.stringify(Object.assign({
164+
const sep = options.authorizationUri.includes('?') ? '&' : '?'
165+
166+
return options.authorizationUri + sep + Querystring.stringify(Object.assign({
165167
client_id: options.clientId,
166168
redirect_uri: options.redirectUri,
167169
scope: sanitizeScope(options.scopes),

test/code.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* global describe, it */
1+
/* global describe, it, context */
22
var expect = require('chai').expect
33
var config = require('./support/config')
44
var ClientOAuth2 = require('../')
@@ -24,6 +24,24 @@ describe('code', function () {
2424
'scope=notifications&response_type=code&state='
2525
)
2626
})
27+
context('when authorizationUri contains query parameters', function () {
28+
it('should preserve query string parameters', function () {
29+
const authWithParams = new ClientOAuth2({
30+
clientId: config.clientId,
31+
clientSecret: config.clientSecret,
32+
accessTokenUri: config.accessTokenUri,
33+
authorizationUri: config.authorizationUri + '?bar=qux',
34+
authorizationGrants: ['code'],
35+
redirectUri: config.redirectUri,
36+
scopes: 'notifications'
37+
})
38+
expect(authWithParams.code.getUri()).to.equal(
39+
config.authorizationUri + '?bar=qux&client_id=abc&' +
40+
'redirect_uri=http%3A%2F%2Fexample.com%2Fauth%2Fcallback&' +
41+
'scope=notifications&response_type=code&state='
42+
)
43+
})
44+
})
2745
})
2846

2947
describe('#getToken', function () {

test/token.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* global describe, it */
1+
/* global describe, it, context */
22
var expect = require('chai').expect
33
var config = require('./support/config')
44
var ClientOAuth2 = require('../')
@@ -22,6 +22,22 @@ describe('token', function () {
2222
'scope=notifications&response_type=token&state='
2323
)
2424
})
25+
context('when authorizationUri contains query parameters', function () {
26+
it('should preserve query string parameters', function () {
27+
const authWithParams = new ClientOAuth2({
28+
clientId: config.clientId,
29+
authorizationUri: config.authorizationUri + '?bar=qux',
30+
authorizationGrants: ['token'],
31+
redirectUri: config.redirectUri,
32+
scopes: ['notifications']
33+
})
34+
expect(authWithParams.token.getUri()).to.equal(
35+
config.authorizationUri + '?bar=qux&client_id=abc&' +
36+
'redirect_uri=http%3A%2F%2Fexample.com%2Fauth%2Fcallback&' +
37+
'scope=notifications&response_type=token&state='
38+
)
39+
})
40+
})
2541
})
2642

2743
describe('#getToken', function () {

0 commit comments

Comments
 (0)