Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

345
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!