I wanted to access a server API I made with Yesod 1.2 from a bookmarklet. I wanted to POST from the bookmarklet at any other sites. The server API has an authentication (by Mozilla Persona and Google ID). This means:
I added OPTIONS to my Handler according to the following.
https://developer.mozilla.org/en-US/docs/HTTP/Access_control_CORS
Allowing cross-origin requests in Yesod
I noticed, however, that the request is forwarded to /auth/login of the Yesod app, even after the user is logged in from the browser (I think this makes sense because these two are different domains). Auth is handled in a subsite. So I think I need OPTIONS for /auth/login as well. How can I add OPTIONS for Auth subsite in config/routes file?
Or, is there any better way to have authentication from a bookmarklet?
Two approaches:
I'd go for (1), you'll be benefiting the community and it will be easier to maintain.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With