Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

389
Visualizações
How is -u of curl request is accessed in node js request message?

I have curl request as below,

curl -u user:password http://localhost:3000/user

How do I access the user and password passed in the http request on the server?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

The option -u specifies the username and password for the HTTP Basic Authentication.

It is accessible via the Request-Header Authorization (req.headers.authorization), but is encoded with base64.

The below code will read the header and decode the string, and then store the username and the password in seperate variables.

const b64auth = (req.headers.authorization || '').split(' ')[1] || ''
const strauth = Buffer.from(b64auth, 'base64').toString()
const splitIndex = strauth.indexOf(':')
const login = strauth.substring(0, splitIndex)
const password = strauth.substring(splitIndex + 1)

For more information see Basic HTTP authentication with Node and Express 4

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda