An intermediate nodejs server for github authentication(OAuth2-passport).
This server is used by web applications that maintain only a client-side and therefore cannot make an OAuth2 authentication.
Make sure you have Node.js v6 or greater installed, if not follow te below instructions:
# Run one of the following
# for Node.js v6
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
# OR for Node.js v7
curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -
Then run:
sudo apt-get install -y nodejs
If you have an older version you can update with:
sudo apt-get purge nodejs npm
Clone the repo
$ git clone https://github.com/Temeteron/node-github-oauth-starter-kit
$ cd node-github-oauth-starter-kit
Install dependencies
$ npm install
Run the app
$ npm start
You can test the project by accessing the following link which will redirect you to the GitCV web application with the accessToken: http://127.0.0.1:3000/https://www.gitcv.com/%23/
- Fork/Clone/Dowload the project
- Install the dependencies
- Change the configuration of GitHub ids info in file server/_config.js. You must change the clientID, clientSecret, callbackURL. The first two can be generated here by registering a new application. The callbackURL is the url that your nodejs server will redirect after the OAuth. This url must be the same in both your code and your registered application.
- Get the accessToken that GitHub will provide to your server. Assume that the callbackURL you provided is: "http://www.mygithubcallbackurl.com/users/". Your nodejs server will concat the accessToken at the end of the callbackURL. Thus, the url that you will be redirected after the OAuth is: "http://www.mygithubcallbackurl.com/users/{myaccesstoken}" where 'myaccesstoken' is a string. After that you can use that token, as a parameter, to make authenticated requests like the following: "https://api.github.com/users/${username}/orgs?access_token=${myaccesstoken}"
- Add your mongodb configuration info in file server/app.js. You can either add a URI to your local mongodb, or get free one at mLab. (A more easier way for mLab is described at the next section)
You can deploy your nodejs server to HEROKU.
- Just log in, or sing up if you haven't, press the button "New" and select "New application".
- Name you application and select a region runtime of your choice.
- After that you can deploy with one of the 3 reccomended ways that are provided.
- You can add a free mongodb database from the dashboard of heroku at "Overview" tab, by searching "mLab Mongodb" at the add-ons section. After accessing mLab by just clicking on it, you must copy and paste the configuration URI (mongodb://:@<your_database>), which is provided from me mLab, to your app.js file. The arg "<your_database>" is already provided from mLab at the basic info of your database. About the "dbuser" and the "dbpassword" of your database you must go to the "users" tab of mLab and add a new "database user". The username and the password that you will use is what you need to copy and paste at the mongodb URI. A full mongodb URI is something like the following one:
mongodb://<dbuser>:<dbpassword>@<your_database> // base URI
mongodb://MyNewUser10:[email protected]:35533/heroku_xad5 // full URI, the one to use
Note: The Procfile that is needed for deployment to heroku is already provided in the repository.