authorize in browser - updates

This commit is contained in:
lohxt1
2025-03-19 17:05:33 +05:30
parent 0e7b0a0ce5
commit cabd520ef1
7 changed files with 32 additions and 14 deletions

View File

@@ -217,13 +217,19 @@ const OAuth2AuthorizationCode = ({ save, item = {}, request, handleRun, updateAu
</div>
</div>
{inputsConfig.map((input) => {
const { key, label, isSecret } = input;
let { key, label, isSecret } = input;
let value = oAuth[key] || '';
let shouldAuthorizeInDefaultBrowser = key == 'callbackUrl' && Boolean(authorizeInDefaultBrowser);
if (shouldAuthorizeInDefaultBrowser) {
value = 'http://localhost:9876/callback'
}
console.log("input", shouldAuthorizeInDefaultBrowser);
return (
<div className="flex items-center gap-4 w-full" key={`input-${key}`}>
<label className="block min-w-[140px]">{label}</label>
<div className="single-line-editor-wrapper flex-1">
<div className={`single-line-editor-wrapper flex-1`}>
<SingleLineEditor
value={oAuth[key] || ''}
value={value}
theme={storedTheme}
onSave={handleSave}
onChange={(val) => handleChange(key, val)}
@@ -231,6 +237,7 @@ const OAuth2AuthorizationCode = ({ save, item = {}, request, handleRun, updateAu
collection={collection}
item={item}
isSecret={isSecret}
readOnly={shouldAuthorizeInDefaultBrowser}
/>
</div>
</div>

View File

@@ -5,6 +5,10 @@ const StyledWrapper = styled.div`
height: 30px;
overflow-y: hidden;
overflow-x: hidden;
&.disabled {
opacity: 0.5;
}
.CodeMirror {
background: transparent;

View File

@@ -53,6 +53,7 @@ class SingleLineEditor extends Component {
},
scrollbarStyle: null,
tabindex: 0,
readOnly: this.props.readOnly,
extraKeys: {
Enter: runHandler,
'Ctrl-Enter': runHandler,
@@ -127,6 +128,9 @@ class SingleLineEditor extends Component {
if (this.props.theme !== prevProps.theme && this.editor) {
this.editor.setOption('theme', this.props.theme === 'dark' ? 'monokai' : 'default');
}
if (this.props.readOnly !== prevProps.readOnly && this.editor) {
this.editor.setOption('readOnly', this.props.readOnly);
}
if (this.props.value !== prevProps.value && this.props.value !== this.cachedValue && this.editor) {
this.cachedValue = String(this.props.value);
this.editor.setValue(String(this.props.value) || '');
@@ -175,7 +179,7 @@ class SingleLineEditor extends Component {
render() {
return (
<div className="flex flex-row justify-between w-full overflow-x-auto">
<StyledWrapper ref={this.editorRef} className="single-line-editor grow" />
<StyledWrapper ref={this.editorRef} className={`single-line-editor grow ${this.props.readOnly? 'disabled' : ''}`} />
{this.secretEye(this.props.isSecret)}
</div>
);

View File

@@ -197,7 +197,7 @@ const interpolateVars = (request, envVariables = {}, runtimeVariables = {}, proc
request.oauth2.autoFetchToken = _interpolate(request.oauth2.autoFetchToken);
request.oauth2.autoRefreshToken = _interpolate(request.oauth2.autoRefreshToken);
request.oauth2.autoRefreshToken = _interpolate(request.oauth2.autoRefreshToken);
request.oauth2.authorizeInDefaultBrowser = _interpolate(request.oauth2.authorizeInDefaultBrowser);
request.oauth2.authorizeInDefaultBrowser = _interpolate(request.oauth2.authorizeInDefaultBrowser) || false;
break;
case 'client_credentials':
request.oauth2.accessTokenUrl = _interpolate(request.oauth2.accessTokenUrl) || '';

View File

@@ -207,7 +207,8 @@ const setAuthHeaders = (axiosRequest, request, collectionRoot) => {
tokenHeaderPrefix: get(request, 'auth.oauth2.tokenHeaderPrefix'),
tokenQueryKey: get(request, 'auth.oauth2.tokenQueryKey'),
autoFetchToken: get(request, 'auth.oauth2.autoFetchToken'),
autoRefreshToken: get(request, 'auth.oauth2.autoRefreshToken')
autoRefreshToken: get(request, 'auth.oauth2.autoRefreshToken'),
authorizeInDefaultBrowser: get(request, 'auth.oauth2.authorizeInDefaultBrowser')
};
break;
case 'client_credentials':

View File

@@ -1,9 +1,9 @@
const express = require("express");
const { shell } = require("electron");
const BRUNO_OAUTH2_SERVER_PORT = 9876;
let { exec } = require('child_process');
const portToPid = require("./pid-port");
const BRUNO_OAUTH2_SERVER_PORT = 9876;
const BRUNO_OAUTH2_SERVER_CALLBACK_URL = `http://localhost:9876/callback`;
let server;
@@ -31,9 +31,10 @@ const freePort = async () => {
}
async function getOauth2AuthorizationCodeUsingDefaultBrowser({ authorizeUrl, port = BRUNO_OAUTH2_SERVER_PORT }) {
await server?.close?.();
await freePort();
const redirectUri = `http://localhost:${port}/callback`;
await server?.close?.();
// test and refactor before uncommenting
// await freePort();
const redirectUri = BRUNO_OAUTH2_SERVER_CALLBACK_URL;
const parsedAuthorizeUrl = new URL(authorizeUrl);
parsedAuthorizeUrl?.searchParams.set('redirect_uri', redirectUri);
const finalAuthorizeUrl = parsedAuthorizeUrl.href;
@@ -65,4 +66,4 @@ async function getOauth2AuthorizationCodeUsingDefaultBrowser({ authorizeUrl, por
});
}
module.exports = { getOauth2AuthorizationCodeUsingDefaultBrowser };
module.exports = { getOauth2AuthorizationCodeUsingDefaultBrowser, BRUNO_OAUTH2_SERVER_CALLBACK_URL };

View File

@@ -4,7 +4,7 @@ const { authorizeUserInWindow } = require('../ipc/network/authorize-user-in-wind
const Oauth2Store = require('../store/oauth2');
const { makeAxiosInstance } = require('../ipc/network/axios-instance');
const { safeParseJSON, safeStringifyJSON, uuid } = require('./common');
const { getOauth2AuthorizationCodeUsingDefaultBrowser } = require('./oauth2-server');
const { getOauth2AuthorizationCodeUsingDefaultBrowser, BRUNO_OAUTH2_SERVER_CALLBACK_URL } = require('./oauth2-server');
const oauth2Store = new Oauth2Store();
@@ -51,6 +51,7 @@ const getOAuth2TokenUsingAuthorizationCode = async ({ request, collectionUid, fo
credentialsId,
autoRefreshToken,
autoFetchToken,
authorizeInDefaultBrowser
} = oAuth;
const url = requestCopy?.oauth2?.accessTokenUrl;
if (!forceFetch) {
@@ -118,7 +119,7 @@ const getOAuth2TokenUsingAuthorizationCode = async ({ request, collectionUid, fo
const data = {
grant_type: 'authorization_code',
code: authorizationCode,
redirect_uri: callbackUrl,
redirect_uri: authorizeInDefaultBrowser ? BRUNO_OAUTH2_SERVER_CALLBACK_URL : callbackUrl,
client_id: clientId,
};
if (clientSecret && credentialsPlacement !== "basic_auth_header") {