I am trying azure function (nodejs) with google authentication from a client side javascript app. I have set up CORS for the correct URL(i.e. http://localhost:8080). But I am still getting the following error:
Credentials flag is 'true', but the 'Access-Control-Allow-Credentials' header is ''. It must be 'true' to allow credentials. Origin 'http://localhost:8080' is therefore not allowed access.
I have tried everywhere on the internet and spent few days to get the answers myself. It seems Azure http response needs to add this Access-Control-Allow-Credentials:true in the header. Is there a way to add custom headers?
Any help will be greatly appreciated.
I am trying azure function (nodejs) with google authentication from a client side javascript app. I have set up CORS for the correct URL(i.e. http://localhost:8080). But I am still getting the following error:
Credentials flag is 'true', but the 'Access-Control-Allow-Credentials' header is ''. It must be 'true' to allow credentials. Origin 'http://localhost:8080' is therefore not allowed access.
I have tried everywhere on the internet and spent few days to get the answers myself. It seems Azure http response needs to add this Access-Control-Allow-Credentials:true in the header. Is there a way to add custom headers?
Any help will be greatly appreciated.
Share Improve this question edited Apr 3, 2018 at 15:36 Damian Green 7,4952 gold badges35 silver badges46 bronze badges asked Aug 29, 2016 at 21:28 Sofa GumSofa Gum 1031 gold badge1 silver badge4 bronze badges 2- Are you using nodejs ? – Thomas Commented Aug 29, 2016 at 21:33
- @Thomas, yes nodejs at server side and javascript fetch at client side. – Sofa Gum Commented Aug 30, 2016 at 3:22
2 Answers
Reset to default 12In a Node function you can specify additional headers as follows:
module.exports = function (context, req) {
context.res = {
status: 200,
body: "Hello " + req.query.name,
headers: {
'Content-Type': 'text/plain',
'MyCustomHeader': 'Testing'
}
};
context.done();
}
I have finally managed to get around the issue. The trick is to remove all the CORS entries from Azure Functions app and handle it directly in your code.
Thanks to the tip shared in another stackoverflow issue regarding azure app service, which worked for azure functions as well.
More details regarding the work around are at:
github issue #620