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

WEB-283 Logging out revokes your access_token through API #305

Merged
merged 2 commits into from
Jan 5, 2021
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ For detailed rules of this file, see [Changelog Rules](#changelog-rules)

### ⚡ Changed
* Further improve message displayed when email validation token is invalid.
* Logging out also removes your access token through the API, so your token cannot be used anywhere anymore. - [#305][]


### 🐛 Fixed
Expand All @@ -25,6 +26,7 @@ For detailed rules of this file, see [Changelog Rules](#changelog-rules)
* Perform some preparation steps for Webpack 5 and Yarn PnP.
* Upgrade to Yarn 2 (but not PnP, that comes later when the bugs are solved).

[#305]: https://github.com/fuelRats/fuelrats.com/pull/305
[#303]: https://github.com/fuelRats/fuelrats.com/pull/303
[#302]: https://github.com/fuelRats/fuelrats.com/pull/302
[Unreleased]: https://github.com/FuelRats/fuelrats.com/compare/v2.12.6...HEAD
Expand Down
6 changes: 6 additions & 0 deletions src/server/middlewares/proxy.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ const configureProxies = (koaServer, env) => {
target: env.api.url,
}))

koaServer.use(createProxyWithDefaults('/api/oauth2/revoke', {
auth: `${env.api.clientId}:${env.api.clientSecret}`,
rewrite: stripPathSegment('api'),
target: env.api.url,
}))

koaServer.use(createProxyWithDefaults('/api', {
rewrite: stripPathSegment('api'),
target: env.api.url,
Expand Down
1 change: 1 addition & 0 deletions src/store/actionTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ const oauth = {
authorize: {
read: 'oauth/authorize/read',
create: 'oauth/authorize/create',
delete: 'oauth/authorize/delete',
},
}

Expand Down
22 changes: 19 additions & 3 deletions src/store/actions/session.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { createFSA } from '@fuelrats/web-util/actions'
import { createFSA, createAxiosFSA } from '@fuelrats/web-util/actions'
import { HttpStatus } from '@fuelrats/web-util/http'
import { isError } from 'flux-standard-action'

import { configureRequest, deleteCookie } from '~/helpers/gIPTools'
import frApi from '~/services/fuelrats'

import actionTypes from '../actionTypes'
import {
selectSessionToken,
selectPageRequiresAuth,
selectSession,
selectUserById,
Expand All @@ -22,14 +24,28 @@ import { getUserProfile } from './user'
* @returns {Function} Redux action thunk
*/
export const logout = (ctx) => {
return (dispatch, getState) => {
return async (dispatch, getState) => {
deleteCookie('access_token', ctx)
const curState = getState()

const token = selectSessionToken(curState)

dispatch(createAxiosFSA(
actionTypes.oauth.authorize.delete,
await frApi.request({
url: '/oauth2/revoke',
method: 'post',
data: {
token,
},
}),
))

return dispatch(
createFSA(
actionTypes.session.logout,
{
waitForDestroy: Boolean(selectPageRequiresAuth(getState())),
waitForDestroy: Boolean(selectPageRequiresAuth(curState)),
},
),
)
Expand Down