Skip to content

Commit 30e80b4

Browse files
committed
Fix: OAuth 2.0 Grant Type Authorization: "invalid_client" error / URL Encode of Client ID
#2115 #1003
1 parent 2621c38 commit 30e80b4

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,26 +49,26 @@ const getOAuth2AuthorizationCode = (request, codeChallenge, collectionUid) => {
4949
const { oauth2 } = request;
5050
const { callbackUrl, clientId, authorizationUrl, scope, state, pkce } = oauth2;
5151

52-
let oauth2QueryParams =
53-
(authorizationUrl.indexOf('?') > -1 ? '&' : '?') + `client_id=${clientId}&response_type=code`;
52+
const authorizationUrlWithQueryParams = new URL(authorizationUrl);
53+
authorizationUrlWithQueryParams.searchParams.append('response_type', 'code');
54+
authorizationUrlWithQueryParams.searchParams.append('client_id', clientId);
5455
if (callbackUrl) {
55-
oauth2QueryParams += `&redirect_uri=${callbackUrl}`;
56+
authorizationUrlWithQueryParams.searchParams.append('redirect_uri', callbackUrl);
5657
}
5758
if (scope) {
58-
oauth2QueryParams += `&scope=${scope}`;
59+
authorizationUrlWithQueryParams.searchParams.append('scope', scope);
5960
}
6061
if (pkce) {
61-
oauth2QueryParams += `&code_challenge=${codeChallenge}&code_challenge_method=S256`;
62+
authorizationUrlWithQueryParams.searchParams.append('code_challenge', codeChallenge);
63+
authorizationUrlWithQueryParams.searchParams.append('code_challenge_method', 'S256');
6264
}
6365
if (state) {
64-
oauth2QueryParams += `&state=${state}`;
66+
authorizationUrlWithQueryParams.searchParams.append('state', state);
6567
}
66-
67-
const authorizationUrlWithQueryParams = authorizationUrl + oauth2QueryParams;
6868
try {
6969
const oauth2Store = new Oauth2Store();
7070
const { authorizationCode } = await authorizeUserInWindow({
71-
authorizeUrl: authorizationUrlWithQueryParams,
71+
authorizeUrl: authorizationUrlWithQueryParams.toString(),
7272
callbackUrl,
7373
session: oauth2Store.getSessionIdOfCollection(collectionUid)
7474
});

0 commit comments

Comments
 (0)