Search code examples
google-api-key-restrictionsgoogle-cloud-api-keys

Asign an apiKey as a environment variable in Blazor


I need help. I'm developing a WebApp using Blazor, I use an google map and I got the google apiKey and works fine, but showing the apiKey.

Ex. ApiKey="aaaabbbbbbbbccccccccdddd"

Soon my WebApp will be in Production and I don't want to expose the apiKey, for that reason I wanted asign an environment variable in the lauchSettings.json file, for example:

APIKEY_MAP="aaaabbbbbbbbccccccccdddd"

and asign it in the Razor component. (I'm using radzen components.)

ApiKey=APIKEY_MAP

but it doesn't result... it doesn't recognize the apiKey Somebody can help me? please Thank you...

I tried not to expose the google apiKey. I would like to have an option to use an google apiKey without exposing it.


Solution

  • I am not sure if I understood your question correctly but to access an env variable you would normally do this: ApiKey = Environment.GetEnvironmentVariable("APIKEY_MAP");