🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

turbasen-auth

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

turbasen-auth

Authenticate group users in Nasjonal Turbase

latest
Source
npmnpm
Version
2.0.0
Version published
Maintainers
1
Created
Source

Nasjonal Turbase Auth

Build status NPM downloads NPM version Node version Dependency status

Authenticate group (grupper) users in Nasjonal Turbase with 0 effort. Just install, and start using it.

Requirements

  • Node.JS >= 0.10
  • Nasjonal Turbase API key

Install

npm install turbasen-auth --save

Test

npm test

Usage

var auth = require('turbasen-auth');

Configure

This package uses the official Node.JS library for Nasjonal Turbase (turbasen.js) which can be fully configured using the environment variables:

  • NTB_API_KEY - API key for authenticate requests
  • NTB_API_ENV - API environment (default api, can be dev)
  • NTB_USER_AGENT - User Agent for API requests

You can also set or update the configuration programmatically using the auth.turbasen.configure() method.

auth.authenticate()

Authenticate user against Nasjonal Turbase.

Params

  • string email - user email
  • string password - user password
  • string callback - callback function (Error error, object user)

Return

The returned user object contains navn (name), epost (email), and gruppe (group).

{
  "navn": "Foo User Name",
  "epost": "foo@bar.com",
  "gruppe": {
    "_id": "54759eb3c090d83494e2d804",
    "navn": "Bix Group Name"
  }
}

Example

auth.authenticate(email, password, function(error, user) {
  if (error) {
    // Something went horrible wrong
    console.error(error);
  } else if (user) {
    console.log('Hello %s!', user.navn);
  } else {
    console.log('Authentication failed!');
  }
});

auth.middleware()

A Connect / Express compatible middleware to make authentication super easy.

Body Params

The following params must be sent as JSON in the request body.

  • string email - user email
  • string password - user password

Return

If the authentication succeeds the user information (identical to authenticate()) will be available in the req.turbasenAuth variable.

Example

See server.js for a complete Express example.

app.post('/auth', auth.middleware, function(req, res){
  // req.turbasenAuth
});

auth.createUserAuth()

Create user authentication object for storage in Nasjonal Turbase.

Params

  • string name - user name
  • string email - user email
  • string password - user password
  • string callback - callback function (Error error, object user)

Return

The returned user object contains navn (name), epost (email), and pbkdf2 (user authentication).

{
  "navn": "Foo User Name",
  "epost": "foo@bar.com",
  "pbkdf2": {
    "prf": "HMAC-SHA1",
    "itrs": 131072,
    "salt": "XO6rZj9WG1UsLEsAGQH16qgZpCM9D7VylFQzwpSmOEo=",
    "dkLen": 256,
    "hash": "Ir/5WTFgyBJoI3pJ8SaH8qWxdgZ0my6qcOPVPHnYJQ4="
  }
}

Example

auth.createUserAuth(name, email, password, function(error, user) {
  if (error) {
    throw error;
  }

  console.log(user);
  }
});

MIT Licensed

Keywords

SSO

FAQs

Package last updated on 15 Feb 2016

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