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 ?
Related
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 }) => {
...
})
I was trying to proxy requests to my backend. Going through docs, I found out that we can add a rewrite() function in config,
module.exports = {
basePath: "",
distDir: "build",
trailingSlash: true,
images: {
domains: ["localhost"],
},
async rewrites() {
return {
beforeFiles: [
{
source: "/api/:path*",
destination: "http://localhost:3001/todos/:path*",
},
],
};
},
};
I tried this but it fails .It fires two request to API for one each, here the first request says 308 permanent redirect, and the second request says 404. And thats it, it does not requests the api.
Can someone help me?
I know that I can use the access token that I receive in the response can be use to authenticate users.
But I want it to be more secure So I want the code that we get in oAuth 2.0.
Is there any way to get the code in the background to authenticate the user in one tap sign In?
An authorization code response that we get from the server is like this in url:
https://oauth2.example.com/auth?code=4/P7q7W91a-oMsCeLvIaQm6bTrgtp7
componentDidMount() {
this.registerNewUser();
}
retrievePromise() {
window.googleyolo.retrieve({
supportedAuthMethods: [
'https://accounts.google.com',
],
supportedIdTokenProviders: [
{
uri: 'https://accounts.google.com',
// Replace with your client Id
clientId: 'XXX...XXX.apps.googleusercontent.com',
},
],
});
}
// eslint-disable-next-line class-methods-use-this
registerNewUser() {
window.googleyolo.hint({
supportedAuthMethods: [
'https://accounts.google.com',
],
supportedIdTokenProviders: [{
uri: 'https://accounts.google.com',
// Replace with your client Id
clientId: 'XXX...XXX.apps.googleusercontent.com',
}],
context: 'signUp',
}).then((credential) => {
console.log(credential);
this.props.doGoogleLogin('login');
this.props.decideWhichSocialLogin(this.props.location);
/* hit backend api and API TOKEN here */
/* Also save basic details that we get here */
}, (error) => {
console.log('Error occurred: ', error.type);
});
}
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.
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.