I am encountering an issue with obtaining the Authorization code for the user.
After the user logs in, I extract the user code from the URL and then use Ajax to fetch the access_token
. However, during this process, I encounter the following error :
AADSTS90023: Cross-origin token redemption is allowed only for the 'Single-Page Application'
Below is my code snippet :
const url = window.location.href;
const code = url.slice((url.indexOf("=")+1), url.indexOf("&"));
console.log(code)
let form = new FormData();
form.append("client_id", "48701536-c150-48f2-917b-730d855f316b");
form.append("client_secret", "RzZ7Q~-GEYd6WayuMKmVXvH2w.Q7GjuaoHNEy");
form.append("scope", "https://graph.microsoft.com/user.read");
form.append("redirect_uri", "http://localhost:3000/Page1.html");
form.append("grant_type", "authorization_code");
form.append("code", `${code}`);
$.ajax({
url: "https://login.microsoftonline.com/consumers/oauth2/v2.0/token",
method: 'POST',
"timeout": 0,
crossDomain: true,
async: false,
processData: false,
mimeType: "multipart/form-data",
contentType: false,
data: form,
success(response) {
console.log(response)
}, error(response){
console.log(response)
}
})