A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developers.google.com/maps/api-key-best-practices below:

Google Maps Platform security guidance

Apps and projects that use the Google Maps Platform APIs and SDKs must use API keys or, if supported, OAuth 2.0, to authenticate themselves.

These best practices show you how to secure your Maps Platform access.

If you want to use OAuth 2.0 to authorize server-to-server traffic, look for the OAuth topic in your API documentation. See Use OAuth for server-side apps for more details.

Important: Restrict you API keys to prevent unauthorized usage. You are financially responsible for charges caused by abuse of unrestricted API keys.

In addition to applying application and API key restrictions, follow any security practices that apply to specific Google Maps Platform products. For example, see the Maps JavaScript API below in Recommended application and API restrictions.

If your API keys are already in use, review the recommendations below in If you are restricting an API key that's in use.

For more details about digital signatures, supported by Maps Static API and Street View Static API, see the Digital Signature Guide.

Recommended best practices

For increased security and to avoid being billed for unauthorized use, follow these API security best practices for all Google Maps Platform APIs, SDKs, or services:

Recommended for all API key uses

Restrict your API keys

Use separate API keys for each app

Delete unused API keys

Check your API key usage

Be careful when rotating API keys

Split client-side and server-side usage into separate projects

Disable unused services

Additional recommendations for client-side apps

Use client-side SDKs

Secure client-side web service calls

Additional recommendations for websites or client-side apps using Static Web APIs

Protect Static Web API usage

Additional recommendations for server-side apps using web services

Protect web service API keys

Use OAuth for server-side apps

If you are restricting or rotating an API key that's in use More information

Recommended application and API restrictions

Restrict your API keys Tip: If you are restricting an API key that's already in use, also see section If you are restricting or rotating an API key that's in use.

Best practice is to always restrict your API keys with one type of application restrictions and one or more API restrictions. For suggested restrictions by API, SDK, or JavaScript service, see Recommended application and API restrictions below.

Set an application restriction for an API key
  1. Open the Google Cloud console Google Maps Platform Credentials page.

  2. Select the API key that you want to restrict.

  3. On the Edit API key page, under Key restrictions, select Set an application restriction.

  4. Select one of the restriction types and supply the requested information following the restriction list.

    Restriction type Description Websites Specify one or more referrer websites. IP addresses Specify one or more IPv4 or IPv6 addresses, or subnets using CIDR notation. The IP addresses must match the source address the Google Maps Platform servers observe. If you use network address translation (NAT), this address typically corresponds to your machine's public IP address. Android apps

    Add the Android package name (from the AndroidManifest.xml file) and the SHA-1 signing certificate fingerprint of each Android application you want to authorize.

    1. Select Android apps.
    2. Click + Add.
    3. Enter your package name and SHA-1 certificate fingerprint. For example:
      com.example.android.mapexample
      BB:0D:AC:74:D3:21:E1:43:67:71:9B:62:91:AF:A1:66:6E:44:5D:75
    4. Click Save.

    There are two certificate types:

    For more information about Android application signing and certificates, see the Sign your app guide.

    If you use Play App Signing, to fetch the signing certificate fingerprint, see Working with API Providers. If you manage your own signing key, see Self-signing your application or refer to the instructions for your build environment.

    iOS apps

    Add the bundle identifier of each iOS application you want to authorize.

    1. Select iOS apps.
    2. Click + Add.
    3. Add the bundle ID to accept requests from the iOS app with that ID.
    4. Click Save.

    For recommendations for an application restriction, see Recommended application Restriction.

  5. Select Save.

Set API restrictions for an API key
  1. Open the Google Cloud console Google Maps Platform Credentials page.

  2. Select the API key that you want to restrict.

  3. On the Edit API key page, under API restrictions:

    If an API or SDK is not listed, you need to enable it. For details, see To enable one or more APIs or SDKs.

  4. Select Save.

    The restriction becomes part of the API key definition after this step. Be sure you provide the appropriate details and select Save to save your API key restrictions. For further information, see the Get an API Key guide in the documentation for the specific API or SDK you are interested in.

For recommended API restrictions, see Recommended API Restrictions.

Check your API key usage

