function debugOverPush(before, after) { if (functions.config().app.debug === "1") { if (before !== null && after !== null) { const minutes = (after.at - before.at) / 60000.0; common.sendPush("State is changed " + before.state + " to " + after.state, "min(s): " + minutes); } } }
router.get('/authorization_url', (req, res) => { // return 'url' for user to authorize. this can be used in a button or elsewhere. let client = new medium.MediumClient({ clientId: functions.config().medium.client_id, clientSecret: functions.config().medium.client_secret }) const state = crypto.randomBytes(20).toString('hex'); let url = client.getAuthorizationUrl(state, functions.config().medium.redirect_uri, [ medium.Scope.BASIC_PROFILE, medium.Scope.PUBLISH_POST, medium.Scope.LIST_PUBLICATIONS ]); // optional usage here to send user immediately to the oAuth endpoint. if(req.query.redirect) { return res.redirect(url); } res.json({url: url}); })
router.post('/authorize_token', (req, res) => { // authorize 'code' param submitted from user if (req.method !== 'POST') { res.status(403).json({error: 'Forbidden!'}); } if(!req.body.code) { return res.status(404).json({error: 'Missing code parameter'}); } let client = new medium.MediumClient({ clientId: functions.config().medium.client_id, clientSecret: functions.config().medium.client_secret }) client.exchangeAuthorizationCode(req.body.code, functions.config().medium.redirect_uri, (err, tokenData) => { if(err) { return res.status(500).json({error: err}); } client.getUser((err, user) => { if(err) { return res.status(500).json({error: err}); } // The organization admin (or user with credentials) can now submit this information to be used. // If we can figure out how to set data on behalf of a user utilizing firebase's database rules that // would be a more secure way to handle this. res.json({user: user, tokenData: tokenData}); }); }) });
const bucket = gcs.bucket(functions.config().firebase.storageBucket); const destLocation = `/imager/${config.organization}/${destFileName}`;
functions.https.onRequest((req, res) => { console.log(functions.config().firebase); cors(req, res, () => { if(req.method !== 'GET') {