Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 448
user606521 Avatar asked Feb 16 '23 09:02

user606521


1 Answers

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

Buffer.from(`${username}:${password}`).toString("base64")
like image 103
Ignacio Vazquez-Abrams Avatar answered May 19 '23 00:05

Ignacio Vazquez-Abrams