New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

hapi-authorized-scope

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hapi-authorized-scope

hapi plugin to require multiple authentication strategies

  • 1.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source
hapi-authorized-scope logo

Determine which scope authorized a user on a route.


Installation · Usage



Build Status hapi-authorized-scope Version Greenkeeper badge

Follow @marcuspoehls for updates!


The Future Studio University supports development of this hapi plugin 🚀
Join the Future Studio University and Skyrocket in Node.js


Introduction

The hapi-authorized-scope plugin determines and stores the scope that authorized an authenticated request. You'll find the scope authorizing the request in request.auth.authorizedScope.

In hapi, you’ll find all auth-related details in request.auth, that’s the reason this plugin adds the authorizedScope property there:

{
  isAuthenticated: true,
  isAuthorized: true,
  credentials: { username: 'marcus', scope: ['admin', 'user'] },
  artifacts: null,
  strategy: 'test',
  mode: 'required',
  error: null,
  isInjected: true,
  authorizedScope: 'user'  // <-- added: the authorized scope that let the user access a route
}

Installation

Add hapi-authorized-scope as a dependency to your project:

npm i hapi-authorized-scope

Usage

The usage is pretty straightforward: register the plugin to your hapi server and that’s it:

await server.register({
  plugin: require('hapi-authorized-scope')
})

// went smooth like chocolate :)

hapi-authorized-scope extends the request lifecycle onPostAuth and finds the first scope in the authenticated credentials that authorizes the request to access the route.

In your route handlers or request lifecycle extension points, you may access the authorized scope like this:

{
  method: 'GET',
  path: '/profile',
  options: {
    handler: async (request, h) {
      const authorizedScope = request.auth.authorizedScope

      Logger.debug(`Scope authorizing the user to access this route: ${authorizedScope}`)

      return h.view('profile')
    }
  }
}

Enjoy!

Contributing

  1. Create a fork
  2. Create your feature branch: git checkout -b my-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request 🚀

License

MIT © Future Studio


futurestud.io  ·  GitHub @futurestudio  ·  Twitter @futurestud_io

Keywords

FAQs

Package last updated on 14 Oct 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc