This package has been deprecated

Author message:

This module is depreciated. Use passport-opskins instead.

opskins-oauth

1.1.0 • Public • Published

opskins-oauth

License: MIT


OPSkins-OAuth is a simple module, made to simplify OPSkins OAuth logins.

Installation

npm i opskins-oauth

Usage

Setup

const CustomStrategy = require('passport-custom');
const opAuth = require('opskins-oauth');
let OpskinsAuth = new opAuth.init({
	name: 'testing', // Site name displayed to users on logon
	returnURL: 'http://localhost:3037/auth/opskins/authenticate', // Your return route
	apiKey: '2087fcb59f2be98c8a5bbfe245669d', // OPSkins API key
	scopes: 'identity deposit withdraw', // Scopes you want to access
	mobile: true // Removes login navbar if true
});

passport.use('custom', new CustomStrategy(function (req, done) {
	OpskinsAuth.authenticate(req, (err, user) => {
		if (err) {
			done(err);
		} else {
			done(null, user);
		}
	});
}));

Routes

app.get('/auth/opskins', function (req, res) {
	res.redirect(OpskinsAuth.getFetchUrl());
});
app.get('/auth/opskins/authenticate', passport.authenticate('custom', {
	failureRedirect: '/'
}), function (req, res) {
	res.redirect('/');
});

Access the user object:

app.get('/', function (req, res) {
	console.log(req.user);
	res.end('test');
});

Scopes

You can find a full range of available scopes here: https://docs.opskins.com/public/en.html#scopes. For a simple logon page, only use identity.

Other

Ignore this if you're only using this module for the purposes of logging a user on

The user object returned will contain an access_token property, which can be used when calling API endpoints on behalf of the user:

let headers = {
	'Authorization': `Bearer ${req.user.access_token}`
};

This access token is valid for 30 minutes. Endpoints will return an error like this after 30 minutes:

{
    "error": "invalid_token",
    "error_description": "Bearer token has expired"
}

Simply redirect the user to /auth/opskins to get a new access token.

Example setup

https://github.com/almatrass/opskins-oauth-tutorial

Readme

Keywords

none

Package Sidebar

Install

npm i opskins-oauth

Weekly Downloads

2

Version

1.1.0

License

ISC

Unpacked Size

10 kB

Total Files

5

Last publish

Collaborators

  • almatrass