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

Easier local debugging for OAuth2 providers #1988

Open
nriesco opened this issue Jun 9, 2020 · 2 comments
Open

Easier local debugging for OAuth2 providers #1988

nriesco opened this issue Jun 9, 2020 · 2 comments

Comments

@nriesco
Copy link

@nriesco nriesco commented Jun 9, 2020

The problem

When doing local tests in order to try/test external OAuth2 service providers, it gets really hard to work with localhost on NODE_ENV that are not 'development' or 'test'.

It would be very simple and a big deal for local testing to instead of forcing http/https and port number based on the environment name, to be able to set it in the config file.

The code:

let protocol = 'https';
// Development environments commonly run on HTTP with an extended port
if (app.get('env') === 'development') {
protocol = 'http';
if (String(port) !== '80') {
host += ':' + port;
}
}

What could be done:

Replace: let protocol = 'https';

With: let protocol = get('protocol') || 'https';

And remove:

  // Development environments commonly run on HTTP with an extended port
  if (app.get('env') === 'development') {
    protocol = 'http';
    if (String(port) !== '80') {
      host += ':' + port;
    }
  }
@daffl
Copy link
Member

@daffl daffl commented Jun 9, 2020

You should already be able to overwrite host and protocol in the oauth configuration settings defaults:

{
  "authentication": {
    "oauth": {
      "redirect": "/frontend",
      "defaults": {
        "host": "localhost",
        "protocol": "https"
      },
      "google": {
        "key": "...",
        "secret": "...",
        "custom_params": { "access_type": "offline" }
      },
      "twitter": {
        "key": "...",
        "secret": "..."
      }
    }
  }
}
@nriesco
Copy link
Author

@nriesco nriesco commented Jun 10, 2020

I tried that but is not just the protocol, is also that is not using the same port. For instance I run a server locally that has a different config (it will connect to a remote database) so is not my development environment but my "local-remote" environment.

That will create an OAuth callback link like this: http://localhost/oauth/google/authenticate instead of http://localhost:3000/oauth/google/authenticate.

Maybe, to avoid potencial security issues (ensuring https, etc.), the appropriate solution would be to change this line:

if (app.get('env') === 'development') {

From: if (app.get('env') === 'development') { to if (app.get('env').indexOf('development') !== -1) {

That way any development-something environments could behave that way (I would change mine to development-remote in that case.

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

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.