export async function auth()

in poller-lambdas/src/pollers/reuters/auth.ts [15:39]


export async function auth(
	clientId: string,
	clientSecret: string,
): Promise<string> {
	const req = new Request(authUrl, {
		method: 'POST',
		headers: {
			'content-type': 'application/x-www-form-urlencoded',
		},
		body: `grant_type=${grantType}&client_id=${clientId}&client_secret=${clientSecret}&audience=${audience}&scope=${encodeURIComponent(scopes)}`,
	});
	try {
		console.log('Requesting new auth token from Reuters');
		const response = await fetch(req);
		const data = (await response.json()) as unknown;
		const { access_token, expires_in } = AuthSchema.parse(data);
		console.log(
			`Received new auth token from Reuters, expires in ${expires_in} seconds`,
		);
		return access_token;
	} catch (error) {
		console.error(error);
		throw new Error('Failed to get auth token from Reuters');
	}
}