Skip to content

Instantly share code, notes, and snippets.

Created November 21, 2016 07:57
What would you like to do?
Forward-all proxy for CARTO's password/token-protected named maps
<!doctype html>
<html lang="en">
<meta charset="utf-8">
<link rel="stylesheet" href="" />
<script src=""></script>
<title>Password-protected named map example</title>
<div id="map" style="height: 500px"></div>
{ maps_api_template: "https://localhost:5000/user-demo-admin" }
).done(function (vis, layers) {
map = vis.getNativeMap();
user_name: "demo-admin",
type: 'namedmap',
options: {
named_map: {
name: "tpl_f7a74d56_a7f0_11e6_b9b8_ea8015be2564",
layers: [
"layer_name": "dot_rail_safety_data",
maps_api_template: "https://localhost:5000/user/demo-admin"
import requests
from flask import Flask, request
VERIFY_SSL_CERT = False # Set to True if you want the proxy to verify CARTO's cert (set to False because in this example we're hitting an onprem with self-signed certs).
app = Flask(__name__)
@app.route('/', defaults={'path': ''})
def viz_json(path):
# Add auth_token to every forwarded request. A bit overkill, but does the trick
args = dict(request.args)
args["auth_token"] = "28c191c187e06780f90d7bde5dc07a0ea267b922e9286b5dec4648eaf2ae1dca"
# Forward request to CARTO
response = requests.get(BASE_URL + request.path, params=args, verify=VERIFY_SSL_CERT, stream=True)
# Send CARTO's response back to the browser
return (, response.status_code, response.headers.items())
if __name__ == "__main__":
# SSL is required for password-protected named maps
# Using a self-signed cert here
# In order to use real certs, do'', ''))"adhoc")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment