Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to set Authorization and Timeout #181

Closed
sunnybogawat opened this issue Jul 28, 2015 · 5 comments
Closed

How to set Authorization and Timeout #181

sunnybogawat opened this issue Jul 28, 2015 · 5 comments

Comments

@sunnybogawat
Copy link

I am doing a get request and I need to pass the authorization token in the request also I need to override the timeout setting. I haven't found any way to do that in the documentation.

@dgraham
Copy link
Contributor

dgraham commented Jul 28, 2015

See this section of the readme for header syntax. See #175 for timeout discussion.

@dgraham dgraham closed this as completed Jul 28, 2015
@sunnybogawat
Copy link
Author

I am following the same way but when I debugged the ajax request I am not able to see the authorization token. I am doing cross origin request.

fetch('/users', {
method: 'post',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': 'Token token=xxxxx'
}})

@dgraham
Copy link
Contributor

dgraham commented Jul 29, 2015

The Chrome Network panel can help debug cross-origin requests.

First, disable the cache so the OPTIONS pre-flight request will occur for each cross-origin request.

screenshot 2015-07-29 10 51 19

Then in the Network panel you can see both the OPTIONS pre-flight and the subsequent actual request. It's likely that OPTIONS is failing so your request is never made.

screen shot 2015-07-29 at 10 57 06 am

@sunnybogawat
Copy link
Author

Thanks for a quick reply. I have the same setting in my chrome agent and I am passing the token to the fetch request also but somehow it failing at OPTIONS request. Please find below screen shot to understand the workflow

  1. The Fetch Request Code -

capture2

  1. My Chrome Setting

capture

  1. Get Request Created and Error Received With Request Header

2015-07-30_1140

2015-07-30_1139

capture1

@dgraham
Copy link
Contributor

dgraham commented Jul 30, 2015

The server is returning a 401 Unauthorized response to the OPTIONS request. HTML 5 Rocks has a good tutorial on how cross-origin requests work on the client and server.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants