简体   繁体   中英

Hide Google Map API Key in Blazor WASM application

I have a Blazor WASM app using the Google Map API. Everything it working as it should but the Google Map API is exposed in the wwwroot\Index.html per instructions. I am looking to move it out of the index.html but I am unclear as to were I should set the key.

<-- Index.html -->
<html>

<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <base href="/" />
    <link href="css/bootstrap/bootstrap.min.css" rel="stylesheet" />
    <link href="css/app.css" rel="stylesheet" />
    <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=<My Google API Key>=initMap"></script>```

This is not specifically Blazor issue. However, as per comments in your question, you can add website or IP restriction in your google cloud platform. Go to the page where you generated your API key. So even if someone has your API key, they can not use it on their website.

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM