How to use the oauth/lib/oauth2.OAuth2 function in oauth

To help you get started, we’ve selected a few oauth examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github elementary / houston / src / houston / passport / stripe.js View on Github external
import moment from 'moment'
import Router from 'koa-router'

import * as policy from 'houston/policy'
import * as stripe from 'service/stripe'
import config from 'lib/config'
import Log from 'lib/log'
import Mistake from 'lib/mistake'
import Project from 'lib/database/project'

const log = new Log('passport:stripe')

const url = 'https://connect.stripe.com/'
const urlAuth = 'oauth/authorize'
const urlToken = 'oauth/token'
const auth = new OAuth2(config.stripe.client, config.stripe.secret, url, urlAuth, urlToken, null)

// Some countries are in Stripe preview do not allow USD currency.
// @see https://stripe.com/global
const PREVIEW_COUNTRIES = ['MX', 'IN']

// Koa server routes used for authentication
export const router = new Router({
  prefix: '/stripe'
})

// NOTE: here be dragons. Really big mockup like dragons that breath fire.
router.get('/callback', policy.isRole('USER'), async (ctx, next) => {
  if (config.stripe == null) {
    log.debug('Stripe callback called while configuration disabled')
    return new ctx.Mistake(503, 'Stripe disabled')
  }