Kyle Vassella
Kyle Vassella

Reputation: 2654

How to test OneTrust cookie banners in localhost?

I'm using OneTrust cookie banners in an Angular application. I'm not the one creating the cookie banner, but it seems the way it works is our OneTrust engineer makes a OneTrust banner available for only a certain domain (URL). Thus, I can set banners to work in Prod or in Dev, but I can't get them to work in localhost:4200 when I locally serve my Angular project.

Is there a way to test the OneTrust SDK / cookie banner in a local environment without pushing to Dev or Sandbox domains?

Upvotes: 1

Views: 2831

Answers (1)

Ben Smith
Ben Smith

Reputation: 20230

If your OneTrust is configured for a particular domain (e.g. acme.net) you can test your local instance against this domain by doing the following:

  1. Add an entry to your hostfile:

    On Mac/Linux:

    sudo nano /etc/hosts
    

    On Windows: The file is at C:\Windows\System32\drivers\etc

    Add localhost.acme.net to your aliases list

    127.0.0.1       localhost localhost.acme.net
    
  2. Download and install caddy (this is a "powerful, enterprise-ready, open source web server with automatic HTTPS written in Go" - you could use something else but I've found this really easy to use) https://caddyserver.com/docs/install

  3. Run your application in the terminal

  4. Run caddy in another terminal caddy reverse-proxy --from localhost.acme.net --to localhost:4200 --insecure --internal-certs

    (note that you may need to change the localhost port number if your application uses something different!)

  5. Access the service at https://localhost.acme.net

Now, as your browser has the same domain as your OneTrust configuration, accepting the consents in the cookie banner will cause the OneTrust cookies to be correctly persisted in your browser.

Upvotes: 1

Related Questions