If you're restricting API keys after they've been created, or if you want to see what APIs are being used by a key so you can restrict them, you want to check your API key usage. These steps show you in which services and API methods an API key is being used. If you see any usage beyond Google Maps Platform services, investigate to determine if you need to add more restrictions to avoid unwanted use. You can use the Google Maps Platform Cloud Console Metrics explorer to help determine which API and application restrictions to apply to your API key:

Tip: If you don't see all chart labels when you open the Metrics explorer, see these topics in the Google Maps Platform Cloud Console Metrics explorer help: Toggling the chart's full legends and Show all legend columns. Determine the APIs that use your API key

The following metrics reports allow you to determine which APIs are using your API keys. Use these reports to do the following:

When applying API restrictions, use these reports to create a list of APIs to authorize, or to validate automatically-generated API key restriction recommendations. For more information about recommended restrictions, see Apply recommended restrictions. For more information about using the Metrics explorer, see Create charts with Metrics explorer .

  1. Go to the Google Cloud console's Metrics explorer

  2. Sign in and select the project for the API keys you want to check.

  3. Go to the Metrics explorer page for your type of API:

  4. Inspect each API key:

    1. Select ADD FILTER.

    2. Select the label credential_id.

    3. Select the value corresponding to the key you want to inspect.

    4. Note which APIs this API key is being used for, and confirm the use is expected.

    5. Once done, select Remove filter delete at the end of the active filter line to delete the extra filter.

  5. Repeat for any remaining keys.

  6. Restrict your API keys to only the APIs that are being used.

  7. If you spot unauthorized use, see Handle unauthorized use of an API key.

Choose the correct type of application restriction using the Metrics explorer

After you have verified and taken any needed actions to make sure your API key is only used for the Google Maps Platform services it is using, also verify the API key has the correct application restrictions.

If your API key has recommended API key restrictions, apply them. For more information, see Apply recommended API key restrictions.

If your API key doesn't have restriction recommendations, determine the type of application restriction to apply, based on the reported platform_type using the Metrics explorer:

  1. Go to the Google Cloud console's Metrics explorer

  2. Sign in and select the project for the APIs you want to check.

  3. Go to this Metrics explorer page: Metrics explorer.

  4. Inspect each API key:

    1. Select ADD FILTER.

    2. Select the label credential_id.

    3. Select the value corresponding to the key you want to inspect.

    4. Once done, select Remove filter delete at the end of the active filter line to delete the extra filter.

  5. Repeat for any remaining keys.

  6. Once you have the platform type for your API keys, apply the application restriction for that platform_type:

    PLATFORM_TYPE_JS : Apply Website restrictions on the key.

    PLATFORM_TYPE_ANDROID : Apply Android application restrictions on the key.

    PLATFORM_TYPE_IOS : Apply iOS application restrictions on the key.

    PLATFORM_TYPE_WEBSERVICE : You may have to rely on IP address restrictions on the key, to properly restrict it.

    For recommendations for Maps Static API and Street View Static API, see Protect Static Web API usage.

    For Maps Embed API recommendations, see Websites with the Maps Embed API.

    My API key is using multiple platform types: Your traffic can't be properly secured with just a single API key. You need to migrate to multiple API keys. For more information, see Migrate to multiple API keys.

Use separate API keys for each app

This practice limits the scope of each key. If one API key is compromised, you can delete or rotate the impacted key without needing to update your other API keys. You can create up to 300 API keys per project. For more information, see Limits on API keys.

While one API key per application is ideal for security purposes, you can use restricted keys on multiple apps as long as they use the same type of application restriction.

Apply recommended API key restrictions Tip: To receive important updates about these automated API key restriction recommendations, star the public issue 286524779.

For some project owners, editors and API key administrators, the Google Cloud console suggests specific API key restrictions to unrestricted API keys based on their Google Maps Platform usage and activity.

Caution: If also use your API key on services other than Google Maps Platform (such as Cloud), you should only apply restrictions after a thorough manual review.

If available, recommendations appear as pre-filled options on the Google Maps Platform Credentials page.

