How do I enable CORS using F# and ASP.NET. I'm trying to authenticate a user with Google but I get the following error in the browser console:
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
A reproducible example is here https://github.com/sashang/safe-google-auth
It uses F# and the SAFE framework so you'll need that setup if you want to try and reproduce this.
You'll also need to setup a client id and secret with Google+ API (https://console.cloud.google.com/apis/library/plus.googleapis.com)
Once that's done add it to your environment:
Bash:
export GOOGLE_ID="client id"
export GOOGLE_SECRET="client secret"
Windows Powershell:
$Env:GOOLGE_ID="client id"
$Env:GOOGLE_SECRET="client secret"
To build it clone the repo and run
fake build --target run
Then click on the button Auth with Google
with the browser console window open to see the error.
In your
Server.fs
you don't call yourconfigure_cors
method