GitHub OAuth Module for NodeJS
This module gives you the ability to authenticate a user using the GitHub API.
The implementation is not complete. You can't provide scopes and it doesn't handle state right now.
Note: All Examples here are written in CoffeeScript.
Install
npm install github_auth
Initialize
GitHub = require 'github_auth'
github = new GitHub app_id, app_secret
Generate OAuth Link
This is the link your users will click to go to github.com and authorize your app.
link = github.link()
Get the Token from GitHub
The GitHub API calls back your application with a code in the query. You need to just take the code parameter from the query and pass it to the login
function.
The API
github.login(code, callback)
callback
provides token
as the parameter.
Express Example
app.get '/login', (req, res, next) ->
if req.query && req.query.code
github.login req.query.code, (token) ->
console.log token
# Now you have the token.
# Save it in your database.
else next()
License
MIT
Copyright © 2012 Arjun Bajaj
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.