Important: The list of recommendations may be incomplete. Make sure to double-check your API key usage following the Google Cloud console instructions, and Check your API key usage before you apply the recommendations. Google Maps Platform APIs and SDKs supported by the automated recommendations Reasons you may not see a recommendation, or an incomplete one Reasons for seeing no recommendation Reasons for seeing an incomplete recommendation Reasons you might see recommendations that are not visible in the charts To apply recommended restrictions
  1. Open the Google Cloud console Google Maps Platform Credentials page.

  2. If available, select Apply recommended restrictions.

    Note: If you don't see any recommended restrictions, see Set API restrictions for an API key to set appropriate restrictions.
  3. Select Check API usage to verify which services the API key is being used on. If you see other than Google Maps Platform services, pause to manually review the recommendation steps above. See the troubleshooting steps at the beginning of section Apply recommended API key restrictions.

  4. Double-check that the pre-filled restrictions match the websites and apps where you expect to use your API key.

    Best Practice: Document and remove any application or API restrictions that are not affiliated with your services. If something breaks due to an unexpected dependency, then you can add the required apps or APIs back in.

  5. Select Apply.

What to do if your application gets rejected after applying a recommendation

If you notice that an app or website gets rejected after applying a restriction, look for the application restriction you need to add in the API response error message.

Client-side SDKs and APIs
Browser and webview based apps
Caution: Exotic referrer URI schemes (i.e., not HTTPS or HTTP) are not well supported, and should be avoided if possible. Unless noted otherwise, don't expect Google Maps Platform service or APIs to support other referrer URI schemes that HTTPS or HTTP.

Modern browsers typically redact the Referer header in cross-origin request for privacy reasons, often stripping it down to the Origin. However, the exact behavior depends on the applied referrer-policy of the hosting site, and may also vary, based on the user browser and version.

Web applications using opaque or local URI schemes for loading content will typically have the rendering browser or webview completely redact the Referer header from any outgoing calls, which may cause requests to fail using API keys with website restrictions.

For further guidance, see Host your browser based apps on a server.

Troubleshooting instructions for browser and webview based apps:

Android apps

Use Android Debug Bridge (adb) or Logcat

iOS apps

See Viewing Log Messages

Apps calling web services directly

For applications calling Maps Platform HTTPS REST API or gRPC endpoints directly without a client-side Google Maps Platform SDK, see below:

Android and iOS apps

If your Android or iOS application calls Maps Platform services directly without using any of the available Google Maps Platform client SDKs, see Android apps and iOS apps for further troubleshooting tips, and Secure client-side web service calls for current best security practices for mobile use cases.

If your app logs Maps Platform API error responses, the above instructions for client-side SDKs may also prove useful for troubleshooting authentication issues.

Server-side apps

Server-side applications relying on API keys are best secured through IP address restrictions. If you have applied IP address restrictions to your key, and your service logs Maps Platform API error responses, check your system logs for further information. The error response will include the server IP address that you need to authorize.

Browser or webview based apps

While Maps Static API, Street View Static API more recent Google Maps Platform APIs will also support referrer restrictions, note that web browsers or webviews will likely restrict the Referer header to the Origin for cross-origin requests, and will likely omiy sending it altogether, e.g., for locally accessed resources, or for resources served over protocols other than HTTP or HTTPS.

If you can't use Maps JavaScript API in your application, and website restrictions don't work, see Secure client-side web service calls for how to issue Maps Platform web service calls securely from within your browser based client-side application.

Tips for checking API restrictions

To check your required API restrictions, see Determine the APIs that use your API key.

If you are unable to determine which restrictions to apply:

  1. Document the current restrictions for future reference.
  2. Remove them temporarily while you investigate the issue. You can check your usage over time using the steps in Check your API key usage.
  3. If needed, contact support.
Delete unused API keys Important: Check your API key usage before deleting it.

Before you delete an API key, make sure that it is not used in production. If there is no successful traffic, the key is likely safe to delete. For more information, see Check your API key usage.

To delete an API key:

  1. Open the Google Cloud console Google Maps Platform Credentials page.

  2. Select the API key you want to delete.

  3. Select the Delete button near the top of the page.

  4. On the Delete credential page, select Delete.

    Deleting an API key takes a few minutes to propagate. After propagation completes, any traffic using the deleted API key is rejected.

