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 blacklist all routes to use a plugin config? #2264

Closed
toymachiner62 opened this issue Dec 8, 2014 · 9 comments
Closed

How to blacklist all routes to use a plugin config? #2264

toymachiner62 opened this issue Dec 8, 2014 · 9 comments
Assignees
Labels
Milestone

Comments

@toymachiner62
Copy link

@toymachiner62 toymachiner62 commented Dec 8, 2014

I'm curious what the best approach is to blacklist all routes by default to use a plugin config. I'm working on my hapi-authorization plugin which works great for routes you add the plugin config to, but this could easily be missed by a developer.

I'm wondering if there is an option or something so that I can have all my routes automatically use this in their config plugins: {'hapiAuthorization': {roles: ['AUTHORIZED']}}, without having to specify it on every route, but then I would be able to override or disable this on each route individually if required.

@toymachiner62 toymachiner62 changed the title How to blacklist all routes to use a plugin? How to blacklist all routes to use a plugin config? Dec 8, 2014
@hueniverse
Copy link
Contributor

@hueniverse hueniverse commented Dec 8, 2014

In version 8.0 you can easily specify the default when you setup the server or add a connection:

var server = new Hapi.Server({
    connections: {
        routes: {
            plugins: {
                hapiAuthorization: { roles: ['AUTHORIZED'] }
            }
        }
    }
});

@hueniverse hueniverse closed this Dec 8, 2014
@hueniverse hueniverse self-assigned this Dec 8, 2014
@hueniverse hueniverse added this to the 8.0.0 milestone Dec 8, 2014
@toymachiner62
Copy link
Author

@toymachiner62 toymachiner62 commented Dec 8, 2014

Awesome. How would you disable it completely on an individual route?

like this?

config: {
  plugins: {
    hapiAuthorization: false
  }
}

@hueniverse
Copy link
Contributor

@hueniverse hueniverse commented Dec 8, 2014

yep

@toymachiner62
Copy link
Author

@toymachiner62 toymachiner62 commented Dec 9, 2014

I don't think this is working to disable a plugin for an individual route:

var server = new Hapi.Server();
server.connection({
    host: '0.0.0.0',
    port: 3000,
    routes: {
        plugins: {
            hapiAuthorization: { roles: ['AUTHORIZED'] }
        }
    },
});

Route config:

config: {
  plugins: {
    hapiAuthorization: false
  }
}

When access this route, it's still calling code for the plugin which should be disabled.

@hueniverse
Copy link
Contributor

@hueniverse hueniverse commented Dec 9, 2014

What's the route plugin config for this route?

@toymachiner62
Copy link
Author

@toymachiner62 toymachiner62 commented Dec 9, 2014

What do you mean? I'm trying to make all routes have this plugin config by default:

plugins: {
  hapiAuthorization: { roles: ['AUTHORIZED'] }
}

But I'm trying to disable the plugin for this one route.

@hueniverse
Copy link
Contributor

@hueniverse hueniverse commented Dec 9, 2014

hapi doesn't do anything with this config. Your plugin has to check route.settings.plugins.hapiAuthorization and decide what to do.

@toymachiner62
Copy link
Author

@toymachiner62 toymachiner62 commented Dec 9, 2014

Oh ok thanks.

@Marsup Marsup added feature and removed request labels Sep 20, 2019
@lock
Copy link

@lock lock bot commented Jan 9, 2020

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants