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

153
Visualizações
How can we initiate a file download request tied to a user gesture with an auth header?

We are trying to build a web page that shows a button to download an XML file. The file is retrieved by making a request to a REST endpoint that requires a Bearer Token in the auth header.

We made a button with onclick function like this:

var myHeaders = new Headers();
myHeaders.append("Authorization", "Bearer <bearer token here>")

var requestOptions = {
  method: 'GET',
  headers: myHeaders,
};

fetch('<url>', requestOptions)
  .then(resp => resp.blob())
  .then(blob => {
    const url = window.URL.createObjectURL(blob);
    const a = document.createElement('a');
    a.style.display = 'none';
    a.href = url;
    // the filename
    a.download = 'todo-1.json';
    document.body.appendChild(a);
    a.click();
    window.URL.revokeObjectURL(url);
    alert('your file has downloaded!');
  })
  .catch(() => alert('Error')); 

Reference for above code

This seems to work great in most browsers, however, on Edge this download is blocked by Microsoft Defender SmartScreen, because it is not tied to a user gesture.

How can we initiate a file download request tied to a user gesture with an auth header?

We know we could change the auth mechanism so that it accepts the auth token from a cookie or the body of the request, but we don't want to do this.

about 4 years ago · Juan Pablo Isaza
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