I currently have a Wep App (ASP.NET Core 2.2) and an Azure Function returns the JSON "hi". No NodeJS is being used.
I have set up both my Web App and Function with B2C and when accessing them individually, they both prompt a login and work fine.
Update: If I access the Web App, login in and then access the function url, it then gives the response "hi" but the Ajax request wont work unless I manually access the function url address manually after login in via the Web App.
My issue is that I have a Ajax request from the web app to the function but it doesn't pass the credentials and only works if I log into both web app and function individually.
I would like help to get the web app to pass on it's credentials to the function so I don't get the following error:
Access to XMLHttpRequest at 'https://xxx.b2clogin.com/xxx.onmicrosoft.com/oauth2/v2.0/authorize?response_type=id_token&redirect_uri=https%3A%2F%2Fxxx.azurewebsites.net%2F.auth%2Flogin%2Faad%2Fcallback&client_id=5e55f7e5-2b51-4a5f-86c0-b7776b2623b2&scope=openid+profile+email&response_mode=form_post&p=b2c_1_signin&nonce=d138edf541d1423e92b99fe7ca400263_20190331110324&state=redir%3D%252Fapi%252FTest%253F_%253D1554029904731' (redirected from 'https://xxx.azurewebsites.net/api/Test?_=1554029904731') from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
function Test2() {
console.log("2. Sending request...");
$.ajax({
type: "GET",
cache: false,
credentials: 'include',
mode: 'cors',
url: 'https://xxx.azurewebsites.net/api/Test',
// contentType: "application/json; charset=utf-8",
//dataType: "application/json",
//data: dataValue,
xhrFields: {
withCredentials: true
},
crossDomain: true,
success: function (response) {
console.log('2. Done');
console.log('2. ' + response);
},
failure: function (response) {
console.log("2. Request: Failed.");
alert(response.d);
}
});
}