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

Specifying API port 80 might cause auth calls to fail with 401 #114

Open
nerfologist opened this issue Mar 6, 2017 · 0 comments
Open

Specifying API port 80 might cause auth calls to fail with 401 #114

nerfologist opened this issue Mar 6, 2017 · 0 comments

Comments

@nerfologist
Copy link

Hey,
in my workplace we just ran into the following GOTCHA:

our production API runs on heroku on http://someserver.net:80 so here's our configure:

store.dispatch(configure({ apiUrl: 'http://someserver.net:80' }))

This configuration is valid and, when we click the Sign In button, a request is issued to http://someserver.net/auth/sign_in according to the Chrome dev tools. Note how :80 is now omitted (being redundant).

Problem is, when response comes back and goes thru the modified fetch, it is compared with the original API URL (including :80) and comparison fails. This results in a 401 error.

// fetch.js:49-53
function updateAuthCredentials(resp) {
  // check config apiUrl matches the current response url
  if (isApiRequest(resp.url)) { // <<<< WILL RETURN FALSE
  // set header for each key in `tokenFormat` config
  var newHeaders = {};
  ...

// fetch.js:12-14
var isApiRequest = function(url) {
  // url =            'http://someserver.net/auth/sign_in
  // getApiUrl(...) = 'http://someserver.net:80'
  return (url.match(getApiUrl(getSessionEndpointKey()))); // no match!
};

A possible solution would be to make the URL comparison in isApiRequest slightly smarter (capable of handling missing port number if it's 80).

As a workaround we ended up modifying our environment-dependent API URL generation code so that port number is omitted if it's 80.

HTH

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

No branches or pull requests

1 participant