diff --git a/app/soapbox/actions/auth.js b/app/soapbox/actions/auth.js index b6bcd888c..5c884dfd1 100644 --- a/app/soapbox/actions/auth.js +++ b/app/soapbox/actions/auth.js @@ -27,6 +27,10 @@ export const FETCH_TOKENS_REQUEST = 'FETCH_TOKENS_REQUEST'; export const FETCH_TOKENS_SUCCESS = 'FETCH_TOKENS_SUCCESS'; export const FETCH_TOKENS_FAIL = 'FETCH_TOKENS_FAIL'; +export const REVOKE_TOKEN_REQUEST = 'REVOKE_TOKEN_REQUEST'; +export const REVOKE_TOKEN_SUCCESS = 'REVOKE_TOKEN_SUCCESS'; +export const REVOKE_TOKEN_FAIL = 'REVOKE_TOKEN_FAIL'; + const noOp = () => () => new Promise(f => f()); function createAppAndToken() { @@ -204,6 +208,17 @@ export function fetchOAuthTokens() { }; } +export function revokeOAuthToken(id) { + return (dispatch, getState) => { + dispatch({ type: REVOKE_TOKEN_REQUEST, id }); + return api(getState).delete(`/api/oauth_tokens/${id}`).then(response => { + dispatch({ type: REVOKE_TOKEN_SUCCESS, id }); + }).catch(error => { + dispatch({ type: REVOKE_TOKEN_FAIL, id }); + }); + }; +} + export function authAppCreated(app) { return { type: AUTH_APP_CREATED, diff --git a/app/soapbox/features/security/index.js b/app/soapbox/features/security/index.js index 2dc378ff6..bfbd98946 100644 --- a/app/soapbox/features/security/index.js +++ b/app/soapbox/features/security/index.js @@ -15,6 +15,7 @@ import { changeEmail, changePassword, fetchOAuthTokens, + revokeOAuthToken, } from 'soapbox/actions/auth'; import { showAlert } from 'soapbox/actions/alerts'; @@ -210,6 +211,12 @@ class AuthTokenList extends ImmutablePureComponent { tokens: ImmutablePropTypes.list, } + handleRevoke = id => { + return e => { + this.props.dispatch(revokeOAuthToken(id)); + }; + } + componentDidMount() { this.props.dispatch(fetchOAuthTokens()); } @@ -221,9 +228,12 @@ class AuthTokenList extends ImmutablePureComponent { {this.props.tokens.map((token, i) => (