Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ruanyf/node-oauth-demo
A very simple demo of OAuth2.0 using node.js
https://github.com/ruanyf/node-oauth-demo
Last synced: 8 days ago
JSON representation
A very simple demo of OAuth2.0 using node.js
- Host: GitHub
- URL: https://github.com/ruanyf/node-oauth-demo
- Owner: ruanyf
- Created: 2019-04-14T14:52:23.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-06-13T09:43:13.000Z (over 5 years ago)
- Last Synced: 2024-08-01T13:28:40.730Z (3 months ago)
- Language: JavaScript
- Homepage:
- Size: 19.5 KB
- Stars: 321
- Watchers: 8
- Forks: 189
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
A very simple demo of OAuth 2.0 using Node.js,to add GitHub login to your app and access GitHub API.
![](https://www.wangbase.com/blogimg/asset/201904/bg2019042103.jpg)
This demo is slightly modified from sohamkamani's [node-oauth-example](https://github.com/sohamkamani/node-oauth-example). More details in his [blog](https://www.sohamkamani.com/blog/javascript/2018-06-24-oauth-with-node-js/) (English) or my [blog](http://www.ruanyifeng.com/blog/2019/04/github-oauth.html) (Chinese).
## Step one: register the app
Register the app on Github : https://github.com/settings/applications/new .
![](https://www.wangbase.com/blogimg/asset/201904/bg2019042102.jpg)
- "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.
```bash
$ git clone [email protected]:ruanyf/node-oauth-demo.git
$ cd node-oauth-demo
```Second, modify the config.
- `index.js`: replace the values of the `clientID` and `clientSecret` variables.
- `public/index.html`: replace the values of the `client_id` variable.Third, install the dependencies.
```bash
$ npm install
```## Step three: run the server
Now, run the server.
```bash
$ node index.js
```Visit http://localhost:8080 in your browser, and click the link to login GitHub.