0.0.5 • Published 10 years ago

express-battlenet-oauth v0.0.5

Weekly downloads
3
License
MIT
Repository
github
Last release
10 years ago

express-battlenet-oauth

Handy sub-app for quickly adding Battle.net (https://dev.battle.net) OAuth to your express application.

####Installation

$ npm install express-battlenet-oauth

####Read Before Getting Started

See http://us.battle.net/en/forum/topic/13977887738#8 for more information.

DISCLAIMER: The following will seem silly to point out, because without sessions enabled authentication is kind of pointless, however, please read it anyway.

While not strictly required, it is highly recommended you enable sessions in your application and make the session available through req.session. If you don't do this, pseudo-random state parameters cannot be created to prevent unauthorized 3rd party authentication attempts.

####Minimal Implementation

var express = require('express');
var app = express();

var bnet = require('express-battlenet-oauth');

var server = app.listen(8080, function() {
  console.log('Listening on port %d', server.address().port);
});

app.set('BNET_ID', '[YOUR BATTLE.NET APPLICATION KEY/ID]');
app.set('BNET_SECRET', '[YOUR BATTLE.NET APPLICATION SECRET]');
app.set('BASE_URL', 'https://yoursecuredomain.com');
app.set('LOGIN_SUCCESS', function(req, res){ 
  //battle.net oauth token is available in res.token_data for whatever your needs are
});
app.set('LOGIN_FAILURE', function(req, res){ 
  //error is available in res.error for you to handle user permission denial or other errors
});

app.use('/', bnet);

//Setup your express app like normal

For a full example please see: https://github.com/battlejj/express-battlenet-oauth/blob/master/examples/index.js

The example should be fully functional as is if you plop in your API Key and Secret and from the root folder run

npm install

I've included a localhost SSL private key and certificate to be used for testing. It will require you to accept a security exception since it is a self signed certificate. Chrome is the most ominous about this warning.

####Options All options for express-battlenet-oauth are set in your main express app via:

app.set('VARIABLE_NAME', value);

The only non-optional fields are BASE_URL, BNET_ID and BNET_SECRET, however, without setting a LOGIN_SUCCESS, LOGIN_FAILURE function you won't be able to do much useful with the authentication.

#####Options List