Skip to content

Commit fd04368

Browse files
committed
Fix: OAuth 2.0 Grant Type Authorization: "invalid_client" error / URL Encode of Client ID
1 parent 98cc19b commit fd04368

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

packages/bruno-electron/src/ipc/network/oauth2-helper.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -102,25 +102,25 @@ const getOAuth2AuthorizationCode = (request, codeChallenge, collectionUid) => {
102102
const { oauth2 } = request;
103103
const { callbackUrl, clientId, authorizationUrl, scope, state, pkce } = oauth2;
104104

105-
let oauth2QueryParams =
106-
(authorizationUrl.indexOf('?') > -1 ? '&' : '?') + `client_id=${clientId}&response_type=code`;
105+
const authorizationUrlWithQueryParams = new URL(authorizationUrl);
106+
authorizationUrlWithQueryParams.searchParams.append('response_type', 'code');
107+
authorizationUrlWithQueryParams.searchParams.append('client_id', clientId);
107108
if (callbackUrl) {
108-
oauth2QueryParams += `&redirect_uri=${callbackUrl}`;
109+
authorizationUrlWithQueryParams.searchParams.append('redirect_uri', callbackUrl);
109110
}
110111
if (scope) {
111-
oauth2QueryParams += `&scope=${scope}`;
112+
authorizationUrlWithQueryParams.searchParams.append('scope', scope);
112113
}
113114
if (pkce) {
114-
oauth2QueryParams += `&code_challenge=${codeChallenge}&code_challenge_method=S256`;
115+
authorizationUrlWithQueryParams.searchParams.append('code_challenge', codeChallenge);
116+
authorizationUrlWithQueryParams.searchParams.append('code_challenge_method', 'S256');
115117
}
116118
if (state) {
117-
oauth2QueryParams += `&state=${state}`;
119+
authorizationUrlWithQueryParams.searchParams.append('state', state);
118120
}
119-
120-
const authorizationUrlWithQueryParams = authorizationUrl + oauth2QueryParams;
121121
try {
122122
const { authorizationCode } = await authorizeUserInWindow({
123-
authorizeUrl: authorizationUrlWithQueryParams,
123+
authorizeUrl: authorizationUrlWithQueryParams.toString(),
124124
callbackUrl,
125125
session: oauth2Store.getSessionIdOfCollection(collectionUid)
126126
});
@@ -210,21 +210,21 @@ const oauth2AuthorizeWithImplicitFlow = async (request, collectionUid) => {
210210
return new Promise(async (resolve, reject) => {
211211
const { oauth2 } = request;
212212
const { callbackUrl, authorizationUrl, clientId, scope, state } = oauth2;
213-
let oauth2QueryParams =
214-
(authorizationUrl.indexOf('?') > -1 ? '&' : '?') + `client_id=${clientId}&response_type=token`;
213+
const authorizationUrlWithQueryParams = new URL(authorizationUrl);
214+
authorizationUrlWithQueryParams.searchParams.append('response_type', 'token');
215+
authorizationUrlWithQueryParams.searchParams.append('client_id', clientId);
215216
if (callbackUrl) {
216-
oauth2QueryParams += `&redirect_uri=${callbackUrl}`;
217+
authorizationUrlWithQueryParams.searchParams.append('redirect_uri', callbackUrl);
217218
}
218219
if (scope) {
219-
oauth2QueryParams += `&scope=${scope}`;
220+
authorizationUrlWithQueryParams.searchParams.append('scope', scope);
220221
}
221222
if (state) {
222-
oauth2QueryParams += `&state=${state}`;
223+
authorizationUrlWithQueryParams.searchParams.append('state', state);
223224
}
224-
const authorizationUrlWithQueryParams = authorizationUrl + oauth2QueryParams;
225225
try {
226226
const { credentials } = await authorizeUserInWindowImplicit({
227-
authorizeUrl: authorizationUrlWithQueryParams,
227+
authorizeUrl: authorizationUrlWithQueryParams.toString(),
228228
callbackUrl: callbackUrl,
229229
session: oauth2Store.getSessionIdOfCollection(collectionUid)
230230
});

0 commit comments

Comments
 (0)