For the complete documentation index, see llms.txt. This page is also available as Markdown.

Authentication

This page outlines how to handle OS API authentication and recommends best practices for securing your OS API credentials.

To use OS APIs you need to authenticate your requests. Before you can authenticate requests you need to add the API into an API Project in the OS Data Hub; this gives you access to a Project API Key and Project API Secret. See Getting started with an API project for more information on setting up your API Project.

Your API key, API secret and OAuth tokens provide access to your OS API project. Treat them like passwords and do not expose them in public websites, applications or source code.

OS API Service Terms

Types of authentication

There are three options for authenticating your API requests. Choose the method that best suits your application and its security requirements. Whichever method you use, you are responsible for protecting the credentials associated with your project.

OAuth2

Using OAuth 2 for authentication is a two-stage process. First you use the Project API Key and Secret to create an access token, and then you include the access token in an Authorization header on your API request. The value of the Authorization header should be 'Bearer', a space, and then the access token, e.g. Bearer <accessToken>.

See the OAuth 2 API documentation for detailed instructions on how to create an access token.

HTTP Header

You can choose to authenticate your API request using a HTTP header. The header name should be key, and the value should be the Project API Key.

HTTP Query Parameter

You can choose to authenticate your API request using a HTTP query parameter. The parameter name should be key, and the value should be the Project API Key.

Keep your credentials secure

If credentials are exposed, someone else may be able to use your API allowance, access licensed data through your application or generate unexpected usage against your account.

Store credentials securely

Store API keys, secrets and tokens in a secure credential store, for example:

  • Azure Key Vault

  • AWS Secrets Manager

  • Google Secret Manager

  • Environment variables or secret settings managed by your hosting platform

Do not place credentials in publicly accessible configuration files.

Do not put credentials in client-side code

Do not embed API keys, API secrets or long-lived tokens in JavaScript, HTML or other code accessed by a user’s browser. A user can inspect the code and network requests and may be able to copy the credential.

For more detail on securing credentials, please refer to our OS Labs guidance.

Do not commit credentials to source control

Do not commit credentials to Git, GitHub, GitLab, Bitbucket or shared code archives. Use your repository or deployment platform’s secret-management features, and configure .gitignore rules where appropriate.

Use least privilege

Give each application no more access than it needs. Where practical:

  • Use separate API projects or credentials for different applications and environments.

  • Only add the APIs the application needs to the relevant API project.

  • Do not share the same credentials across unrelated services.

  • Remove or rotate credentials that are no longer required.

Rotate credentials

Replace credentials periodically, or immediately if you believe they may have been exposed. Update the application and revoke the old credentials as soon as the replacement is working. Users can regenerate the API key within each API project in the Data Hub.

The most secure approach is to keep your OS API credentials on a server that you control. A backend proxy is a small service that sits between your users and OS APIs.

The browser or mobile app calls your backend service. This service then adds the OS API credential and sends the request to the OS API, returning only the response your application needs.

Adopting this approach means:

  • Credentials remain on your server and are not sent to the user.

  • You can validate requests before forwarding them.

  • You can restrict which OS API endpoints and parameters your application uses.

  • You can apply monitoring, rate limits and other controls to your own service.

When might I not need a backend service?

You may not need a backend service or proxy for internal prototypes, proof-of-concepts, development tools, or applications that are not publicly accessible. In these cases, the risk of exposing a credential or unauthorised access to data is typically lower.

We recognise that not every user has the technical capability to build and operate a backend service immediately. If you choose to call an OS API directly from browser-based code in the short term, you should understand that the credential may be visible and reusable by others.

To reduce the risk of calling the OS API directly from the browser:

  • Use short-lived OAuth tokens where the API and application pattern support them.

  • Apply any available restrictions, quotas and rate limits.

  • Use separate credentials for prototypes and production services.

  • Monitor usage for unexpected activity.

  • Rotate your API key regularly and after any suspected exposure.

  • Move to a backend architecture before the service handles sensitive, licensed or business-critical use cases.

Monitor your usage

Review usage within your OS Data Hub project and investigate activity that does not match the expected behaviour of your application such as unexpected increases in requests or consumption.

If you think a credential has been exposed:

  • Stop using or revoke the affected credential.

  • Create a replacement credential.

  • Update your secure server configuration.

  • Review logs and usage to understand the possible impact.

  • Check source repositories, build output and deployed client-side code for other exposed credentials.

Choose the right approach

Scenario
Recommended approach

Public interactive web map

Use a backend proxy service. Do not embed OS credentials in client-side JavaScript.

Address search or lookup form

Send the search request to your backend, which calls the relevant OS API.

Mobile application

Use a backend proxy service. Do not depend on hiding credentials inside the app.

Server-to-server integration

Store credentials securely on the server and use the authentication method supported by the API.

Short-lived prototype

Prefer a backend service. If you accept the risk of a frontend implementation, use separate credentials, monitor usage and remove them when the prototype ends.

Common Mistakes to Avoid

Implementation Checklist

Last updated

Was this helpful?