UNPKG

waigo

Version:

Node.js ES6 framework for reactive, data-driven apps and APIs (Koa, RethinkDB)

39 lines (24 loc) 766 B
"use strict"; const waigo = global.waigo, _ = waigo._, OauthError = waigo.load('support/oauth/error'), GenericOauth = waigo.load('support/oauth/providers/generic'); exports.load = function*(ctx, provider, tokens) { if (!provider) { throw new OauthError('No OAuth provider given', 404); } // see if we have an access token for this provider for current user if (!tokens) { let user = ctx.currentUser; if (user) { tokens = yield user.getOauth(provider); } } let Impl = GenericOauth; try { Impl = waigo.load(`support/oauth/providers/${provider}`); } catch (err) { ctx.logger.warn(`No OAuth implementation found for "${provider}", using generic.`, err); } return new Impl(ctx, provider, tokens); }