Skip to content

Commit 9ea2c92

Browse files
authored
Merge pull request #66 from Cimpress-MCP/mh/FixLoggingAuth0
use our logger when creating http client in tokenProvider.ts
2 parents 8a60cd2 + f9a4ff8 commit 9ea2c92

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "lambda-essentials-ts",
3-
"version": "7.0.0-beta",
3+
"version": "7.0.1",
44
"description": "A selection of the finest modules supporting authorization, API routing, error handling, logging and sending HTTP requests.",
55
"main": "lib/index.js",
66
"private": false,

src/tokenProvider/tokenProvider.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import jwtManager from 'jsonwebtoken';
22
import { AxiosRequestConfig, AxiosResponse } from 'axios';
33
import HttpClient from '../httpClient/httpClient';
4+
import Logger from '../logger/logger';
45

56
export default abstract class TokenProvider {
67
private httpClient: TokenProviderHttpClient;
@@ -16,6 +17,7 @@ export default abstract class TokenProvider {
1617
this.httpClient =
1718
options.httpClient ??
1819
new HttpClient({
20+
logFunction: (msg) => new Logger().log(msg),
1921
enableCache: false,
2022
enableRetry: true,
2123
retryOptions: {

tests/logger/logger.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,32 @@ describe('log message', () => {
2323
expect(logFunction).toHaveBeenCalledWith(JSON.stringify(receivedObject, null, 2));
2424
});
2525

26+
test('test redacting secret from our http client', () => {
27+
const logObjectWithSecret: SuggestedLogObject = {
28+
title: 'One secret',
29+
level: 'DEBUG',
30+
request: {
31+
client_id: 'baconClientId',
32+
client_secret: 'E5BuCZ8AuBpnDfB25dhgftyuvBcBwDiBBCC5DjBGBeBfjD5BeBqhBFBQDGDp_gSw_',
33+
audience: 'https://api.banana.io/',
34+
grant_type: 'client_credentials',
35+
},
36+
};
37+
testLogger.log(logObjectWithSecret);
38+
const receivedObject: SuggestedLogObject = {
39+
invocationId: 'none',
40+
title: 'One secret',
41+
level: 'DEBUG',
42+
request: {
43+
client_id: 'baconClientId',
44+
client_secret: '<REDACTED>',
45+
audience: 'https://api.banana.io/',
46+
grant_type: 'client_credentials',
47+
},
48+
};
49+
expect(logFunction).toHaveBeenCalledWith(JSON.stringify(receivedObject, null, 2));
50+
});
51+
2652
test('test truncating TOKEN', () => {
2753
const logObjectWithToken: SuggestedLogObject = {
2854
title: 'One TOKEN',

0 commit comments

Comments
 (0)