SOCKS5 Proxy Authentication in Google Chrome Extension - javascript

I'm trying to create a extension which would use my SOCKS5 proxy with authentication.
Code in my background script is like this:
var config = {
mode: "fixed_servers",
rules: {
fallbackProxy: {
scheme: "socks5",
host: "myhostaddress"
}
}
};
chrome.proxy.settings.set(
{ value: config, scope: 'regular' },
function () { });
chrome.webRequest.onAuthRequired.addListener(
function (details) {
console.log("onAuthRequired!", details);
return ({
authCredentials: {
'username': "uname",
'password': "pass"
}
});
},
{ urls: ["<all_urls>"] },
['blocking']
);
But I always get ERR_SOCKS_CONNECTION_FAILED error on each page...
What am I doing wrong?

As stated in thread, Chrome doesn't support SOCKS5 proxy with authentication. The only browser that might be supported is Maxthon browser.

Related

Chrome extension proxy authentication: error net::ERR_TUNNEL_CONNECTION_FAILED

I'm trying to use the chrome.proxy API to change the proxy in a Chrome extension, and in order to use the authentication, I listen to the chrome.webRequest.onAuthRequired event, in order to intercept the request and add the credentials to it, as follows:
background.js
chrome.webRequest.onAuthRequired.addListener(function (details, callbackFn) {
callbackFn({
authCredentials: {
'username': myUsername,
'password': myPassword
}
});
}, {urls: ["<all_urls>"]}, ['asyncBlocking']);
And to change the proxy, I do it inside an internal page of the extension, as follows:
let config = {
mode: "fixed_servers",
rules: {
singleProxy: {
host: 1.1.1.1,
scheme: 'http',
port: 80,
},
},
};
chrome.proxy.settings.set({
value: config,
scope: "regular"
}, function () {
console.log('Changed the proxy!');
});
In the manifest.json I have the permissions:
"permissions": [
"proxy",
"tabs",
"webRequest"
],
The problem is:
the credentials dialogue still shows up, and I get the following error inside the chrome.proxy.onProxyError event:
{
"details": "",
"error": "net::ERR_TUNNEL_CONNECTION_FAILED",
"fatal": true
}
What am I doing wrong here ?

cypress.origin throws error: (uncaught exception)Error: on only accepts instances of Function

I am using Cypress with Cucumber.
I am trying to test cross origin login but the origin method keeps on throwing error:
Code:
Given(/^the user login to the Test Page$/, function () {
cy.visit("https://example-originalURL");
cy.get("button").contains("Login").click();
const credentials = {
username: "hello",
password: "user",
};
cy.origin("https://example-newURL", { args: credentials }, ({ username, password }) => {
cy.get("#email", { timeout: 20000 }).type(username);
cy.get("#password").type(password, { log: false });
cy.get("button").contains("Login").click();
});
});
Cypress.config.js
module.exports = defineConfig({
projectId: "t7unhv",
e2e: {
setupNodeEvents(on, config) {
on("file:preprocessor", cucumber());
on('task', {
log(message) {
console.log(message +'\n\n');
return null;
},
});
},
specPattern: "./cypress/e2e/features/*.feature",
chromeWebSecurity: false,
experimentalSessionAndOrigin: true,
defaultCommandTimeout: 15000,
env: {
devCentralUrl: "https://***.dev.***.com.au/login",
testCentralUrl:
"https://***.test.***.com.au/login",
test***: "http://***.test.***.com.au",
dev***: "http://***.dev.***.com.au",
uat***: "https://***.uat.***.com.au",
dataSource: "",
environs: "test",
},
retries: {
runMode: 0,
},
pageLoadTimeout: 15000,
reporter: "mochawesome",
reporterOptions: {
reporterEnabled: "mochawesome",
mochawesomeReporterOptions: {
reportDir: "cypress/reports/mocha",
quite: true,
charts: true,
overwrite: false,
html: false,
json: true,
},
},
},
});
Error:
The following error originated from your test code, not from Cypress.
> on only accepts instances of Function
When Cypress detects uncaught errors originating from your test code it will automatically fail the current test.
I have tried multiple syntax changes like not passing the credentials as optional argument to cy.origin.
If someone can provide a quick help, that will be great.
If the problem is in the test code, it is likely to be that newURL is undefined. The error message suggests the problem is in the app, but that might be a red herring.
Try just adding a fixed string for the cy.origin() key,
cy.origin('login', { args: credentials }, ({ username, password }) => {
...
})

Vuejs-nuxt (SSR Mode) not able to get UserUUID through getter inside plugins. It shows undefined for GetUserUUID

