user606521
user606521

Reputation: 15454

How to compute Basic Authorization header from username and password

I have username and password and I want to compute Authorization header for HTTP Basic Auth. Computed header looks like this: 'Basic xyz123xxx'. Is there a node package in npm that will allow me to do this?

Upvotes: 7

Views: 5212

Answers (1)

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 799210

Use Buffer to encode the string for use in the header.

Buffer.from(`${username}:${password}`).toString("base64")

Upvotes: 14

Related Questions