Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return (config) => {
const { query, pathname } = url.parse(config.url, true)
const jwtToken = jwt.encode({
...getExpirationInSeconds(),
iss,
qsh: jwt.createQueryStringHash({
method: config.method,
originalUrl: pathname,
query
})
}, secret)
return {
...config,
headers: {
...config.headers,
Authorization: `JWT ${jwtToken}`
}
}
}
}
if (!options.headers) {
options.headers = {}
}
options.headers['Authorization'] = 'Basic ' + this.basic_auth.base64
} else {
options.auth = this.basic_auth;
}
} else if (this.jwt) {
const pathname = new URL(options.uri).pathname;
const nowInSeconds = Math.floor(Date.now() / 1000);
const queryParam = queryString.parse(queryString.stringify(options.qs));
const jwtToken = jwt.encode({
iss: this.jwt.iss,
iat: nowInSeconds,
exp: nowInSeconds + this.jwt.expiry_time_seconds,
qsh: jwt.createQueryStringHash({
method: options.method,
pathname,
query: queryParam || {}
})
}, this.jwt.secret);
if (!options.headers) {
options.headers = {};
}
options.headers['Authorization'] = `JWT ${jwtToken}`;
}
if (this.cookie_jar) {
options.jar = this.cookie_jar;
}
getToken = (method: string = 'get', path: string, iss: string, sharedSecret: string): Promise => {
const iat = Math.floor(Date.now() / 1000);
const exp = iat + 180;
const req: Request = fromMethodAndUrl(method, path);
const tokenData = {
iss,
iat,
exp,
qsh: createQueryStringHash(req),
};
const token = encode(tokenData, sharedSecret);
return token;
};