# @rss/auth

> custom passport strategy and helper function for working with rss token server

Latest version **0.0.21** (published 2018-09-14) · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install @rss/auth
pnpm add @rss/auth
yarn add @rss/auth
bun add @rss/auth
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.0.21 |
| Published | 2018-09-14 |
| First published | 2017-02-26 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 9.3 KB |
| Known vulnerabilities | 0 (+5 in 3 direct dependencies) |
| Install scripts | no |
| Author | Risk & Safety Solutions |
| Maintainers | rss |

## Links

- npm: https://www.npmjs.com/package/@rss/auth
- Homepage: http://riskandsafetysolutions.com
- npm.io page: https://npm.io/package/@rss/auth

## Dependencies (5)

- [redis](https://npm.io/package/redis.md) ^2.6.5
- [request](https://npm.io/package/request.md) ^2.83.0
- [node-cache](https://npm.io/package/node-cache.md) ^4.1.1
- [jsonwebtoken](https://npm.io/package/jsonwebtoken.md) ^8.2.0
- [passport-strategy](https://npm.io/package/passport-strategy.md) ^1.0.0

## Recent versions

- 0.0.21 (latest) — 2018-09-14
- 0.0.20 — 2018-03-20
- 0.0.19 — 2018-03-19
- 0.0.18 — 2018-03-11
- 0.0.17 — 2018-03-11
- 0.0.16 — 2018-03-10
- 0.0.15 — 2017-07-20
- 0.0.14 — 2017-06-16
- 0.0.11 — 2017-05-04
- 0.0.10 — 2017-05-01
- 0.0.9 — 2017-03-08
- 0.0.8 — 2017-03-08
- 0.0.7 — 2017-03-08
- 0.0.6 — 2017-02-28
- 0.0.5 — 2017-02-28
- … 4 more at https://npm.io/package/@rss/auth/versions

## README

# @rss/auth
Helper library for working with token server.  
rss token authenticatoin strategy for passport.
## Installation

```bash
$ npm install @rss/auth
```

# Server Usage (express.js)

## Initialize 

TokenHelper must be initialize before first using any method on it or passing it into the strategy.

```js
const TokenHelper = require('@rss/auth').TokenHelper;

TokenHelper.initialize({
  tokenClientName: config.TOKEN_CLIENT_NAME,
  tokenClientKey: config.TOKEN_CLIENT_KEY,
  tokenServerURL: config.TOKEN_SERVER_URL
});
```

### Available Options

TokenHelper initialize takes an hash value with the following options.

* `tokenClientName` - Required, client name registered with the token server
* `tokenClientKey` - Required, client key for the token server
* `tokenServerURL` - Required, url location of the token server
* `redis` - Optional, configuration options for redis.  if this is not defined then fallback to using memory-cache

## Configure Strategy

The rss authentication strategy authenticates users using a token passed in on the reqeust header.   The strategy requires a `verify` callback, which accepts valid decoded token and calls `done` providing a user.

```js
passport.use(new RssStrategy({ tokenHelper: TokenHelper }, function(decodedToken, done) {
    // load user
    const user = decodedToken;
    return done(null, user);
}));
```

### Available Options

This strategy takes an hash value with the following options

* `tokenHelper` - Required, TokenHelper after its been initialize

## Authenticate Requests

Use `passport.authenticate()`, specifying the `'rss'` strategy, to
authenticate requests.

```js
app.post('/api/sample', 
  passport.authenticate('rss', { session: false }),
  function(req, res) {
    res.redirect('/');
  });
```

### Available Options

This strategy takes an hash value with the following options

* `session` - Options, save user to session - should be set to false
* `usage` - Optional, what token type is acceptable.  Default to all but can limit to `CLIENT` or  `USER`


## Token Helper API

### TokenHelper.clientToken()

Get a clientToken to use for communicating to other services.

```js
TokenHelper.clientToken().then(clientToken => {
  // clientToken can now be use for request
})
```

# Client Usage (angular)

## Initialize 

Client.checkIfAuthenticated should be call in the app.component 

```js
import { Client } from '@rss/auth/angular/client';

export class AppComponent {
  ngOnInit() {
    Client.checkIfAuthenticated(this.location, 'URL_TO_AUTHENTICATE_USER').then(() => {
      // user is authenticated - load profile
    });
  }
}

```

## Client API

### Client.checkIfAuthenticated(location, 'URL_TO_AUTHENTICATE_USER')

check if user is authenticate.  if not, redirect user to authentication url

### Client.getUserToken()

get user token if available

### Client.redirectToAuthentication('URL_TO_AUTHENTICATE_USER')

redirect user to token server for authentication

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