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

[ Question ] What is the correct way to use proxy if there is an dependency request #1053

Open
iroy2000 opened this issue Aug 27, 2016 · 0 comments

Comments

@iroy2000
Copy link

iroy2000 commented Aug 27, 2016

Not sure if it is a matter of configuration ( or what is the correct way of doing that )

I have a PHP server serving api, and in order to get the response, I need to get a token. If there is no token or an invalid token, it will denied your access. The token is session based.

The sequence is like that

  1. get the token ( /api/token )
  2. append the token to the proxy request

I'm able to do that when I do that sequence from the browser, but when I used the proxy, I can't get that working.

The following is a middleware for a particular route

// testGetTokenMiddleware.js

export default (req, res, next) => {

    // There are some more code for performance, but following is the "stripped" relevant code.

    request(`${config.get('myUrl')}/get_token`, function(err, response, body) {

      if(err) {
        response.send(404);
      }

      const tokenResponse = JSON.parse(body);

      // I then append the token to my url, but when I debug further, this token is not the same as the token in the "PHP session"
      req.session.phpToken = tokenRsponse.token;

      next();

    });
}

And later on I use that middleware in one of my route

  import testGetTokenMiddleware from 'testGetTokenMiddleware';

  // ... ignore some other code ... blah 

  router.get('/api/test', testGetTokenMiddleware, myProxy);

When I debug the issue, I found out that the token that I got from the middleware is different from the token in the php session. ( Maybe it is passing the wrong Cookie, or the request and proxy is on different sessions ?? ) Wondering what is the best way to solve that issue.

Thanks

@iroy2000 iroy2000 changed the title [ Question ] What is the correct way to use proxy to get session token from PHP [ Question ] What is the correct way to use proxy if there is an dependency request Aug 27, 2016
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