I'm having a problem to get the Authorization code of the user.
After the login, I get the user code in URL and after that I go get the access_token
with Ajax, But when I do that, I am getting an error :
AADSTS90023: Cross-origin token redemption is permitted only for the 'Single-Page Application'
Here my code :
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/Pagina1.html");
form.append("grant_type", "authorization_code");
form.append("code", `${code}`);
// Tried with, but no effect -> https://cors-anywhere.herokuapp.com/
$.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)
}
})