Skip to content

Commit 0244b37

Browse files
committed
Merge branch 'master' of github.com:MrSwitch/node-oauth-shim
2 parents d690789 + bf9a2dd commit 0244b37

File tree

3 files changed

+52
-2
lines changed

3 files changed

+52
-2
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
node_modules/
1+
node_modules/
2+
.env

README.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ var oauthshim = require('oauth-shim'),
2222
express = require('express');
2323

2424
var app = express();
25+
app.listen(3000);
2526
app.all('/oauthproxy', oauthshim);
2627

2728
// Initiate the shim with Client ID's and secret, e.g.
@@ -32,10 +33,34 @@ oauthshim.init({
3233
});
3334
```
3435

36+
The above code will put your shimming service to the pathname `http://localhost:3000/oauthproxy`.
3537

3638

39+
## Example
40+
41+
An example of the above script can be found at [example.js](./example.js).
42+
43+
To run `node example.js` locally:
44+
45+
* Install developer dependencies `npm install -l`.
46+
* Create a `.env` file with a `NETWORK_ID` and `NETWORK_SECRET`. e.g.
47+
48+
```bash
49+
TWITTER_ID='twit1234'
50+
TWITTER_SECRET='secret1234'
51+
YAHOO_ID='yahoo1234'
52+
YAHOO_SECRET='secret1234'
53+
```
54+
55+
* Then start up the server...
56+
57+
```bash
58+
PORT=5500 env $(cat .env | xargs) node example.js
59+
```
60+
61+
This sets the `.env` lines as local environment variables and will startup a server on port 5500. Now define your `redirect_uri` via `hello.init` to point to `http://localhost:5500/proxy`.
62+
3763

38-
The code above says apply the shim to all requests to the pathname `/oauthproxy`.
3964

4065
## Customised Middleware
4166

example.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Demonstation of integration
2+
var oauthshim = require('./index.js'),
3+
express = require('express');
4+
5+
var app = express();
6+
7+
// Define a path where to put this OAuth Shim
8+
app.all('/proxy', oauthshim);
9+
10+
// Create a key value list of {client_id => client_secret, ...}
11+
var creds = {};
12+
13+
// Set credentials
14+
if (process.env.YAHOO_ID) creds[process.env.YAHOO_ID] = process.env.YAHOO_SECRET;
15+
if (process.env.TWITTER_ID) creds[process.env.TWITTER_ID] = process.env.TWITTER_SECRET;
16+
17+
18+
// Initiate the shim with Client ID's and secret, e.g.
19+
oauthshim.init(creds);
20+
21+
// Set application to list on PORT
22+
app.listen(process.env.PORT);
23+
24+
console.log("OAuth Shim listening on "+process.env.PORT);

0 commit comments

Comments
 (0)