What is the best way to get JSON data via JavaScript with cookie authentication?
-
I'm building an application with Ruby on Rails. The application is a Javascript application that get data by JSON calls from the `api` application. It also provide the cross domain authentication for the application itself and the `api`. I handle the cross domain authentication via making both application cookies with same secret session key and same name e.g. `_app_an_api_session`. Now, I'll write down the senario and I'll show you when it fails. The application domain is `domain.local` the api domain `api.domain.local` Lets say that `api.domain.local/me` is a protected page. When I open it i got `unauthenticated` When I go to the application and `sign in` and go to `api.domain.local/me` again, I can see the data in it. [Pass] [it works also for the opposite actions]. The problem is, for example, after `sign in` I want to load `api.domain.local/me` contents [JSON data] in `domain.local`, I can see in the console that the `status` is `(canceled)`. In addition for debugging sake. I tried to see the `env` variable on each request to the `api`. So, when I access the `api.domain.local/me`directly, I can see the cookies hash in the console, else if it via the real application, there's no cookies/sessions at all. So, how to make it possible to done this right?
-
Answer:
I apologize if I'm not reading your question right, but... if you are serving json, then you don't need cross-domain authentication. Just authenticate to your json domain, and your json will be cross-domain through the script tag. http://en.m.wikipedia.org/wiki/JSONP
Bradford Mar at Quora Visit the source
Other answers
If a cookie is set to domain.local, it can also be read by subdomains, such as api.domain.local. Are you sure that 'unauthenticated' is an error caused by the lack of a session key?
John Paul
Related Q & A:
- What's the best way to get into the Graphic Design industry?Best solution by Yahoo! Answers
- What is the best way to get from Denver to Fort Collins?Best solution by Yahoo! Answers
- What is the best way to get a job on cruise ships without spending money?Best solution by cruiseserver.net
- What is the best way to get website traffic?Best solution by Yahoo! Answers
- What's the best way to get a job in a restaurant?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.