npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

loopback-component-auth

v1.1.1

Published

Extends loopback-component-passport to support custom auth schemes (i.e. other than the supported 'ldap', 'local', 'oauth', 'oauth1', 'oauth 1.0', 'openid', 'openid connect' and 'oauth 2.0')

Downloads

8

Readme

NPM version Dependency Status

loopback-component-auth

Extends loopback-component-passport to support custom auth schemes (i.e. other than the supported 'ldap', 'local', 'oauth', 'oauth1', 'oauth 1.0', 'openid', 'openid connect' and 'oauth 2.0')

Installation

$ npm install --save loopback-component-auth

(the --save option saves it as dependency in your package.json).

Mount component to your Loopback Application

This module's main export is a function that follows the component contract defined in loopback. With that said, you can configure this components declaratively in component-config.json or require this module in a boot script and call the exported function with your app object as well as options.

Example: configure declaratively

{
  "loopback-component-auth": {
    "serverBaseUrl": "https://secure.my-server.com"
  }
}

Example: configure from boot script

'use strict';

const authComponent = require('loopback-component-auth');
const authOptions = { serverBaseUrl: 'https://secure.my-server.com' };

module.exports = function bootAuthComponent(app) {
  authComponent(app, authOptions);
}

Component Options

| Name | Required | Type | Default | Description | | ---- | -------- | ---- | ------- | ----------- | | appRootDir | false | String | path.join(process.cwd(), 'server') | an absolute path referencing your Loopback Application's root directory (typically <project>/server) | | enableSessionSupport | falseBooleanfalse | is forwarded to the init method of loopback-component-passport's PassportConfigurator. Will ultimately require express-session to be installed | | contextRoot | falseString'/auth'http junction used to prefix all resources provided by this component (includes routes for providers) | | serverBaseUrl | falseString'http://localhost:3000' | base url used to url.resolve() all computed absolute urls to access resources under this component | | frontendBaseUrl | falseStringserverBaseUrl, 'http://localhost:3000' | base url used to url.resolve() successRedirect and failureRedirect urls for non-json providers. When only serverBaseUrl is provided, that value is used here as well | | models | falseObject{} | an object literal bundling information about the models described in this table. All models will default to those provided by loopback-component-passport, AccessToken, User | | models.userModel | falseStringModel'User' | String or Model instance resolving to a model to access user records. When providing a String, model instance will be resolved from app.registry.getModel('userModel') | | models.userIdentityModel | falseStringModel'UserIdentity' | String or Model instance resolving to a model to access user-identity records. When providing a String, model instance will be resolved from app.registry.getModel('userIdentityModel') | | models.userCredentialModel | falseStringModel'UserCredential' | String or Model instance resolving to a model to access user-credential records. When providing a String, model instance will be resolved from app.registry.getModel('userCredentialModel') | | models.accessTokenModel | falseStringModel'AccessToken' | String or Model instance resolving to a model to access access-token records. When providing a String, model instance will be resolved from app.registry.getModel('accessTokenModel') |

Configuring Providers

When loading this Loopback Component, it will use oniyi-config with { basePath: options.appRootDir + 'authentication', module: 'providers' }. With that said, you can configure all your authentication providers in files located e.g. at 'server/authentication' following the pattern providers.[environment].(json|js). The environment part is optional. Possible values are anything you can set in process.env.NODE_ENV. For file name resolution, process.env.NODE_ENV will be transformed to lower-case.
One special environment is local. It will always be loaded last.

Sample load order (with provess.env.NODE_ENV === 'development'):

  1. 'providers.json'
  2. 'providers.js'
  3. 'providers.development.json'
  4. 'providers.development.js'
  5. 'providers.local.json'
  6. 'providers.local.js'

Note: As files with extension json will always be loaded before files with extension js, you can provide the same file name with different extensions (meaning js will overwrite json files).

Those providers can then be either of the loopback third-party providers or a custom type with your own verify function according to the passport documentation

See server/authentication for an example

{
  "w3-connections": {
    "authScheme": "ibm-connections-basic",
    "module": "passport-ibm-connections-basic",
    "json": true,
    "session": false,
    "authHostname": "w3-connections.ibm.com",
    "openSocial": "/common"
  }
}

Noteworthy

sessions (including passport session middleware) are disabled per default.

Provideroptions

  • disabled (boolean) - default: false; when set to true, provider will not be registered
  • link (boolean)
  • module
  • strategy (string) - default: "Strategy"; name of the module's exported Property to be used as Passport Strategy
  • json
  • session

sheme options

  • makeLoginCallback (function) - receives single argument of type function (the "done" handler from passport's verify function). Must return function that takes (err, user, identity, token) as arguments and finally calls done(err, user, authInfo) according to the passport documentation. Purpose of the returned function is to serve as callback for UserIdentityModel.login(), which is documented here

strategy options

  • passReqToCallback
  • successRedirect (generated for non-json providers only, uses frontendBaseUrl as base url)
  • failureRedirect (generated for non-json providers only, uses frontendBaseUrl as base url)
  • domain
  • scope
  • failureFlash
  • authInfo

route options

routeName: any. one route with name 'auth' is always created.

  • path - - computed to: ${contextRoot}/${providerName}/${routeName}; path to register authenticate or authorize controller
  • method - (String) - Allows values of 'GET' and 'POST', defaults to 'GET' when provided value doesn't match one of the allowed values case-insensitively; method to register authenticate or authorize controller
  • bodyParser (string) - required when method === 'POST', must be one the parsers provided by body-parser module
  • bodyParserOptions (object) - optional; passed to bodyParser['bodyParser'](bodyParserOptions)
  • middleware (function)

License

Apache-2.0 © Benjamin Kroeger