This repository was archived by the owner on Nov 20, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 406
This repository was archived by the owner on Nov 20, 2025. It is now read-only.
How to set user agent in the auth request ? #1489
Copy link
Copy link
Closed
Labels
priority: p3Desirable enhancement or fix. May not be included in next release.Desirable enhancement or fix. May not be included in next release.type: questionRequest for information or clarification. Not an issue.Request for information or clarification. Not an issue.
Description
our domain is protected with IAP authentication, and its blocking our e2e test.
so we have added API authentication using the code snippet below
import { GoogleAuth } from 'google-auth-library';
const auth = new GoogleAuth();
const url = `${configList.baseURL}/dashboard`;
const targetAudience = "51297171365dbt6s3oc4d09cf.apps.googleusercontent.com";
async function IapAuth() {
try {
console.info(`request IAP ${url} with target audience ${targetAudience}`);
const client = await auth.getIdTokenClient(targetAudience);
const res = await client.request({
url, headers: {
user-Agent: 'e2e.test'
}
});
IAP_token = res.config.headers.Authorization
process.env.IAP_token = IAP_token
console.log(`√ Iap token has been obtained ----> ${JSON.stringify(IAP_token)}`)
} catch (err: any) {
console.error(JSON.stringify(`X ---> ${JSON.stringify(err.message)}`));
process.exitCode = 1;
}
}
But since our domain is protected by DataDome, we need to pass a certain user agent in the request in order to not be blocked by Recaptcha, but the solution above didn't work out since my user agent is not overnight the existing one but it appends with it
and I'm getting
the response below
response: {
config: {
url: 'https://test.net/ch/test/en/accounts/mpre/dashboard',
headers: [Object],
paramsSerializer: [Function: paramsSerializer],
validateStatus: [Function: validateStatus],
responseType: 'json',
method: 'GET'
},
data: {
url: 'https://geo.captcha-delivery.com/captcha/?initialCid=AHrlqAAAAAMAcG9_Htx_-xsAJcnjBA==&cid=y4Yi1XOmjjBKzFYD5yHexjTu9D8m4fr7R8VJ0qXItUW6~ml8Qy29O9I4.35XmXgvk4p9x8GKyoGcSJ2a8xWgXhlzp1qBP1wcuZPGoD8XXA-70sd-l5qy1iIIxQ753Gx&referer=http%3A%2F%2Fim-search-demo-predev.pricehubble.net%2Fch%2Fimmoworlddashboard%2Fen%2Faccounts%2Fmpre%2Fdashboard&hash=9F1FB446984167FE5DE89E73FFEE6E&t=fe&s=32675&e=71208da2bdf44b4b6ce35cd599f70dfd86f153f9cde560aab23d80d53832f711'
},
headers: {
'accept-ch': 'Sec-CH-UA,Sec-CH-UA-Mobile,Sec-CH-UA-Platform,Sec-CH-UA-Arch,Sec-CH-UA-Full-Version-List,Sec-CH-UA-Model,Sec-CH-Device-Memory',
'alt-svc': 'h3=":443"; ma=2592000,h3-29=":443"; ma=2592000',
'cache-control': 'max-age=0, private, no-cache, no-store, must-revalidate',
charset: 'utf-8',
connection: 'close',
'content-length': '463',
'content-type': 'application/json;charset=utf-8',
date: 'Wed, 16 Nov 2022 13:31:58 GMT',
pragma: 'no-cache',
server: 'istio-envoy',
'set-cookie': 'datadome=y4Yi1XOmjjBKzFYD5yHexjTu9D8m4fr7R8VJ0qXItUW6~ml8Qy29O9I4.35XmXgvk4p9x8GKyoGcSJ2a8xWgXhlzp1qBP1wcuZPGoD8XXA-70sd-l5qy1iIIxQ753Gx; Max-Age=31536000; Domain=.pricehubble.net; Path=/; Secure; SameSite=Lax',
via: '1.1 google',
'x-datadome': 'protected',
'x-datadome-cid': 'AHrlqAAAAAMAcG9_Htx_-xsAJcnjBA==',
'x-dd-b': '537',
'x-envoy-upstream-service-time': '39'
},
status: 401,
statusText: 'Unauthorized',
request: {
responseURL: 'https://test.net/ch/test/en/accounts/mpre/dashboard'
}
},
config: {
url: 'https://itest/ch/test/dashboard/en/accounts/mpre/dashboard',
headers: {
Authorization: 'Bearer eyJhbGciOiJSUzI1NaWF0IjoxNjY4NjA1NTE3LCJpc3MiOiJodHRwczovL2FjY291bnRzLmdvb2dsZS5jb20iLCJzdWIiOiIxMTc5NDk1NzQzODI4NTIwOTg3NTEifQ.HtGYf8R1NCE-MEgPDKvLz77gsdDpLPTbHpK26XYm1gAHhelOlObszZBMBbg3OhWc9VLStsg1rIHdv7VTEm3TB-v_orrpeTyQnqI11MvWvNWevJ4mr6KkDjO5AX8TKM9lOs-VBTVmHqWUcS3IADcpgJbExqwN42_0-VOUc0M9Wk_UC8lH0BaSXBwh5YNRkh5iNUnaTEmHa1bsqvV3Dcmhd1Lso3LtLJ80zcYz0nPVpdQdAESXp3nSOxETEdQ-ySFwF4NNZOy5CTp-AuJjmnpqHaGt7wDZGtf3Gux7f6Ps8e0rmZVnSHrK1T-LVtk6Z32yhb2ctM0ZsULIFFCaA2hOsw',
'User-Agent': ' e2e_test' google-api-nodejs-client/8.7.0', -----> need to change this
'x-goog-api-client': 'gl-node/16.15.1 auth/8.7.0',
Accept: 'application/json'
},
paramsSerializer: [Function: paramsSerializer],
validateStatus: [Function: validateStatus],
responseType: 'json',
method: 'GET'
},
code: '401'
}
PLEASE READ: If you have a support contract with Google, please create an issue in the support console instead of filing on GitHub. This will ensure a timely response.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
priority: p3Desirable enhancement or fix. May not be included in next release.Desirable enhancement or fix. May not be included in next release.type: questionRequest for information or clarification. Not an issue.Request for information or clarification. Not an issue.