<commit_before># plex-api-credentials [![Build Status](https://api.travis-ci.org/phillipj/node-plex-api-credentials.png)](http://travis-ci.org/phillipj/node-plex-api-credentials)

[plex-api](https://www.npmjs.com/package/plex-api) authenticator module which provides PlexHome credentials authentication.

*It's usually not required to install and handle this package explicitly, as username/password/managed user credentials
can be specified when creating an plex-api client.*

## Usage

```bash
$ npm install plex-api-credentials --save
```

Then provide the plex-api-credentials object to the plex-api client upon creation:

```js
const PlexAPI = require('plex-api');
const credentials = require('plex-api-credentials');

const userAndPass = credentials({
    username: 'MainParentUser',
    password: '<PASSWORD>',
    managedUser: {    // Required for Plex managed users
        name: 'RestrictedFamilyMember',
        pin: '1234' // Optional four digit pin code if user is protected
    }
});

const client = new PlexAPI({
    hostname: '192.168.0.1',
    authenticator: userAndPass
});

// use PlexAPI client as usual
client.find('/library/sections', ...);
```

## Events

### `token`

Emitted whenever a token has been retrieved from plex.tv.

### Usage

```js
userAndPass.on('token', function(token){
    // possibly cache retrieved token here?
});
```

## Contributing

Contributions are more than welcome! Create an issue describing what you want to do.
If that feature is seen to fit this project, send a pull request with the changes accompanied by tests.

### Running tests

```bash
$ npm install
$ npm test
```

To run all tests as soon as files or tests has been changed:

```bash
$ npm run test:watch
```

## Changelog

### v2.0.0

- Use plex-api-headers for generating X-Plex headers
- Changed .authenticate(apiOptions) -> .authenticate(plexApi)

### v1.0.0

Initial release. Pretty much extracted as was when the code once existed in the plex-api module itself.
<commit_msg>Preparing release notes for v3.0<commit_after># plex-api-credentials [![Build Status](https://api.travis-ci.org/phillipj/node-plex-api-credentials.png)](http://travis-ci.org/phillipj/node-plex-api-credentials)

[plex-api](https://www.npmjs.com/package/plex-api) authenticator module which provides PlexHome credentials authentication.

*It's usually not required to install and handle this package explicitly, as username/password/managed user credentials
can be specified when creating an plex-api client.*

## Usage

```bash
$ npm install plex-api-credentials --save
```

Then provide the plex-api-credentials object to the plex-api client upon creation:

```js
const PlexAPI = require('plex-api');
const credentials = require('plex-api-credentials');

const userAndPass = credentials({
    username: 'MainParentUser',
    password: '<PASSWORD>',
    managedUser: {    // Required for Plex managed users
        name: 'RestrictedFamilyMember',
        pin: '1234' // Optional four digit pin code if user is protected
    }
});

const client = new PlexAPI({
    hostname: '192.168.0.1',
    authenticator: userAndPass
});

// use PlexAPI client as usual
client.find('/library/sections', ...);
```

## Events

### `token`

Emitted whenever a token has been retrieved from plex.tv.

### Usage

```js
userAndPass.on('token', function(token){
    // possibly cache retrieved token here?
});
```

## Contributing

Contributions are more than welcome! Create an issue describing what you want to do.
If that feature is seen to fit this project, send a pull request with the changes accompanied by tests.

### Running tests

```bash
$ npm install
$ npm test
```

To run all tests as soon as files or tests has been changed:

```bash
$ npm run test:watch
```

## Changelog

### v3.0.0

- Support for managed users by [@hyperlink](https://github.com/hyperlink)

**BREAKING CHANGES:**
- Requires at least Node.js v4.0
- `constructor(username, password)` -> `constructor(options)` <br>
    Previously the constructor accepted two simple string arguments,
        this has been changed to accepting a complex options object.

### v2.0.0

- Use plex-api-headers for generating X-Plex headers
- Changed .authenticate(apiOptions) -> .authenticate(plexApi)

### v1.0.0

Initial release. Pretty much extracted as was when the code once existed in the plex-api module itself.

{'fraction_non_alphanumeric': 0.12020225235578028, 'fraction_numerical': 0.009882785566536429, 'mean_word_length': 4.03121387283237, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 9, 'https://': 5, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '434557', 'n_tokens_mistral': 1348, 'n_tokens_neox': 1263, 'n_words': 452}