Socket
Socket
Sign inDemoInstall

express-oauth2-helper

Package Overview
Dependencies
7
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    express-oauth2-helper

express oauth2 helper


Version published
Weekly downloads
4
Maintainers
1
Created
Weekly downloads
 

Readme

Source

express-oauth2

express oauth2 helper

path

this helper return a router that registers some paths:

  • /: The auth url, which will redirect the client to the oauth service to login.
  • /redirect: must the same with the redirect url that you set in the oauth service.
  • /refresh: request a new token if it's expired.

usage

example: access http://localhost:9900/discord on your browser the redirect url should be http://localhost:9900/discord/redirect

require('dotenv').config()
const fetch = require('node-fetch')

const express = require('express')
const app = express()
const port = 9900

const discord = require('.')({
    client_id: process.env.DISCORD_CLIENT_ID,
    client_secret: process.env.DISCORD_CLIENT_SECRET,
    scope: process.env.DISCORD_SCOPE,
    url_auth: process.env.DISCORD_URL_AUTH,
    url_token: process.env.DISCORD_URL_TOKEN,
    url_redirect: process.env.DISCORD_URL_REDIRECT,
    hook,
})

app.use('/discord', discord)

app.use((err, req, res, next) => {
    console.error('ERR:', err)
    res.status(err.status || 500).end()
})

app.listen(port, () => {
    console.log(`OAUTH example listening at localhost:${port}/discord`)
})

async function hook(token) {
    const res = await fetch('http://httpbin.org/post', {
        method: 'POST',
        body: JSON.stringify(token),
        headers: {
            'content-type': 'application/json',
        },
    })
    const data = await res.json()
    console.log(res.status)
    console.log(data)
}

FAQs

Last updated on 22 Apr 2021

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc