Changing credentials to a proxy server on the fly - javascript

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.

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 ?

invalid-dynamic-link-domain - Firebase Auth

I would like to use the activation email link on localhost. But getting an error auth/invalid-dynamic-link-domain. Here's my configuration which I later pass to sendSignInLinkToEmail method
const actionCodeSettings = {
url: 'exp://192.168.18.30:19001',
handleCodeInApp: true,
iOS: {
bundleId: 'xxx.xxx.xxx'
},
android: {
packageName: 'xxx.xxx.xxx'
installApp: true,
minimumVersion: '12'
},
dynamicLinkDomain: 'http://192.168.18.30:19001/activation'
};
Im not sure If I understand correctly idea of dynamic link...But I can't skip this param

Set clientId in swagger ui nestjs oauth2

The ultimate goal (which works if clientId is provided and scopes are clicked): Use Swagger UI to get the azure Auth to receive an accessToken for further requests.
Since the client_id and scopes are static I was hoping to bypass the popup and immediately trigger what happens when clicked on the Authorize button by pre setting the client_id and scopes, since I couldn't find anything there I am atleast trying to pre fill the form so the user only has to click Authorize in my organisation.
What I tried without success:
swagger options initOAuth
DocumentBuilder.components.requestBodies
The Code in main.ts of nestjs:
// Swagger
const config = new DocumentBuilder()
.setTitle('Auth Backend')
.setDescription('Azure PoC backend')
.setVersion('0.1')
.addTag('auth')
.addOAuth2({
type: "oauth2",
description: "description",
name: "AzureAD",
flows: {
implicit: {
scopes: { "User.Read": "Read user profile" },
authorizationUrl: `https://login.microsoftonline.com/${process.env.TENANT_ID}/oauth2/v2.0/authorize`,
}
}
}, "AzureAD")
.build()
const document = SwaggerModule.createDocument(app, config)
SwaggerModule.setup('swagger', app, document, {initOAuth: {clientId: process.env.CLIENT_ID, clientSecret: process.env.CLIENT_SECRET}});
Please try by including swaggerOptions in SwaggerModule.setup which can pass swaggerOptions into swaggerUi.generateHTML
SwaggerModule.setup('api', app, document, { customSiteTitle: 'Your API name', swaggerOptions: {
oauth: {
clientId: clientid",
clientSecret: "clientsecret",
realm: "your-realms",
appName: " ",
scopeSeparator: " ",
scopes: ["User.Read", "profile",”offline_access”],
…. },
persistAuthorization: true, }, });
For the latest versions: ( as given by #julianklumpers in Access swagger-ui after setup to initialize oauth2 -nest.js· Issue · GitHub)
SwaggerModule.setup('api', app, document, {
customSiteTitle: 'API',
swaggerOptions: {
persistAuthorization: true,
oauth2RedirectUrl: 'https://…….’,
initOAuth: {
ClientId,
ClientSecret,
scopes: ["User.Read", "profile",”offline_access”],
appName: ‘name of the app',
},
},
});
Reference: swagger-ui oauth2 · GitHub

How to use OAuth 2.0 flow in Google One tap Sign In?

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);
});
}

SOCKS5 Proxy Authentication in Google Chrome Extension

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.

Categories

Resources