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 use apex_oauth with node4ords ? #33

Open
tiagosteil opened this issue Apr 15, 2017 · 7 comments
Open

How to use apex_oauth with node4ords ? #33

tiagosteil opened this issue Apr 15, 2017 · 7 comments
Labels

Comments

@tiagosteil
Copy link

Hi

I'm using node4ords as weblistener on my server with the OXAR project: Https://github.com/OraOpenSource/OXAR

And now I want to use this project below to be able to perform the
Login with Gmail: Https://github.com/smart4solutions/apex_oauth

However I have a problem to redirect the user to the
Google login page, which I researched is due to CORS.
In the apex_oauth project Is cited to create a reverse proxy.

captura de tela 2017-04-15 as 12 04 11

How do I do this reverse proxy on node4ords?

Thank you for your attention.

@tiagosteil tiagosteil changed the title How to use apex_oauth with node4ords How to use apex_oauth with node4ords ? Apr 15, 2017
@martindsouza
Copy link
Member

I'm not 100% sure how to resolve this issue. You could try to modify /opt/node4ords/app.js and set res.setHeader('Access-Control-Allow-Origin', '*'); in the middleware.

@krisrice any ideas?

@dmcghan
Copy link

dmcghan commented Apr 17, 2017

If you're redirecting then why would you need CORS? Maybe @rhjmartens could help.

@tiagosteil
Copy link
Author

Hi,

The above error occurs when the application tries to make the code below:

t_url := 'https://accounts.google.com/o/oauth2/auth?client_id=' || g_provider.client_id 
                        || '&redirect_uri='  || g_provider.redirect_uri 
                        || '&scope='         || apex_util.url_encode(g_provider.scope)
                        || '&state='         || v('APP_SESSION') || ':' || v('WORKSPACE_ID') || ':' || v('APP_ID') || ':' || p_gotopage
                        || '&response_type=' || 'code'  -- mandatory for google
                        || g_provider.extras
                        || case g_provider.force_approval
                             when 'Y' then '&approval_prompt=force'
                             else ''
                           end;

owa_util.redirect_url ( t_url );

So I changed the /opt/node4ords/app.js file and created the following proxy rule below:

app.use('/acgoogle', proxy(
  {
    target: 'https://accounts.google.com/',
    changeOrigin: true,
    https: true,
    onProxyRes: function(proxyRes, req, res){

        proxyRes.headers['Access-Control-Allow-Origin'] = '*';

        if (req.headers['access-control-request-method']) {
          res.setHeader('access-control-allow-methods', req.headers['access-control-request-method']);
        }

        if (req.headers['access-control-request-headers']) {
          res.setHeader('access-control-allow-headers', req.headers['access-control-request-headers']);
        }

    },
    pathRewrite: {
      '^/acgoogle' : '/'
    }
  }
)); 

After that, I changed the redirect link to the link below:

t_url := 'http://myhost/acgoogle/o/oauth2/auth?client_id=' || g_provider.client_id 
                        || '&redirect_uri='  || g_provider.redirect_uri 
                        || '&scope='         || apex_util.url_encode(g_provider.scope)
                        || '&state='         || v('APP_SESSION') || ':' || v('WORKSPACE_ID') || ':' || v('APP_ID') || ':' || p_gotopage
                        || '&response_type=' || 'code'  -- mandatory for google
                        || g_provider.extras
                        || case g_provider.force_approval
                             when 'Y' then '&approval_prompt=force'
                             else ''
                           end
                        ;   

owa_util.redirect_url ( t_url ); 

And now the error that is being displayed is the error below:

captura de tela 2017-04-17 as 15 55 12

When I click on the link generated by pck, the google page opens correctly ... however redirect does not work.

I believe there is something wrong or missing from my proxy rule.

Thanks for listening.

@rmartenss4s
Copy link

rmartenss4s commented Apr 18, 2017 via email

@krisrice
Copy link

The origin is getting lost somehow. I've never used this but did notice this in the wiki
💡 Tip: Set the option changeOrigin to true for name-based virtual hosted sites.

@tiagosteil
Copy link
Author

tiagosteil commented Apr 18, 2017

The origin is getting lost somehow. I've never used this but did notice this in the wiki
💡 Tip: Set the option changeOrigin to true for name-based virtual hosted sites.

I put this option to true, but I do not know if it's in the correct place.

app.use('/acgoogle', proxy(
  {
    target: 'https://accounts.google.com/',
    changeOrigin: true,
    https: true,
    onProxyRes: function(proxyRes, req, res){

        proxyRes.headers['Access-Control-Allow-Origin'] = '*';

        if (req.headers['access-control-request-method']) {
          res.setHeader('access-control-allow-methods', req.headers['access-control-request-method']);
        }

        if (req.headers['access-control-request-headers']) {
          res.setHeader('access-control-allow-headers', req.headers['access-control-request-headers']);
        }

    },
    pathRewrite: {
      '^/acgoogle' : '/'
    }
  }
)); 

@tiagosteil
Copy link
Author

Try to use the URL in your log in a web-browser. If you do not see Google page, proxy is not working.

When I access the proxy URL I see the following page...

captura de tela 2017-04-18 as 09 04 08

When I access the link that is in the chrome console error, I see the following page

captura de tela 2017-04-18 as 10 54 36

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

No branches or pull requests

5 participants