My requirement is that I want to expose my lightning component to an external website(HTML webpage) without user having to log in to salesforce. For this, as per this questions's answer., I have done following steps:

  1. Create a lightning app as :
<aura:application access="GLOBAL" extends="ltng:outApp" implements="ltng:allowGuestAccess"> 

    <aura:dependency resource="c:SFMC_LtngOutPOC"/>
    <aura:dependency resource="lightning:recordForm"/>
  1. Lightning component:
        <aura:attribute name="MyComponent" type="String" default="Sarang">
        My Simple lightning component: {!v.MyComponent}
  1. Created a simple html page:

        <h1>This  is my web page!! </h1>
        <div id="domLocator"></div>
  1. With scripts as:
<script src="https://myTestDomain.my.salesforce.com/lightning/lightning.out.js"></script>

function setupLightning(callback) {
var appName = "c:LtngOutPOCApp";

        function() {
            document.getElementById("lexcontainer").style.display = "";
            if (typeof callback === "function") {
        }, "https://myTestDomain.lightning.force.com", <ACCESS_TOKEN_FROM_CONNECTED_APP>);

function createComponent(function() {
    $Lightning.createComponent("LtngOutPOC", {}, "domLocator", function(component){
        console.log('Inside create component callback');


I have created a localhost on my machin to host this page at:


And added this URL in CORS setting in my salesforce instance. I have directly hard coded the access token by copying it from my connected app in salesforce. After doing these steps I am getting following error:

Access to XMLHttpRequest at 'https://myTestDomain.lightning.force.com/c/LtngOutPOCApp.app?aura.format=JSON&aura.formatAdapter=LIGHTNING_OUT' from origin 'http://localhost:8000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

What could be the reason for this? Can I not expose my lightning component without wanting user to log in to salesforce manually, just by giving the access token through code? Is any other setting being missed here?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.