A very simple demo of OAuth 2.0 using Node.js,to add GitHub login to your app and access GitHub API.
This demo is slightly modified from sohamkamani's node-oauth-example. More details in his blog (English) or my blog (Chinese).
Step one: register the app
Register the app on Github : https://github.com/settings/applications/new .
- "Application name" field, enter any name you like.
- "Homepage URL" field, enter "http://localhost:8080/ ".
- "callback URL" field, enter "http://localhost:8080/oauth/redirect ".
Once register, you will get a client ID and a client secret.
Step two: get the code
First, clone the repo.
$ git clone [email protected]:ruanyf/node-oauth-demo.git
$ cd node-oauth-demo
Second, modify the config.
index.js
: replace the values of theclientID
andclientSecret
variables.public/index.html
: replace the values of theclient_id
variable.
Third, install the dependencies.
$ npm install
Step three: run the server
Now, run the server.
$ node index.js
Visit http://localhost:8080 in your browser, and click the link to login GitHub.