# playlyfe-node-sdk

> Playlyfe SDK for NodeJS

Latest version **0.2.3** (published 2014-08-01) · 0 weekly downloads

## Install

```sh
npm install playlyfe-node-sdk
pnpm add playlyfe-node-sdk
yarn add playlyfe-node-sdk
bun add playlyfe-node-sdk
```

## Health

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

Positive: no vulnerabilities.

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

Negative: insecure dependencies; abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.3 |
| Published | 2014-08-01 |
| First published | 2013-03-12 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 (+7 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Johny Jose |
| Maintainers | atrniv |
| Keywords | playlyfe, auth, authentication, identity, oauth, api, sdk |

## Links

- npm: https://www.npmjs.com/package/playlyfe-node-sdk
- Repository: https://github.com/playlyfe/playlyfe-node-sdk
- Homepage: http://dev.playlyfe.com
- Issues: http://github.com/playlyfe/playlyfe-node-sdk/issues
- npm.io page: https://npm.io/package/playlyfe-node-sdk

## Dependencies (3)

- [lodash](https://npm.io/package/lodash.md) 2.4.1
- [request](https://npm.io/package/request.md) 2.34
- [simple-oauth2](https://npm.io/package/simple-oauth2.md) git://github.com/atrniv/simple-oauth2.git#7e8a7ba73bcb40761d392bf969f3d34f66b3f509

## 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
- [@luigi-project/plugin-auth-oauth2](https://npm.io/package/@luigi-project/plugin-auth-oauth2.md) — 2.3K weekly downloads
- [@nocobase/plugin-verification](https://npm.io/package/@nocobase/plugin-verification.md) — 2.0K weekly downloads

## Recent versions

- 0.2.3 (latest) — 2014-08-01
- 0.2.2 — 2014-06-06
- 0.2.1 — 2014-03-18
- 0.1.1 — 2014-01-15
- 0.1.0 — 2013-12-30
- 0.0.9 — 2013-10-10
- 0.0.8 — 2013-10-05
- 0.0.7 — 2013-10-05
- 0.0.6 — 2013-09-23
- 0.0.5 — 2013-07-25
- 0.0.3 — 2013-06-25
- 0.0.2 — 2013-03-13
- 0.0.1 — 2013-03-12

## README

Playlyfe Node SDK
=================

Playlyfe API implementation in NodeJS. This module integrates seamlessly with the [passport-playlyfe](https://github.com/playlyfe/passport-playlyfe) module for authentication support.

Visit the complete [API reference](https://dev.playlyfe.com/docs/api)

To learn more about how you can build applications on Playlyfe visit the [official developer documentation](https://dev.playlyfe.com)


##Install
To get started simply run

```
npm install playlyfe-node-sdk
```

##Synopsis

```javascript
express = require('express');
Playlyfe = require('playlyfe-node-sdk')

// Put in your application details here.
var config = {
  type: 'code', // The type of OAuth2.0 flow we wish use
  client_id: 'YOUR CLIENT ID',
  client_secret: 'YOUR CLIENT SECRET',
  redirect_uri: 'https://localhost:8080/auth/redirect'
};

client = new Playlyfe(config);

app = express();
app.use(express.cookieParser());
app.use(express.session({ secret: 'TOP_SECRET' }));
app.use(express.static(__dirname+"/public"));
app.use(app.router);
app.use(express.logger());
app.use(express.errorHandler());

var auth = function (req, res, next) {
  if (req.session.logged_in) {
    return next();
  } else {
    return res.redirect(client.getAuthorizationURI());
  }
};

// start playlyfe oauth authorization code flow
app.get('/auth', auth, function (req, res) {
  return res.redirect('/home');
});

// get access token and save it
app.get('/auth/redirect', function (req, res) {
  if (req.query.code !== null) {
    client.getToken(req.query.code, function(err, token) {
      if (err) return res.json(500, err);
      req.session.auth = token;
      req.session.logged_in = true;
      res.redirect('/api/player');
    });
  } else {
    res.redirect('/api/player');
  }
});

// Proxy requests to playlyfe server.
// We keep the access token away from cheaters by using the authorization code flow.
app.all('/api/*', auth, function(req, res) {
  res.header("Cache-Control", "no-cache, no-store, must-revalidate");
  res.header("Pragma", "no-cache");
  res.header("Expires", 0);
  client.api(
    '/' + req.params[0],
    req.route.method.toUpperCase(),
    { qs: req.query, body: req.body },
    req.session.auth.token.access_token,
    function(err, response, body) {
      for (header in response.headers) {
        res.header(header, response.headers[header]);
      }
      res.end(body);
    }
  );
});

app.get('/logout', auth, function (req, res) {
  req.session.logged_in = false;
  delete req.session.auth;
  res.redirect('/');
});

app.listen(8080);
```

## Methods

### constructor (options)
The options object contains the configuration options for your playlyfe application.
These values can be found in the clients menu in the game builder on the [Playlyfe Platform](https://playlyfe.com).

    {
      type: 'OAUTH_2.0_FLOW_TYPE' // Must be either code or client
      clientID: 'YOUR_CLIENT_ID',
      clientSecret: 'YOUR_CLIENT_SECRET',
      redirectURI: 'REDIRECT_URI' // Only required
    }

The redirect URI must match exactly with any of the registered redirect endpoints or the oauth flow will fail.

### getAuthorizationURI
Get the Authorization URI for the app.

### getToken (code, saveTokenFunction)
Exchange the Authorization Code for Access Token.

### api (url, method, data, access_token, callback)
Executes an API call. This method differs from the request helper in requiring the accessToken and refreshToken to be manually provided. Visit the complete [API reference](https://dev.playlyfe.com/docs/api)

## License

    Playlyfe NodeJS SDK v0.0.1
    https://dev.playlyfe.com/
    Copyright(c) 2013-2014, Playlyfe Technologies, developers@playlyfe.com

    Permission is hereby granted, free of charge, to any person obtaining a copy
    of this software and associated documentation files (the "Software"), to deal
    in the Software without restriction, including without limitation the rights
    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    copies of the Software, and to permit persons to whom the Software is
    furnished to do so, subject to the following conditions:

    The above copyright notice and this permission notice shall be included in
    all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    THE SOFTWARE.

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