UNPKG

@uppy/companion

Version:

OAuth helper and remote fetcher for Uppy's (https://uppy.io) extensible file upload widget with support for drag&drop, resumable uploads, previews, restrictions, file processing/encoding, remote providers like Dropbox and Google Drive, S3 and more :dog:

39 lines (38 loc) 1.25 kB
"use strict"; const got = require('../../got'); const { withGoogleErrorHandling } = require('../providerErrors'); /** * Reusable google stuff */ const getOauthClient = async () => (await got).extend({ prefixUrl: 'https://oauth2.googleapis.com', }); async function refreshToken({ clientId, clientSecret, refreshToken: theRefreshToken, }) { return withGoogleErrorHandling('google', 'provider.google.token.refresh.error', async () => { const { access_token: accessToken } = await (await getOauthClient()) .post('token', { responseType: 'json', form: { refresh_token: theRefreshToken, grant_type: 'refresh_token', client_id: clientId, client_secret: clientSecret, }, }) .json(); return { accessToken }; }); } async function logout({ token }) { return withGoogleErrorHandling('google', 'provider.google.logout.error', async () => { await (await got).post('https://accounts.google.com/o/oauth2/revoke', { searchParams: { token }, responseType: 'json', }); return { revoked: true }; }); } module.exports = { refreshToken, logout, };