How can I embed an Autodesk Forge Viewer to a Flask App without CORS errors?

Solution




  
  
  Axpo BIM Viewer
  
  
  
  
  



  
from flask import Flask, render_template
import requests

app = Flask(__name__)

# Update variable values
document_id=""
client_id=""
client_secret=""

@app.route("/")
def run():
  return render_template('index.html', documentId=document_id)

@app.route("/access_token")
def get_access_token():
  headers = {"Content-Type": "application/x-www-form-urlencoded"}
  body = (
    f"client_id={client_id}"
    f"&client_secret={client_secret}"
    "&grant_type=client_credentials"
    "&scope=viewables:read"
  )
  print(body)
  res = requests.post("https://developer.api.autodesk.com/authentication/v1/authenticate", data=body, headers=headers)
  data = res.json()
  return data