I'm using SSR mode in my vuejs-nuxt project. So whenever I attempt to call socket event, I need to pass userID to that socket from the store. The GetUserUUID getter works fine in all other APIs. But it fails only in case of calling from the "plugin/socketio.js" file. I need some help to get data from the getter.
plugins/socketio.js
export default async ({ store, $axios }) => {
console.log(store.getters.GetUserUUID,"Current User UUID which is showing undefined");
function listenStock({ channelName, eventName }, callback) {
console.log("callback",callback);
window.Echo.channel(channelName).listen(eventName, callback);
}
//Fetch user data
listenStock(
{
channelName: `BalanceUpdateEvent.${store.getters.GetUserUUID}`,
eventName: "BalanceUpdateEvent"
},
({ data }) => {
console.log(data, "socket data");
try {
store.dispatch("setUserBalance", data.data.userBalance);
} catch (ex) {
console.log(ex);
}
}
);
nuxt.config.js
plugins: [
{ src: '~/plugins/socketio', mode: 'client' }
]
echo: {
plugins: ['~/plugins/socketio.js']
},
This image is a result of console.log(store.getters), But I need to access GetUserUUID.
Please try it in the nuxt.config.js
export default {
plugins: [
....
{ src: '~/plugins/socketio.js', mode: 'client' }, // only on client side
...
]
}
That run your plugin in client side

Changing credentials to a proxy server on the fly

I'm developing an extension for chrome. The extension allows to pick any proxy server from a list, each proxy is required authorization. There is an issue when a user would like to connect to the same proxy server twice but with different credentials for example if a user was successfully logged in the first time the chrome remembers it and when the user would try to connect with other credentials the chrome would use credentials that were inputted in the first login.
var authCredentials = {
username: 'Jack',
password: 'PassForJack'
}
var auth = function () {
return {
authCredentials
};
};
chrome.webRequest.onAuthRequired.addListener(auth, {
urls: ["<all_urls>"]
}, ["blocking"]);
// set a new proxy server for the first login
chrome.proxy.settings.set({
value: {
mode: 'fixed_servers',
rules: {
singleProxy: {
host: 'some-proxy-server.com',
port: 8000
}
}
},
scope: 'regular'
});
// change credentails
authCredentials = {
username: 'Bob',
password: 'PassForBob'
};
// remove proxy configuration
chrome.proxy.settings.set({
value: {
mode: 'direct'
},
scope: 'regular'
});
// remove onAuthListener
chrome.webRequest.onAuthRequired.removeListener(auth)
chrome.webRequest.onAuthRequired.hasListener(auth) // returns false
chrome.webRequest.onAuthRequired.addListener(auth, {
urls: ["<all_urls>"]
}, ["blocking"]);
// lets re connect
chrome.proxy.settings.set({
value: {
mode: 'fixed_servers',
rules: {
singleProxy: {
host: 'some-proxy-server.com',
port: 8000
}
}
},
scope: 'regular'
});
// that doesn't help the user would be logged as "Jack" but has to be as "Bob"
There are multiple possibilities here since the question is not very clear. I would suggest to walk through documentation for the chrome.webRequest first. But My question would be why don't you use interceptor method to check for server-credential pair ? There's a good article about adding interceptor in the background.js script of your extension which suggests to use the beforeRequest hook.

hello.js: Is it possible to set the provider's settings dynamically?

I have implemented a new module for hello.js.
I need the auth, grant and base to be dynamic.
Is there a way to set/override these values from the hello.init() call?
My module looks like this:
(function(hello) {
hello.init({
my_service_name: {
name: 'My-Service-Name',
oauth: {
version: 2,
auth: 'http://mydomain/oauth/authorize',
grant: 'http://mydomain/oauth/token'
},
scope: {
basic: ['basic_scope']
},
base: 'http://mydomain/',
xhr: function(p) {
if (p.method !== 'get' && p.data) {
// Serialize payload as JSON
p.headers = p.headers || {};
p.headers['Content-Type'] = 'application/json';
if (typeof (p.data) === 'object') {
p.data = JSON.stringify(p.data);
}
}
return true;
}
}
});
})(hello);
and my hello.init() call:
hello.init({
my_service_name: server.consumerKey
}, {
redirect_uri : server.callbackUrl,
});
The use-case is that the application I am developing will communicate with several servers, so I cannot hardcode the URLs in the module's file.
I figured out that I can override the default settings by passing the whole oauth object in the hello.init() call:
hello.init({
my_service_name: {
id: server.consumerKey,
oauth: {
version: 2,
auth: server.auth_url,
grant: server.token_url
},
base: server.baseUrl
}
}, {
redirect_uri : server.callbackUrl
});

Categories

Resources