Important: If you have deleted a key that is still used in production and need to recover it, see Undelete an API key. Be careful when rotating API keys Important: Check your API key usage before rotating it.

Rotating an API key creates a new key that has all the old key's restrictions. During this time window, both the old and new key are accepted, giving you a chance to migrate your apps to use the new key.

Before rotating an API key:

If the preceding suggestions aren't possible, and you must rotate your API key to prevent unauthorized use, then follow these steps:

  1. Open the Google Cloud console Google Maps Platform Credentials page.

  2. Open the API key you want to rotate.

  3. At the top of the page, select Rotate key.

  4. Optionally, change the API key name.

  5. Select Create.

  6. Update your applications to use the new key.

After you have updated your applications to using the new key, delete the old key by clicking the Delete the previous key button under the Previous Key section of the new API key page.

Important: Check your API key usage before deleting your old key, to verify that you have migrated all your applications. Migrate to multiple API keys

To migrate from using one API key for multiple apps to a single unique API key for each app, do the following:

  1. Identify which apps need new keys:

  2. Create and restrict the new keys: Add both an application restriction and at least one API restriction. For more information, see Recommended best practices.

  3. Add the new keys to your apps: For mobile apps, this process may take months until all of your users update to the latest app with the new API key.

Important: While you can secure API keys after they're created and in use, in mobile apps (Android and iOS), keys aren't replaced until customers update their apps. Updating or replacing keys in JavaScript or web service apps are much more straightforward, but it still may require careful planning and fast work. For more information, see If you are restricting or regenerating an API key that's in use. Split client-side and server-side usage into separate projects

If you need to call Google Maps Platform services both from server-side applications and directly from client-side applications running end-user devices, Google recommends splitting up your usage between two separate projects.

This approach lets you apply appropriate per-minute, per-user quota limits on most Google Maps Platform services on your client-side project, helping to make sure all end users get their fair share of your overall project quota without impacting each other.

However, since per-user quota restrictions impact both client-side and server-side applications, if you also require high bandwidth for your server-side jobs, set up a separate project for this use case, configured with a higher per-user quota limit, or no limit at all.

Disable unused services

Don't leave unused services enabled on a project, as this practice is vulnerable to abuse, especially if you have not restricted all your public API keys. As a best practice, only enable a service on a project once it is needed by your applications.

Adding API restrictions on a key prevent its use on services that it hasn't been authorized for, but API restrictions only apply to that specific key. Disable a service at the project level to prevents unauthorized use of the service on any key linked to the project.

Use client-side SDKs

When using provided client-side Google Maps Platform SDKs, you will always be able to apply proper restrictions to your API key to secure your service usage.

Using client-side SDKs will also allow you to adopt more advanced security mechanism, such as Firebase App Check on the Maps Platform API surfaces that support it. See Use App Check to secure your API key for further details.

If client-side SDKs are not available for your platform, see Secure your client-side web service calls.

For the availability of client-side Google Maps Platform SDKs for different platforms, see Recommended application and API restrictions.

Protect Static Web API usage Important: Apply both website and API restrictions to a Static Web API key, if the key is publicly exposed on your web page, for example, inside an HTML <img> tag used for displaying a static map or Street View panorama.

Static Web APIs, such as the Maps Static API and Street View Static API, are similar to web service API calls.

You call both using an HTTPS REST API, and you typically generate the API request URL on the server. However, instead of returning a JSON response, Static Web APIs generate an image that you can embed in generated HTML code. More importantly, it is generally the end-user client, not the server, that calls the Google Maps Platform service.

Tip: For more information about securing your Static Web APIs, see the blog post, Securing API keys when using Static Maps and Street View APIs. Use a digital signature

As a best practice, always use digital signatures in addition to an API key. Also, review how many unsigned requests you want to allow per day and adjust your unsigned request quotas accordingly.

For more details about digital signatures, see the Digital Signature Guide.

Protect your signing secret Important: Always sign your requests server-side, not on the client. If you for example, do the signing client-side in JavaScript, you expose it to anyone visiting your site.

To protect Static Web APIs, don't embed your API signing secrets directly in code or in the source tree, or expose them in client-side applications. Follow these best practices for protecting your signing secrets:

