Skip to main content
Level 1
Oct 15, 2026 1:32 PM UTC
Question

Universal Editor Integration in AEM 6.5 LTS

Hi, 

 

I am trying to Integrate Universal Editor with AEM 6.5 LTS. 

I have created a content fragment, a react app. App is able to connect with AEM and the content fragment values are rendering on App. 

But when i try to add the react app url in the Universal Editor console, i am getting following error :

AEM GraphQL error: Error: AEM CSRF response does not contain a token
    at loadFragment (App.jsx:55:17) and this is my app.jsx file :

 

import { useEffect, useState } from 'react'
import './App.css'

const AEM_HOST = 'https://localhost:5502'

const GRAPHQL_URL =
  '/aem/content/cq:graphql/b2bcfconfig/endpoint.json'

const CSRF_URL =
  '/aem/libs/granite/csrf/token.json'

const QUERY = `
  query {
    universalEditorByPath(
      _path: "/content/dam/b2b/contentfragments/ue-demo"
    ) {
      item {
        _path
        title
      }
    }
  }
`

function App() {
  const [fragment, setFragment] = useState(null)
  const [error, setError] = useState('')
  const [loading, setLoading] = useState(true)

  useEffect(() => {
    let cancelled = false

    async function loadFragment() {
      try {
        setLoading(true)
        setError('')

        // Step 1: Get the CSRF token from AEM
        const tokenResponse = await fetch(CSRF_URL, {
          method: 'GET',
          credentials: 'include',
        })

        if (!tokenResponse.ok) {
          throw new Error(
            'CSRF token request failed: ' + tokenResponse.status
          )
        }

        // AEM returns { "token": "..." }
        const tokenData = await tokenResponse.json()
        const csrfToken = tokenData && tokenData.token

        if (!csrfToken) {
          throw new Error(
            'AEM CSRF response does not contain a token'
          )
        }

        console.log('AEM CSRF token retrieved successfully')

        // Step 2: Send the GraphQL query
        const response = await fetch(GRAPHQL_URL, {
          method: 'POST',
          credentials: 'include',
          headers: {
            'Content-Type': 'application/json',
            'CSRF-Token': csrfToken,
          },
          body: JSON.stringify({
            query: QUERY,
          }),
        })

        if (!response.ok) {
          const responseText = await response.text()

          throw new Error(
            'GraphQL request failed: ' +
              response.status +
              (responseText ? ' - ' + responseText : '')
          )
        }

        // Step 3: Read the GraphQL response
        const result = await response.json()

        if (result.errors && result.errors.length > 0) {
          throw new Error(result.errors[0].message)
        }

        const item =
          result.data &&
          result.data.universalEditorByPath &&
          result.data.universalEditorByPath.item

        if (!item) {
          throw new Error(
            'No Content Fragment returned. Check the fragment path and GraphQL query.'
          )
        }

        if (!cancelled) {
          setFragment(item)
        }
      } catch (err) {
        console.error('AEM GraphQL error:', err)

        if (!cancelled) {
          setError(
            err instanceof Error
              ? err.message
              : 'An unexpected error occurred while loading AEM content.'
          )
        }
      } finally {
        if (!cancelled) {
          setLoading(false)
        }
      }
    }

    loadFragment()

    return () => {
      cancelled = true
    }
  }, [])

  return (
    <main className="page">
      <p className="eyebrow">AEM Universal Editor Demo</p>

      {error ? (
        <p role="alert">{error}</p>
      ) : loading ? (
        <p>Loading content from AEM…</p>
      ) : fragment ? (
        <article>
          <h1
            data-aue-resource="urn:aemconnection:/content/dam/b2b/contentfragments/ue-demo/jcr:content/data/master"
            data-aue-prop="title"
            data-aue-type="text"
            data-aue-label="Demo Title"
          >
            {fragment.title || 'Untitled demo fragment'}
          </h1>

          <p>
            Content Fragment path: {fragment._path}
          </p>
        </article>
      ) : null}
    </main>
  )
}

export default App

2 replies

Level 2
Oct 15, 2026 6:06 PM UTC

​@intuitive_Moonbeam2bbf ,

I’d look at the Universal Editor setup for 6.5 LTS first, because this smells like an auth problem in the editor’s iframe. The editor runs on experience.adobe.com, so your app is loaded cross-site. The 6.5 LTS docs say to set the SameSite attribute of the login-token cookie (token.samesite.cookie.attr) on the Adobe Granite Token Authentication Handler to Partitioned, to enable the Query Parameter Authentication Handler by putting “/” in its path, and to set the Universal Editor Opening Mapping. Also double check your meta tags use the aem65 protocol, not aem. Then open the Network tab inside the editor and see what the token.json request actually returns. My guess is it’s coming back anonymous because the cookie isn’t being sent. Longer term, AEM’s docs recommend persisted queries over GET instead of POSTing queries, which would also let you drop the CSRF token step.

Translate
Raja_Reddy
Community Advisor
Community Advisor
Nov 7, 2026 10:34 AM UTC

Hi ​@intuitive_Moonbeam2bbf 
That error message comes from your own code (throw new Error('AEM CSRF response does not contain a token')), so the request to /libs/granite/csrf/token.json succeeded but the JSON had no token field. It works when you open the app directly but fails inside Universal Editor, which points to authentication rather than to the query or the fragment.

Why it likely fails only in Universal Editor

The editor runs on experience.adobe.com, so your app loads in a cross-site iframe. A normal credentials: 'include' request then often arrives without the AEM login cookie, and the token endpoint returns something other than a valid token.

Things to check

  1. Log the actual response. Before the if (!csrfToken) check, add console.log(tokenData) and look at the request in the Network tab (select the iframe’s context in DevTools). If it’s empty or an anonymous response, it’s the cookie issue.
  2. Login-token cookie: in /system/console/configMgr, open Adobe Granite Token Authentication Handler and set token.samesite.cookie.attr to Partitioned, as the 6.5 LTS Universal Editor docs describe.
  3. X-Frame-Options: remove the SAMEORIGIN header setting so AEM content can be framed.
  4. Meta tags in your app’s HTML: for 6.5 LTS the protocol must be aem65, not aem, and the service must be announced:

html

   <meta name="urn:adobe:aue:system:aemconnection" content="aem65:https://localhost:5502"/>
<meta name="urn:adobe:aue:config:service" content="https://localhost:5502/universal-editor"/>

Also use aem65 instead of aem in the plugins section of the component definitions.
5. Universal Editor Service: make sure the local UE service is running and reachable, since 6.5 LTS needs it.

A simplification to consider: the CSRF token is only needed for write-style requests. If you move the GraphQL call to a persisted query fetched with GET, you can drop the CSRF step entirely, which removes this failure point. This is my suggestion rather than something from the docs, so confirm that your persisted-query setup supports it.

Hope this helps. If it still fails, please share what tokenData contains inside the editor.

Translate