# basic-sso

> Basic authentication mechanism for Single sign-on

Latest version **0.4.1** (published 2017-04-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install basic-sso
pnpm add basic-sso
yarn add basic-sso
bun add basic-sso
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.4.1 |
| Published | 2017-04-27 |
| First published | 2017-02-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Matteo Maselli |
| Maintainers | daack |
| Keywords | sso, authentication, express |

## Links

- npm: https://www.npmjs.com/package/basic-sso
- Repository: https://github.com/daack/basic-sso
- Homepage: https://github.com/daack/basic-sso#readme
- Issues: https://github.com/daack/basic-sso/issues
- npm.io page: https://npm.io/package/basic-sso

## Dependencies (5)

- [atob](https://npm.io/package/atob.md) ^2.0.3
- [btoa](https://npm.io/package/btoa.md) ^1.1.2
- [cookies](https://npm.io/package/cookies.md) ^0.7.0
- [keygrip](https://npm.io/package/keygrip.md) ^1.0.1
- [diffie-hellman-key-exchange](https://npm.io/package/diffie-hellman-key-exchange.md) ^1.2.2

## Alternatives

- [@clerk/clerk-expo](https://npm.io/package/@clerk/clerk-expo.md) — 133.6K weekly downloads
- [@pothos/plugin-authz](https://npm.io/package/@pothos/plugin-authz.md) — 12.4K weekly downloads
- [@bounded-sh/client](https://npm.io/package/@bounded-sh/client.md) — 3.2K weekly downloads
- [@oxyhq/services](https://npm.io/package/@oxyhq/services.md) — 2.3K weekly downloads
- [@luigi-project/plugin-auth-oauth2](https://npm.io/package/@luigi-project/plugin-auth-oauth2.md) — 2.3K weekly downloads

## Recent versions

- 0.4.1 (latest) — 2017-04-27
- 0.4.0 — 2017-04-21
- 0.3.3 — 2017-04-20
- 0.3.2 — 2017-04-20
- 0.3.1 — 2017-04-11
- 0.3.0 — 2017-04-11
- 0.2.0 — 2017-03-01
- 0.1.0 — 2017-02-28

## README

# Basic SSO :unlock:

Basic authentication mechanism for Single sign-on

* [Install](#install)
* [Example](#example)

<a name="install"></a>

## Install

To install basic-sso, simply use npm:

```
npm install basic-sso --save
```

<a name="example"></a>

## Example

### Server

```javascript
const app = require('express')()
const Sso = require('basic-sso')

const sso = Sso('server_unique_app_name', {
	prime: 'diffie_hellman_prime',
	listen: 8001 // port for key exchange
})

const server = sso.server({
	domain: 'foo.com',
	cookie: {
		secret: 'password',
		keylist: ['foo', 'bar'],
		name: 'sso_signed',
		secure: false,
		httpOnly: true
	}
})

server.addApp('client', {
	redirect: 'http://127.0.0.1:3000/landing'
})

server.strategy('strategy', (username, password, done) => {
  const user = User.findByUsername(username)

  // Compare password

  done(null, user)
})

server.authorizeUser((user, app, done) => {
  // if user can access this app

  done(null, {
    // user info to return to client
  })
})

server.serializeUser((user, done) => {
  // What to put in the cookie
  done(null, user.id)
})

server.deserializeUser((id, done) => {
  // Retrive user from cookie
  const user = User.findById(id)
  done(null, user)
})

// Endpoint to authenticate user
app.get('/auth', server.authenticate(), (req, res, next) => {
	// render login page
})
// Endpoint to login user
app.post('/login', server.logIn('strategy'))
```

### Client

```javascript
const app = require('express')()
const Sso = require('basic-sso')

const sso = Sso('client_unique_app_name', {
	prime: 'diffie_hellman_prime',
	listen: 8002 // port for key exchange
})

const client = sso.client({
	verify: 'verify',
	server: {
		name: 'server',
		host: '127.0.0.1',
		port: 3000,
		dh_port: 8001,
		auth_path: '/auth'
	}
})

app.get('/login', (req, res) => {
	client.redirectLogIn(res)
})

app.get('/landing', client.landing(), (req, res) => {
	console.log(req.user)
})
```

---
_Source: https://npm.io/package/basic-sso · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