Protect web service API keys Warning: Web service API keys are not expected to be publicly exposed to unauthorized users or untrusted applications or devices! The keys are meant to remain a shared secret between the developer's servers and Google.

For secure use of Google Maps Platform APIs and services from client-side apps, see Use client-side SDKs and Secure client-side web service calls.

Store API keys outside of your application's source code or source tree. If you put your API keys or any other information in environment variables or include files that are stored separately and then share your code, the API keys are not included in the shared files. This is particularly important if you use a public source code management system, such as GitHub.

To help shield your web service API key against accidental use, Google recommends applying API restrictions to any key used for Maps Platform. Furthermore, also applying IP address restrictions to your web service key will protect it against help protect it against unauthorized use from other source IP addresses, even if the key accidentally leaks.

Use OAuth for server-side apps

OAuth 2.0 is an open standard for access delegation.

Warning: Even if a Maps Platform API might support OAuth, never expose service account keys in a client-side application that may be run by untrusted end users or on untrusted end user devices.

While the OAuth 2.0 protocol supports use cases, where an end user authorizes an application to access personal data on their behalf, the intended use case for OAuth 2.0 with Maps Platform is for the developer to utilize temporary access tokens for authorizing their application to call an API on behalf of their Google Cloud project service account with the permissions of the service account.

As a service account may have extremely broad permissions, OAuth 2.0 is recommended for authorizing server-to-server calls between a developer's trusted server-side applications and Google's Maps Platform servers.

For client-side applications running on end user devices, other authentication methods, such as API keys, are recommended.

If you want to use OAuth 2.0 to authorize server-to-server traffic, look for the OAuth topic in your API documentation.

For example, here is the OAuth topic for the Address Validation API.

Secure client-side web service calls Important: If a client-side SDK is available for a Maps Platform service on your platform, use it instead! See Use client-side SDKs.

If client-side SDKs are not available, see the recommendations below.

Use a proxy server

Using a secure proxy server provides a solid source for interacting with a Google Maps Platform web service endpoint from a client-side application without exposing your API key, signing secret or Google Cloud service account to unauthorized users.

Tip: For Maps Static API and Street View Static API it is enough for your server to just generate the signed request URL. If the request signing logic is implemented in a proxy server, it can just issue a HTTP redirect to the client using the newly signed request URL.
This approach can, e.g., be used together with a mobile application that uses the static web APIs.

Key points:

Important: Always require authentication for client access to the proxy servers.

For more information about using a proxy server, see Living Vicariously: Using Proxy Servers with the Google Data API Client Libraries.

Secure direct mobile web service calls Important: Use a separate API key for your client-side web service calls, and store it in a secure keystore! This step makes it harder to scrape API keys and other private data directly from the application.

If you are unable to set up a secure proxy server for your client-side app, secure your application using the following steps:

  1. Use HTTP headers:

  2. Add the corresponding application restrictions to your Android or iOS key.

    Important: Android and iOS application restrictions may not be fully supported on older legacy Google Maps Platform services.
  3. Before you consider issuing calls directly from your mobile application to a Google Maps Platform REST API web service, verify that requests with incorrect Android or iOS application identifiers are rejected.

    If Android and iOS application restrictions are not supported on the tested endpoint, Google strongly recommends that you use a secure proxy server between your mobile clients and the Google Maps Platform web service endpoint.

Tips for Android applications:

Tips for iOS applications:

For further information, refer to articles Manage API keys and Use API keys to access APIs.

Host your browser based apps on a server

Frameworks, such as Apache Cordova, allow you to conveniently create multi-platform hybrid apps running inside a webview. However, API key website restrictions are not guaranteed to work correctly, unless your web app is loaded using HTTP or HTTPS from a website that you control and have authorized.

Bundled resources, loaded locally from within a hybrid application, or accessed using a local file URL will in many cases prevent referrer based authorization from working as the browser engine powering your webview will omit sending the Referer header. To avoid this, host your web applications server-side, not client-side.

Alternatively, for mobile applications, consider using available native Google Maps Platform Android and iOS SDKs, instead of using a web based SDK.

Use App Check to secure your API key

