简体   繁体   English

当我从 angular 调用 api 时,如何将 api 键放在后面

[英]how can I put api key in the back when i call api from angular

In my current Agular app im sending a request to back end and i need to add api key as below:在我当前的 Agular 应用程序中,我向后端发送请求,我需要添加 api 密钥,如下所示:

         let header = new HttpHeaders()
        header = header.append("api-key","jkhjkh") 
        this.http.get(`https://api/${"EUR"}+${"SEK"}`,{headers:header}).subscribe(s=>{....

the problem is im exposing the api key to the user,its shown on the browser which is not secure,i was seraching on the google and found they say you have to put api key on the backend,if i do that how can i call then?please help me with an example or suggestion问题是我将 api 密钥暴露给用户,它显示在浏览器上不安全,我在谷歌上搜索,发现他们说你必须把 api 密钥放在后端,如果我这样做我怎么打电话那么?请帮我举个例子或建议

You need to keep the API-key away from the Angular frontend.您需要将 API 密钥远离 Angular 前端。 If you have an dotnet core backend, create a controller there that wraps your call to the API (with for example HttpClient ) and returns the response.如果您有一个 dotnet 核心后端,请在此处创建一个 controller 来包装您对 API 的调用(例如HttpClient )并返回响应。

Angular <-> backend <-> API 
                    key

Instead of代替

Angular <-> API 
        key

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将 API 数据放入 angular 图表? - How can I put API data to angular chart? How can I add API key to Apollo-Angular to fetch data from mongodb realm GraphQL API - How can I add API key to Apollo-Angular to fetch data from mongodb realm GraphQL API angular 4 _ 如何动态更改谷歌地图 api 密钥 - angular 4 _ how can I change dynamically google map api key 如何使用Angular在一个函数上调用多个API? - How can I call multiple API's on a function with Angular? 如何从 angular 调用 B2C Graph API? - How can I call B2C Graph API from angular? 我的应用程序即将关闭时如何调用API - How can i call an API when my application is going to close 如何使用此处地理编码和搜索 api 从 angular 服务与 API 密钥 - How do I use Here Geocoding and search api from angular service with API key 当我返回相同的路线,角度为6时,重用api中的数据 - Reuse data from api when i get back same route, angular 6 如何在Angular 7中使用Chrome中的PasswordCredential API - How can i use the PasswordCredential API from Chrome in Angular 7 如何从 Angular 中的宁静 API 获得 JSON? - How can I obtain a JSON from a restful API in Angular?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM