Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revoke provider access #1843

Merged
merged 4 commits into from
Sep 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/@uppy/companion-client/src/Provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ module.exports = class Provider extends RequestClient {
return this.get(`${this.id}/list/${directory || ''}`)
}

logout (redirect = location.href) {
logout () {
return new Promise((resolve, reject) => {
this.get(`${this.id}/logout?redirect=${redirect}`)
this.get(`${this.id}/logout`)
.then((res) => {
this.uppy.getPlugin(this.pluginId).storage.removeItem(this.tokenKey)
.then(() => resolve(res))
Expand Down
32 changes: 21 additions & 11 deletions packages/@uppy/companion/src/server/controllers/logout.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,30 @@ const tokenService = require('../helpers/jwt')
* @param {object} req
* @param {object} res
*/
function logout (req, res) {
const session = req.session
const providerName = req.params.providerName

if (req.uppy.providerTokens && req.uppy.providerTokens[providerName]) {
delete req.uppy.providerTokens[providerName]
tokenService.removeFromCookies(res, req.uppy.options, req.uppy.provider.authProviderName)
function logout (req, res, next) {
const cleanSession = () => {
if (req.session.grant) {
req.session.grant.state = null
req.session.grant.dynamic = null
}
}
const providerName = req.params.providerName
const token = req.uppy.providerTokens ? req.uppy.providerTokens[providerName] : null
if (token) {
req.uppy.provider.logout({ token }, (err, data) => {
if (err) {
return next(err)
}

if (session.grant) {
session.grant.state = null
session.grant.dynamic = null
delete req.uppy.providerTokens[providerName]
tokenService.removeFromCookies(res, req.uppy.options, req.uppy.provider.authProviderName)
cleanSession()
res.json(Object.assign({ ok: true }, data))
})
} else {
cleanSession()
res.json({ ok: true, revoked: false })
}
res.json({ ok: true })
}

module.exports = logout
14 changes: 14 additions & 0 deletions packages/@uppy/companion/src/server/provider/drive/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,20 @@ class Drive {
})
}

logout ({ token }, done) {
return this.client
.get('https://accounts.google.com/o/oauth2/revoke')
.qs({ token })
.request((err, resp) => {
if (err || resp.statusCode !== 200) {
logger.error(err, 'provider.drive.logout.error')
done(this._error(err, resp))
return
}
done(null, { revoked: true })
})
}

adaptData (res, sharedDrivesResp, uppy, directory, query) {
const adaptItem = (item) => ({
isFolder: adapter.isFolder(item),
Expand Down
15 changes: 15 additions & 0 deletions packages/@uppy/companion/src/server/provider/dropbox/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,21 @@ class DropBox {
})
}

logout ({ token }, done) {
return this.client
.post('auth/token/revoke')
.options({ version: '2' })
.auth(token)
.request((err, resp) => {
if (err || resp.statusCode !== 200) {
logger.error(err, 'provider.dropbox.size.error')
done(this._error(err, resp))
return
}
done(null, { revoked: true })
})
}

adaptData (res, uppy) {
const data = { username: adapter.getUsername(res), items: [] }
const items = adapter.getItemSubList(res)
Expand Down
14 changes: 14 additions & 0 deletions packages/@uppy/companion/src/server/provider/facebook/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,20 @@ class Facebook {
})
}

logout ({ token }, done) {
return this.client
.delete('me/permissions')
.auth(token)
.request((err, resp) => {
if (err || resp.statusCode !== 200) {
logger.error(err, 'provider.facebook.logout.error')
done(this._error(err, resp))
return
}
done(null, { revoked: true })
})
}

adaptData (res, username, directory, currentQuery) {
const data = { username: username, items: [] }
const items = adapter.getItemSubList(res)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ class Instagram {
})
}

logout (_, done) {
// access revoke is not supported by Instagram's API
done(null, { revoked: false, manual_revoke_url: 'https://www.instagram.com/accounts/manage_access/' })
}

adaptData (res, username) {
const data = { username: username, items: [] }
const items = adapter.getItemSubList(res)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ class OneDrive {
})
}

logout (_, done) {
// access revoke is not supported by Microsoft/OneDrive's API
done(null, { revoked: false, manual_revoke_url: 'https://account.live.com/consent/Manage' })
}

adaptData (res, username) {
const data = { username, items: [] }
const items = adapter.getItemSubList(res)
Expand Down
1 change: 1 addition & 0 deletions packages/@uppy/core/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class Uppy {
youCanOnlyUploadFileTypes: 'You can only upload: %{types}',
companionError: 'Connection with Companion failed',
companionAuthError: 'Authorization required',
companionUnauthorizeHint: 'To unauthorize to your %{provider} account, please go to %{url}',
Copy link
Contributor

@goto-bus-stop goto-bus-stop Sep 23, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The link is not clickable and users won't be able to copy it before the bubble disappears, so I'm not sure if this is super useful. Maybe we could make it say something like "You can now remove the authorization in %{provider}'s settings panel"? Would be nice to actually link to the page but that would require some changes in the info bubbles...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could make the link clickable (by setting content of the informer with __dangerouslySetInnerHTML) and set the bubble to hold for 10 seconds? Until we add support for alert modals with “ok” (or we could use actual alert? I think it would be too intrusive and ugly in this case).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my thought is that the URL being displayed now at least helps users find the URL where to revoke this access. Otherwise, some of these settings can be hard to find. Is there someway to make informer stay longer maybe?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3rd argument to uppy.info() is duration in milliseconds

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you! I have extended the duration of the message to last for 7 seconds, and it seemed long enough for me to highlight and copy the message.

failedToUpload: 'Failed to upload %{file}',
noInternetConnection: 'No Internet connection',
connectedToInternet: 'Connected to the Internet',
Expand Down
10 changes: 9 additions & 1 deletion packages/@uppy/provider-views/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,17 @@ module.exports = class ProviderView {
* Removes session token on client side.
*/
logout () {
this.provider.logout(location.href)
this.provider.logout()
.then((res) => {
if (res.ok) {
if (!res.revoked) {
const message = this.plugin.uppy.i18n('companionUnauthorizeHint', {
provider: this.plugin.title,
url: res.manual_revoke_url
})
this.plugin.uppy.info(message, 'info', 7000)
}

const newState = {
authenticated: false,
files: [],
Expand Down