Certain Maps SDKs and APIs allow you to integrate with Firebase App Check. App Check provides protection for calls from your app to Google Maps Platform by blocking traffic that comes from sources other than legitimate apps. It does this by checking for a token from an attestation provider. Integrating your apps with App Check helps to protect against malicious requests, so you're not charged for unauthorized API calls.

App Check integration instructions:

Handle unauthorized use of an API key

If you detect use of your API key that is unauthorized, do the following to address the problem:

  1. Restrict your keys: If you've used the same key in multiple apps, migrate to multiple API keys, and use separate API keys for each app. For more details, see:

  2. If you use the Places SDK or the Maps Javascript API, you can also use App Check to secure your API Key.

  3. Only replace or rotate keys if the following is true:

    Before proceeding, read through Be careful when rotating API keys.

  4. If you are still having issues or need help, contact support.

Recommended application and API restrictions

The following sections suggest appropriate application and API restrictions for each Google Maps Platform API, SDK or service.

Recommended API Restrictions

The following guidelines for API restrictions apply to all Google Maps Platform services:

1 For more details, see the Places SDK for Android and Places SDK for iOS documentation.

2 If you are unsure if you need to authorize Places API (New) or Places API, see the Maps JavaScript API documentation.

Some examples:

Recommended application Restriction Important: Restricting your API keys helps to minimize overages and billing from unauthorized use, especially when a test environment may be or is publicly visible, or when an application is ready to be used in a production environment. Websites Tip: For Maps Embed API, see Websites with the Maps Embed API.

For websites using Maps JavaScript API services, Maps Static API or Street View Static API or calling recent Google Maps Platform services directly over the HTTPS REST API or gRPC, use the Websites application restriction:

1 For mobile applications, consider using the native Maps SDK for Android and Maps SDK for iOS.

2 For mobile applications, consider using the native Places SDK for Android and Places SDK for iOS.

3 See also Protect Static Web API usage.

Websites with the Maps Embed API

While using the Maps Embed API is no charge, you should still restrict any used API key to prevent abuse on other services.

Best practice: Create a separate API key for Maps Embed API use, and restrict this key to only the Maps Embed API. This restriction sufficiently secures the key, preventing its unauthorized use on any other Google service. For full control over where your Maps Embed API key can be used from, Google recommends also applying Websites application restrictions.

If you are unable to separate your Maps Embed API usage to a separate API key, secure your existing key using the Websites application restriction.

Apps and servers using web services Tip: For server-side applications, Google recommends using OAuth 2.0 over API keys on the services that support it. Refer to the table below for full details.

For servers and client-side apps from trusted corporate internal networks using web services together with API keys, use the IP addresses application restriction.

Important: IP restrictions might be impractical in some scenarios, such as in mobile applications and cloud environments that rely on dynamic IP addresses. When using Maps web service in these scenarios, secure your apps using a proxy server.

Use for apps and servers using these APIs:

4 For mobile applications, consider using the Navigation SDK.

5 For safe mobile usage, use a secure proxy server.

6 For client-side applications, consider using the native geolocation service offered by the platform; for example, W3C Geolocation for web browsers, LocationManager or the Fused Location Provider API for Android, or the Apple Core Location framework for iOS.

7 For mobile applications, consider using the native Places SDK for Android and Places SDK for iOS.

8 For safe client-side usage, use a secure proxy server.

Android apps

For apps on Android, use the Android apps application restriction. Use for apps using these SDKs:

Important: For maximum security, Google strongly recommends that you use our native SDKs to access Google Maps Platform services from your Android application.
If you need to access Google Maps Platform services for which a native Android SDKs is not available, see Secure client-side web service calls and Protect Static Web API usage.

In addition, prevent accidentally checking API keys into version control by using the Secrets Gradle Plugin to inject secrets from a local file rather than storing them in the Android Manifest.

iOS apps

For apps on iOS, use the iOS apps application restriction. Use for apps and servers using these SDKs:

Important: For maximum security, Google strongly recommend that you use our native SDKs to access Maps Platform services from your iOS application.
If you need to access Maps Platform services for which a native iOS SDKs is not available, see Secure client-side web service calls and Protect Static Web API usage.
Further reading

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4