Hi @jayv25585659,
Here’s what’s actually happening - Postman works because it’s not affected by browser security rules. But when you call your AEM servlet via JavaScript in a web page:
Basic Auth header is correct
Browser blocks the request -> 403 due to CORS / CSRF / Sling Referrer Filter
Add these headers:
const headers = new Headers();
headers.append("Content-Type", "application/json");
headers.append("Authorization", "Basic YWRtaW46YWRtaW4=");
headers.append("CSRF-Token", "nocheck");
Then:
const response = await fetch("http://localhost:4502/bin/acara/principals/accessrequest", {
method: "POST",
credentials: "include",
headers: headers,
body: JSON.stringify(payload)
});
For AEM Author only
You also need to whitelist your local site:
AEM -> Web Console ->
OSGi Config -> Adobe Granite Cross-Origin Resource Sharing Policy
Add:
Allowed Origins: http://localhost:3000 (or your front-end port)
Allowed Headers: Authorization, Content-Type, CSRF-Token
Supported Methods: POST, GET, OPTIONS
Also update:
Adobe Granite Referrer Filter
-> Add localhost to allow list
Quick Test to Confirm Your Servlet Works in Browser
Open browser DevTools:
fetch("http://localhost:4502/bin/acara/principals/accessrequest", {
method: "POST",
headers: {
"Authorization": "Basic YWRtaW46YWRtaW4=",
"Content-Type": "application/json",
"CSRF-Token": "nocheck"
},
body: JSON.stringify({ test: true })
}).then(r => console.log(r.status, r.text()));
If this works -> CORS/Referrer are the missing pieces in your frontend app.