Hello @mancillaignAdobe
You can try the below :
You can :
- Use window.postMessage to securely send token from parent to iFrame.
// Parent page
const token = new URL(window.location.href).searchParams.get('token');
document.getElementById('aem-form-iframe').contentWindow
.postMessage({ token }, 'https://your-aem-domain.com');
// AEM Form (iFrame)
window.addEventListener('message', (event) => {
if (event.data.token) {
const token = event.data.token;
// Use token for API call
}
});
- Not expose external API or token client-side; send token to custom AEM servlet.
// iFrame JS (after receiving token)
fetch('/bin/userdata', {
method: 'POST',
body: JSON.stringify({ token }),
headers: { 'Content-Type': 'application/json' }
})
.then(r => r.json())
.then(data => {
// Prefill fields
document.getElementById('name').value = data.name;
document.getElementById('email').value = data.email;
});
- Implement Custom AEM Servlet to handle receiving token and fetching user data.
@SlingServlet(paths = "/bin/userdata", methods = "POST")
public class UserDataServlet extends SlingAllMethodsServlet {
protected void doPost(SlingHttpServletRequest req, SlingHttpServletResponse resp) throws IOException {
String token = req.getParameter("token");
// Fetch user info from backend API using token
// Return JSON: {"name":"John Doe", "email":"john@example.com"}
}
}
- After receiving user data, set form field values via JS:
document.getElementById('name').value = data.name;
document.getElementById('email').value = data.email;
You can also prefill using OOTB Prefill Service.
https://experienceleague.adobe.com/en/docs/experience-manager-learn/forms/adaptive-forms/prefill-ser...