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

electrode-ota-server-auth-basic

v4.8.4

Published

electrode-ota-server-auth-basic === This project is part of the [electrode-ota-server](https://github.com/electrode-io/electrode-ota-server)

Downloads

119

Readme

electrode-ota-server-auth-basic

This project is part of the electrode-ota-server

It is not meant to be used standalone, use at your own risk.

Install

$ npm install electrode-ota-server-auth-basic --save

Usage

Electrode OTA authentication is based on HapiJS authenication and BellJS. See https://hapijs.com/tutorials/auth for HapiJS authentication. https://github.com/hapijs/bell

You can define your authentication strategy with the electrode-ota-server-auth module. In this example, we define a validateFunc within the options of the the basic auth. Note you have to convert your config json file to a js file under <root>/config/default.json

module.exports = {
"plugins": {
   "electrode-ota-server-auth": {
      "options": {
         "strategy": {
            "github-oauth": {
               "enable": false
            },
            "basic": {
               "module": "electrode-ota-server-auth-basic",
               "scheme": "basic",
               "options": {
                  "realm": "My Realm",
                  "validateFunc": (request, username, password, callback) => {
                     const err = null;
                     const isValid = true;
                     const provider = "basic-auth";
                     const profile = { email:"[email protected]", displayName:"John Doe", username:"johndoe" };
                     const credentials = { provider, profile };
                     callback(err, isValid, credentials);
                  }
               }
            }
         }
      }
   }
   "electrode-ota-server-routes-auth": {
      options: {
        providers: [
          {
            name: "basic",
            auth: "basic",
            label: "Basic Authentication",
            icon: {
              src: "https://examples.com/myLogo.png",
              height: 50,
              width: 50
            }
          }
        ]
      }
    }
  }
};
  • We disabled github-oauth (the default behavior)
  • Then we define options for electrode-ota-server-auth-basic
  • In the options, define your validateFunc. Note the credentials matches what BellJS expects.
  • Then we override the electrode-ota-server-routes-auth with our basic route. Replace icon with your desired icon. This adds the "Basic Authentication" link to the homepage. This link will authenticate using "basic" strategy defined above.

Then restart the OTA server. If you have an error complaining about github, make sure you have the electrode-ota-server-routes-auth defined, and you disable github-oauth as specified above.

Another method to do the same thing is by creating your own validation module; by overriding electrode-ota-server-auth-validate. Create a new package. Copy the contents of electrode-ota-server-auth-validate package.json and index.js. Modify index.js to add your validation method.

In this example, we added the basic validation function.

const register = diregister.default({
    name: 'ota!validate',
    dependencies: ['ota!account'],
    multiple: false,
    connections: false
}, (options, {validateFunc}) => {

    const token = (name, callback) => validateFunc(name).then(profile => callback(null, true, {
        email: profile.email,
        name
    }), () => callback(null, false));

    // validates existing session
    const session = (request, session, callback) => token(session.token, callback);


    return {
        // name matches "validate" field in "electrode-ota-server-auth" config
        basic(r, username, password, callback){
            // TODO:
            //      validate username, password
           // credentials objects matches hapijs/bell credentials format.
           // {
           //          provider: 'custom',
           //          query: {},
           //          profile: {
           //                         id: '1234567890',
           //                         username: 'steve',
           //                         displayName: 'steve',
           //                         email: '[email protected]'
            //         }
            //   }
            callback(error, isValid, credentials);
        },
        token,
        session
    };
});
module.exports = {register};

In the config, override electrode-ota-server-validate with your custom validate. Provide options as desired.

const root = path.join.bind(path, __dirname, "..");

module.exports = {

   "electrode-ota-server-auth-validate": {
        "module": root("lib/my-custom-auth-validate"),
        "options": {}
   }

}

Then, in the config, use this validate method. Note the basic name matches those defined in your my-custom-auth-validate.

{
 
 "plugins":{

           "electrode-ota-server-auth": {
            "options": {
                "strategy": {
                    "github-oauth": {
                        "enable": false
                    },
                    
                    "basic": {
                        "module":"electrode-ota-server-auth-basic",
                        "scheme": "basic",
                        "validate": "basic",
                        "options": {
                            "realm": "<YOUR_REALM>"
                        }
                    }
                }
            }
        },
        "electrode-ota-server-routes-auth": {
    "options": {
        "providers": [
            {
                "name": "basic",
                "auth": "basic",
                "label": "Basic Authentication",
                "icon": {
                    "src": "https://examples.com/myLogo.png",
                    "height": 50,
                    "width": 50
                }
            }
        ]
    }
},
    }
}