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

347
Visualizações
Hide API token from generated .cshtml page source code

I have a .cshtml page, where a click on a button calls an API

Currently, my JS code looks like :

var headers = {};
headers["Authorization-Token"] = '@Model.ApiToken';

$.ajax({
    url: "my-url",
    type: "GET",
    headers: headers
});

However, if the end-user opens the browser console, goes to the Network tab, searches for the generated cshtml, he can see :

var headers = {}
headers[Authorization-Token] = 'my_token'

The token can be seen in clear text I can't call my API without this header, as the call is immediately rejected if the header is not present.

Is there a way to hide it to the end-user, and if so, how ?
Thank you

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

It is better to keep the tokens outside the browser, one option is to store the token inside the cookie (encrypted of course). ASP.NET Core can handle that for you automatically. Or in the backend as part of the user session.

An perhaps better option is to look at using the Backend For Frontend (a.k.a BFF) pattern to secure SPA applications.

See

  • Backend For Frontend Authentication Pattern with Auth0 and ASP.NET Core
  • The BFF Pattern (Backend for Frontend): An Introduction
  • Securing SPAs using the BFF Pattern (once and for all)
about 4 years ago · Juan Pablo Isaza 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