
Security News
Deno 2.6 + Socket: Supply Chain Defense In Your CLI
Deno 2.6 introduces deno audit with a new --socket flag that plugs directly into Socket to bring supply chain security checks into the Deno CLI.
simple-oauth2-github
Advanced tools
This library is a wrapper around Simple OAuth2 Library
Specially made for Authorization Code Flow with GitHub.
Latest Node 8 LTS or newer versions.
npm install --save simple-oauth2 simple-oauth2-github
or
yarn add simple-oauth2 simple-oauth2-github
const simpleOAuth2Github = require('simple-oauth2-github');
const github = simpleOAuth2Github.create(options);
github object exposes 3 keys:
access_tokenSimpleOAuth2Github comes with default values for most of the options.
Required options
| Option | Description |
|---|---|
| clientId | Your App Id. |
| clientSecret | Your App Secret Id. |
| callbackURL | Callback configured when you created the app. |
Other options
| Option | Default | Description |
|---|---|---|
| scope | ['read:user', 'read:email'] | https://developer.github.com/apps/building-oauth-apps/understanding-scopes-for-oauth-apps |
| state | '' | Your CSRF anti-forgery token. More at: https://auth0.com/docs/protocols/oauth2/oauth-state |
| returnError | false | When is false (default), will call the next middleware with the error object. When is true, will set req.tokenError to the error, and call the next middleware as if there were no error. |
| authorizeHost | 'https://github.com' | |
| authorizePath | '/login/oauth/authorize' | |
| tokenHost | 'https://github.com' | |
| tokenPath | '/login/oauth/access_token' | |
| authorizeOptions | {} | Pass extra parameters when requesting authorization. |
| tokenOptions | {} | Pass extra parameters when requesting access_token. |
const oauth2 = require('simple-oauth2').create({
client: {
id: process.env.GITHUB_CLIENT_ID,
secret: process.env.GITHUB_CLIENT_SECRET
},
auth: {
authorizeHost: 'https://github.com',
authorizePath: '/login/oauth/authorize',
tokenHost: 'https://github.com',
tokenPath: '/login/oauth/access_token'
}
});
router.get('/auth/github', (req, res) => {
const authorizationUri = oauth2.authorizationCode.authorizeURL({
redirect_uri: 'http://localhost:3000/auth/github/callback',
scope: ['read:user', 'read:email']
});
res.redirect(authorizationUri);
});
router.get('/auth/github/callback', async(req, res) => {
const code = req.query.code;
const options = {
code,
redirect_uri: 'http://localhost:3000/auth/github/callback'
};
try {
// The resulting token.
const result = await oauth2.authorizationCode.getToken(options);
// Exchange for the access token.
const token = oauth2.accessToken.create(result);
return res.status(200).json(token);
} catch (error) {
console.error('Access Token Error', error.message);
return res.status(500).json('Authentication failed');
}
});
const simpleOAuth2Github = require('simple-oauth2-github');
const github = simpleOAuth2Github.create({
clientId: process.env.GITHUB_CLIENT_ID,
clientSecret: process.env.GITHUB_CLIENT_SECRET,
callbackURL: 'http://localhost:3000/auth/github/callback'
});
// Ask the user to authorize.
router.get('/auth/github', github.authorize);
// Exchange the token for the access token.
router.get('/auth/github/callback', github.accessToken, (req, res) => {
return res.status(200).json(req.token);
});
FAQs
A simple Node.js client library for GitHub OAuth2.
The npm package simple-oauth2-github receives a total of 0 weekly downloads. As such, simple-oauth2-github popularity was classified as not popular.
We found that simple-oauth2-github demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Deno 2.6 introduces deno audit with a new --socket flag that plugs directly into Socket to bring supply chain security checks into the Deno CLI.

Security News
New DoS and source code exposure bugs in React Server Components and Next.js: what’s affected and how to update safely.

Security News
Socket CEO Feross Aboukhadijeh joins Software Engineering Daily to discuss modern software supply chain attacks and rising AI-driven security risks.