Skip to content

Commit

Permalink
add bearer auth capabilities to http transport; (winstonjs#1662)
Browse files Browse the repository at this point in the history
* add bearer auth capabilities to http transport;

* replace headers clone via spread operator with Object.assign for node 6 compatibility;
  • Loading branch information
georgeonofrei authored and DABH committed Aug 15, 2019
1 parent 7f5e9b2 commit 8b27583
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 6 additions & 2 deletions lib/winston/transports/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,17 @@ module.exports = class Http extends TransportStream {
delete options.path;

// Prepare options for outgoing HTTP request
const headers = Object.assign({}, this.headers);
if (auth && auth.bearer) {
headers['Authorization'] = `Bearer ${auth.bearer}`;
}
const req = (this.ssl ? https : http).request({
method: 'POST',
host: this.host,
port: this.port,
path: `/${path.replace(/^\//, '')}`,
headers: this.headers,
auth: auth ? (`${auth.username}:${auth.password}`) : '',
headers: headers,
auth: (auth && auth.username && auth.password) ? (`${auth.username}:${auth.password}`) : '',
agent: this.agent
});

Expand Down
4 changes: 2 additions & 2 deletions lib/winston/transports/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ declare namespace winston {
ssl?: any;
host?: string;
port?: number;
auth?: { username: string; password: string; };
auth?: { username?: string | undefined, password?: string | undefined, bearer?: string | undefined };
path?: string;
agent?: Agent;
headers?: object;
Expand All @@ -66,7 +66,7 @@ declare namespace winston {
ssl: boolean;
host: string;
port: number;
auth?: { username: string, password: string };
auth?: { username?: string | undefined, password?: string | undefined, bearer?: string | undefined };
path: string;
agent?: Agent | null;

Expand Down

0 comments on commit 8b27583

Please sign in to comment.