1.1.7 • Published 3 years ago

rauth v1.1.7

Weekly downloads
78
License
MIT
Repository
github
Last release
3 years ago

RAuth 🔏 - Reign Authorization and Authentication library

  • Travis Master: Build Status
  • Travis Develop: Build Status

RAuth library provides a simple way for using Authorization and Authentication via JWT encapsulating their main methods. Allows to handle multiple sessions ensuring trust between an application and its users.

How to use

$ npm install rauth

Create a session control

import 'rauth/engines/SQLiteEngine';
import { SessionControl } from 'rauth/session/SessionControl';

const sessionControl = new SessionControl({ engineConnectionStore: 'SQLite' });

Create an authorization handler

This handler allows create the session

// Handler to GET /authorize?grant_type=basic

// Here is your method to validate the credentials

const session = await sessionControl.createSession(username);

res.setHeader('Content-Type', 'application/json');
return res.end(JSON.stringify(session), 'utf8');

Validate token

const token = query.token;
const session = await sessionControl.verify(token);

Create a refresh token handler

This handler allows refresh the session.

// Handler to GET /authorize?grant_type=refresh_token&refresh_token=...
const refreshToken = query.refresh_token;

const session = await sessionControl.refreshSession(refreshToken);

res.setHeader('Content-Type', 'application/json');
return res.end(JSON.stringify(session), 'utf8');

Create a revoke token handler

This handler allows revoke a refresh token.

// Handler to GET /logout
await sessionControl.revokeSession(session);

res.setHeader('Content-Type', 'application/json');
return res.end(JSON.stringify(session), 'utf8');

Revoke all tokens

await sessionControl.revokeAllSessions(session)

List all session

const sessions = await sessionControl.getAllSessions(session);

Engines

The engines help control the session storage. Currently, RAuth provides following engines:

  • Mongoose rauth/engines/MongooseEngine (Sample)
  • SQLite rauth/engines/SQLiteEngine (Requires sqlite installed)
  • Memory rauth/engines/MemoryEngine
  • TypeORM rauth/engines/TypeormEngine (Sample Requires typeorm installed)

Samples

Mongoose:

import 'rauth/engines/MongooseEngine';
export const sessionControl = new SessionControl({
  connectionStore: new ConnectionStore('Mongoose', { model: SessionModel }),
});

Memory:

import 'rauth/engines/MemoryEngine';
export const sessionControl = new SessionControl({
  engineConnectionStore: 'Memory',
});

SQLite:

import 'rauth/engines/SQLiteEngine';
export const sessionControl = new SessionControl({
  engineConnectionStore: 'SQLite',
});
// Or
import 'rauth/engines/SQLiteEngine';
export const sessionControl = new SessionControl({
  connectionStore: new ConnectionStore('SQLite', {
    filename: `${__dirname}/db.sqlite`,
    table: 'sessions',
  }),
});

Typeorm:

import '../engines/TypeormEngine';
export const sessionControl = new SessionControl({
  connectionStore: new ConnectionStore('Typeorm', { entity: Session }),
});
2.0.0-beta.2

3 years ago

2.0.0-beta.1

3 years ago

2.0.0-beta.0

3 years ago

1.1.7

3 years ago

1.1.6

3 years ago

1.1.6-beta.2

4 years ago

1.1.6-beta.1

4 years ago

1.1.6-beta.0

4 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.3-alpha.3

4 years ago

1.1.3-alpha.1

4 years ago

1.1.3-alpha.2

4 years ago

1.1.3-alpha.0

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.1.0-beta.1

4 years ago

1.1.0-beta.0

4 years ago

1.0.24

5 years ago

1.0.23

5 years ago

1.0.16

5 years ago

1.0.15

5 years ago

1.0.14

5 years ago

1.0.13

5 years ago

1.0.12

5 years ago

1.0.11

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago