UNPKG

4.82 kBMarkdownView Raw
1# @node-plex/api-auth
2
3> **Authorizes external applications to use the Plex API.**
4
5[![CI pipeline status][ci-badge]][ci-url]
6[![project vulnerabilities][vulnerabilities-badge]][vulnerabilities-url]
7[![project dependencies][dependencies-badge]][dependencies-url]
8[![code coverage][coverage-badge]][coverage-url]
9[![code style standardjs][standardjs-badge]][standardjs-url]
10[![versioning strategy][semver-badge]][semver-url]
11![required Node version][node-version-badge]
12
13<!-- badge images and URLs -->
14[ci-badge]: https://gitlab.com/node-plex/api-auth/badges/master/pipeline.svg
15[ci-url]: https://gitlab.com/node-plex/api-auth
16[coverage-badge]: https://gitlab.com/node-plex/api-auth/badges/master/coverage.svg?job=pages
17[coverage-url]: https://node-plex.gitlab.io/api-auth/master/coverage
18[dependencies-badge]: https://img.shields.io/librariesio/release/npm/@node-plex/api-auth
19[dependencies-url]: https://www.npmjs.com/package/@node-plex/api-auth?activeTab=dependencies
20[node-version-badge]: https://img.shields.io/node/v/@node-plex/api-auth?logo=node.js
21[semver-badge]: https://img.shields.io/static/v1?logo=&label=semver&message=standard-version&color=brightgreen&style=flat
22[semver-url]: https://github.com/conventional-changelog/standard-version
23[standardjs-badge]: https://img.shields.io/static/v1?logo=&label=code%20style&message=standard&color=brightgreen&style=flat
24[standardjs-url]: https://standardjs.com/
25[vulnerabilities-badge]: https://img.shields.io/snyk/vulnerabilities/npm/@node-plex/api-auth?logo=snyk
26[vulnerabilities-url]: https://snyk.io/vuln/search?q=%40node-plex%2Fapi-auth&type=npm
27
28## Releases
29
30[![latest release version][stable-release-badge]][npm-url]
31[![next release version][next-release-badge]][npm-url]
32[![package install size][install-size-badge]][install-size-url]
33
34<!-- badge images and URLs -->
35[install-size-badge]: https://packagephobia.now.sh/badge?p=@node-plex/api-auth
36[install-size-url]: https://packagephobia.now.sh/result?p=@node-plex/api-auth
37[next-release-badge]: https://img.shields.io/npm/v/@node-plex/api-auth/next?label=@next&logo=npm
38[npm-url]: https://npmjs.org/package/@node-plex/api-auth
39[stable-release-badge]: https://img.shields.io/npm/v/@node-plex/api-auth/latest?label=%40latest&logo=npm
40[standardjs-badge]: https://img.shields.io/static/v1?logo=&label=code%20style&message=standard&color=brightgreen&style=flat
41
42## Getting Started
43
44### Installation
45```sh
46$ npm install @node-plex/api-auth
47```
48
49### Usage
50```javascript
51const PlexAppAuthenticator = require('@node-plex/api-auth')
52
53const paa = new PlexAppAuthenticator({
54 headers: {
55 'X-Plex-Client-Identifier': '<your application uuidv4>',
56 'X-Plex-Product': '<your application name>',
57 'X-Plex-Version': '<your application version>',
58 },
59 password: '<your Plex password>',
60 username: '<your Plex username>',
61})
62
63paa.authorize()
64 .then(console.log) // resolves to auth token as String
65 .catch(console.error)
66```
67
68> :information_source: `headers` key may contain:
69>```javascript
70>// an object with header name:value pairs
71>{ 'X-Header': 'value' }
72>```
73>```javascript
74>// a Header instance
75>const headers = new Headers()
76>headers.set('X-Header', 'value')
77>```
78
79> :information_source: `headers` _must_ include:
80>```json
81>"X-Plex-Client-Identifier",
82>"X-Plex-Product",
83>"X-Plex-Version"
84>```
85
86## Built with
87
88[![Fedora Linux](https://img.shields.io/static/v1?logo=fedora&label=Fedora&message=workstation&color=294172&style=flat)](https://getfedora.org/)
89[![VSCode](https://img.shields.io/static/v1?logo=visual-studio-code&label=VSCode&message=insiders&color=2A917D&style=flat)](https://code.visualstudio.com/)
90[![GitLab](https://img.shields.io/static/v1?logo=gitlab&label=GitLab&message=FOSS&color=DE4020&style=flat)](https://gitlab.com/gitlab-org/gitlab)
91[![Caffeine](https://img.shields.io/static/v1?logo=buy-me-a-coffee&label=Caffeine&message=☕&color=603015&style=flat)](https://en.wikipedia.org/wiki/Caffeine)
92
93## Contributing
94
95Please read [CONTRIBUTING.md](https://gitlab.com/node-plex/api-auth/-/blob/master/CONTRIBUTING.md) for details on how to contribute to this project.
96
97## License
98
99[![NPM][license-badge]][license-url]
100
101Copyright 2020 © [Chet Manley](https://gitlab.com/chet.manley).
102
103<!-- badge images and URLs -->
104[license-badge]: https://img.shields.io/npm/l/@node-plex/api-auth
105[license-url]: https://gitlab.com/node-plex/api-auth/-/blob/master/LICENSE
106
107## Acknowledgements
108
109Based on [phillipj's](https://github.com/phillipj) [node-plex-api-credentials](https://github.com/phillipj/node-plex-api-credentials/), this rewrite aims to improve upon it in two major ways:
110
111- Implement the most current official token retrieval method [provided by Plex](https://forums.plex.tv/t/how-to-request-a-x-plex-token-token-for-your-app/84551).
112- Use ES2015+ code conventions and best practices.
113
\No newline at end of file