<commit_before># just-auth

[![Build Status][travis-badge]][travis-badge-url]
[![Coverage Status][coveralls-badge]][coveralls-badge-url]

**Don't use yet, this is still a work in progress.**

Simple SPA focused token based authentication for Express.js
This library follows convention over configuration, but configuration is available :wink:.

## Installation

Download node at [nodejs.org](http://nodejs.org) and install it, if you haven't already.

```sh
npm install just-auth --save
```


## Usage

```js
var express = require('express');
var justAuth = require('just-auth');
var app = express();
var auth = justAuth({
  secret: 'c47sRfunny101',

  getUser: function (email, callback) {
    // if error: callback({ myerror: 'failure' });
    // if success: callback(undefined, { email: 'my<EMAIL>', passwordHash: <PASSWORD>..' });
  },

  configureToken: function (user) {
    // user without passwordHash
    // return data you want set on the token
  }
});

app.use('/auth', auth.router);

// Can also use `succeeded()` and `failed()` for redirects, etc.
// See https://www.npmjs.com/package/express-authentication
app.use('/api/admin', auth.middleware.required());

app.listen(80);
```

POST to `/auth/login` with `{ email: 'my<EMAIL>', password: '<PASSWORD>' }`.
Result will be JSON, e.g. `{ token: '2mkql3...' }`.

## Available Options

* `secret` - String, **required**.
* `loginEndpoint` - String, defaults to '/login'.<commit_msg>Document passsword utility<commit_after># just-auth

[![Build Status][travis-badge]][travis-badge-url]
[![Coverage Status][coveralls-badge]][coveralls-badge-url]

**Don't use yet, this is still a work in progress.**

Simple SPA focused token based authentication for Express.js
This library follows convention over configuration, but configuration is available :wink:.

## Installation

Download node at [nodejs.org](http://nodejs.org) and install it, if you haven't already.

```sh
npm install just-auth --save
```


## Usage

```js
var express = require('express');
var justAuth = require('just-auth');
var app = express();
var auth = justAuth({
  secret: 'c47sRfunny101',

  getUser: function (email, callback) {
    // if error: callback({ myerror: 'failure' });
    // if success: callback(undefined, { email: 'my@<EMAIL>', passwordHash: <PASSWORD>..' });
  },

  configureToken: function (user) {
    // user without passwordHash
    // return data you want set on the token
  }
});

app.use('/auth', auth.router);

// Can also use `succeeded()` and `failed()` for redirects, etc.
// See https://www.npmjs.com/package/express-authentication
app.use('/api/admin', auth.middleware.required());

app.listen(80);
```

POST to `/auth/login` with `{ email: 'my<EMAIL>', password: '<PASSWORD>' }`.
Result will be JSON, e.g. `{ token: '2mkql3...' }`.

_Note: To use the built in password utilities, you can use the following: `var pass = require('just-auth/lib/password');`.
This has two functions, `pass.validate(pass, hash)` and `pass.hash(pass, cb)`._

## Available Options

* `secret` - String, **required**.
* `loginEndpoint` - String, defaults to '/login'.
{'fraction_non_alphanumeric': 0.1708575112830432, 'fraction_numerical': 0.005802707930367505, 'mean_word_length': 4.268251273344652, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '547313', 'n_tokens_mistral': 1015, 'n_tokens_neox': 975, 'n_words': 304}