Client - revoke all token for a given client

This commit is contained in:
Sam 2022-06-12 18:03:26 +02:00
parent e01248d0d1
commit 524a221725
9 changed files with 94 additions and 9 deletions

View File

@ -3,13 +3,22 @@
<Modal
v-if="displayModal"
:title="$t('common.CONFIRMATION')"
:message="$t('oauth2.APP_DELETION_CONFIRMATION')"
@confirmAction="deleteClient(client.id)"
:message="$t(messageToDisplay)"
@confirmAction="confirmAction(client.id)"
@cancelAction="updateDisplayModal(false)"
/>
<div v-if="client && client.client_id">
<div class="info-box success-message" v-if="afterCreation">
{{ $t('oauth2.APP_CREATED_SUCCESSFULLY') }}
<div
class="info-box success-message"
v-if="afterCreation || revocationSuccessful"
>
{{
$t(
afterCreation
? 'oauth2.APP_CREATED_SUCCESSFULLY'
: 'oauth2.TOKENS_REVOKED'
)
}}
</div>
<dl>
<dt>{{ $t('oauth2.APP.CLIENT_ID') }}:</dt>
@ -55,7 +64,10 @@
</dd>
</dl>
<div class="app-buttons">
<button class="danger" @click="updateDisplayModal(true)">
<button class="danger" @click="updateMessageToDisplay(false)">
{{ $t('oauth2.REVOKE_ALL_TOKENS') }}
</button>
<button class="danger" @click="updateMessageToDisplay(true)">
{{ $t('oauth2.DELETE_APP') }}
</button>
<button @click="$router.push('/profile/apps')">
@ -84,6 +96,7 @@
ref,
onUnmounted,
withDefaults,
watch,
} from 'vue'
import { useRoute } from 'vue-router'
@ -107,7 +120,11 @@
const client: ComputedRef<IOAuth2Client> = computed(
() => store.getters[OAUTH2_STORE.GETTERS.CLIENT]
)
const revocationSuccessful: ComputedRef<boolean> = computed(
() => store.getters[OAUTH2_STORE.GETTERS.REVOCATION_SUCCESSFUL]
)
let displayModal: Ref<boolean> = ref(false)
let messageToDisplay: Ref<string | null> = ref(null)
onBeforeMount(() => {
loadClient()
@ -123,16 +140,39 @@
store.dispatch(OAUTH2_STORE.ACTIONS.GET_CLIENT_BY_ID, +route.params.id)
}
}
function deleteClient(clientId: number) {
store.dispatch(OAUTH2_STORE.ACTIONS.DELETE_CLIENT, clientId)
function updateMessageToDisplay(forDelete: boolean) {
messageToDisplay.value = forDelete
? 'oauth2.APP_DELETION_CONFIRMATION'
: 'oauth2.TOKENS_REVOCATION_CONFIRMATION'
updateDisplayModal(true)
}
function updateDisplayModal(value: boolean) {
displayModal.value = value
if (!value) {
messageToDisplay.value = null
}
}
function confirmAction(clientId: number) {
if (messageToDisplay.value === 'oauth2.APP_DELETION_CONFIRMATION') {
store.dispatch(OAUTH2_STORE.ACTIONS.DELETE_CLIENT, clientId)
} else {
store.dispatch(OAUTH2_STORE.ACTIONS.REVOKE_ALL_TOKENS, clientId)
}
}
onUnmounted(() => {
store.commit(ROOT_STORE.MUTATIONS.EMPTY_ERROR_MESSAGES)
store.commit(OAUTH2_STORE.MUTATIONS.EMPTY_CLIENT)
store.commit(OAUTH2_STORE.MUTATIONS.SET_REVOCATION_SUCCESSFUL, false)
})
watch(
() => revocationSuccessful.value,
(newValue) => {
if (newValue) {
updateDisplayModal(false)
}
}
)
</script>
<style scoped lang="scss">

View File

@ -23,5 +23,8 @@
"NEW_APP": "New OAuth App",
"NO_DESCRIPTION": "no description",
"NO_APP": "Application not found!",
"NO_APPS": "no applications"
"NO_APPS": "no applications",
"REVOKE_ALL_TOKENS": "Revoke all tokens",
"TOKENS_REVOCATION_CONFIRMATION": "Are you sure you want to revoke all tokens?",
"TOKENS_REVOKED": "All existing associated tokens have been revoked."
}

View File

@ -23,5 +23,8 @@
"NEW_APP": "Ajouter une App OAuth",
"NO_DESCRIPTION": "pas de description",
"NO_APP": "Application introuvable !",
"NO_APPS": "pas de applications"
"NO_APPS": "pas de applications",
"REVOKE_ALL_TOKENS": "Révoquer tous les jetons",
"TOKENS_REVOCATION_CONFIRMATION": "Êtes-vous sûr de vouloir révoquer tous les jetons ?",
"TOKENS_REVOKED": "Tous les jetons associés existants ont été révoqués."
}

View File

@ -134,4 +134,21 @@ export const actions: ActionTree<IOAuth2State, IRootState> & IOAuth2Actions = {
})
.catch((error) => handleError(context, error))
},
[OAUTH2_STORE.ACTIONS.REVOKE_ALL_TOKENS](
context: ActionContext<IOAuth2State, IRootState>,
id: number
): void {
context.commit(ROOT_STORE.MUTATIONS.EMPTY_ERROR_MESSAGES)
context.commit(OAUTH2_STORE.MUTATIONS.SET_REVOCATION_SUCCESSFUL, false)
authApi
.post(`oauth/apps/${id}/revoke`)
.then((res) => {
if (res.data.status === 'success') {
context.commit(OAUTH2_STORE.MUTATIONS.SET_REVOCATION_SUCCESSFUL, true)
} else {
handleError(context, null)
}
})
.catch((error) => handleError(context, error))
},
}

View File

@ -5,12 +5,14 @@ export enum OAuth2Actions {
GET_CLIENTS = 'GET_CLIENTS',
GET_CLIENT_BY_CLIENT_ID = 'GET_CLIENT_BY_CLIENT_ID',
GET_CLIENT_BY_ID = 'GET_CLIENT_BY_ID',
REVOKE_ALL_TOKENS = 'REVOKE_ALL_TOKENS',
}
export enum OAuth2Getters {
CLIENT = 'CLIENT',
CLIENTS = 'CLIENTS',
CLIENTS_PAGINATION = 'CLIENTS_PAGINATION',
REVOCATION_SUCCESSFUL = 'REVOCATION_SUCCESSFUL',
}
export enum OAuth2Mutations {
@ -18,4 +20,5 @@ export enum OAuth2Mutations {
SET_CLIENT = 'SET_CLIENT',
SET_CLIENTS = 'SET_CLIENTS',
SET_CLIENTS_PAGINATION = 'SET_CLIENTS_PAGINATION',
SET_REVOCATION_SUCCESSFUL = 'SET_REVOCATION_SUCCESSFUL',
}

View File

@ -9,4 +9,6 @@ export const getters: GetterTree<IOAuth2State, IRootState> & IOAuth2Getters = {
[OAUTH2_STORE.GETTERS.CLIENTS]: (state: IOAuth2State) => state.clients,
[OAUTH2_STORE.GETTERS.CLIENTS_PAGINATION]: (state: IOAuth2State) =>
state.pagination,
[OAUTH2_STORE.GETTERS.REVOCATION_SUCCESSFUL]: (state: IOAuth2State) =>
state.revocationSuccessful,
}

View File

@ -27,4 +27,10 @@ export const mutations: MutationTree<IOAuth2State> & TOAuth2Mutations = {
) {
state.pagination = pagination
},
[OAUTH2_STORE.MUTATIONS.SET_REVOCATION_SUCCESSFUL](
state: IOAuth2State,
revocationSuccessful: boolean
) {
state.revocationSuccessful = revocationSuccessful
},
}

View File

@ -6,4 +6,5 @@ export const oAuth2State: IOAuth2State = {
client: <IOAuth2Client>{},
clients: [],
pagination: <IPagination>{},
revocationSuccessful: false,
}

View File

@ -19,6 +19,7 @@ export interface IOAuth2State {
client: IOAuth2Client
clients: IOAuth2Client[]
pagination: IPagination
revocationSuccessful: boolean
}
export interface IOAuth2Actions {
@ -46,12 +47,17 @@ export interface IOAuth2Actions {
context: ActionContext<IOAuth2State, IRootState>,
payload: IOauth2ClientsPayload
): void
[OAUTH2_STORE.ACTIONS.REVOKE_ALL_TOKENS](
context: ActionContext<IOAuth2State, IRootState>,
id: number
): void
}
export interface IOAuth2Getters {
[OAUTH2_STORE.GETTERS.CLIENT](state: IOAuth2State): IOAuth2Client
[OAUTH2_STORE.GETTERS.CLIENTS](state: IOAuth2State): IOAuth2Client[]
[OAUTH2_STORE.GETTERS.CLIENTS_PAGINATION](state: IOAuth2State): IPagination
[OAUTH2_STORE.GETTERS.REVOCATION_SUCCESSFUL](state: IOAuth2State): boolean
}
export type TOAuth2Mutations<S = IOAuth2State> = {
@ -62,6 +68,10 @@ export type TOAuth2Mutations<S = IOAuth2State> = {
state: S,
pagination: IPagination
): void
[OAUTH2_STORE.MUTATIONS.SET_REVOCATION_SUCCESSFUL](
state: S,
revocationSuccessful: boolean
): void
}
export type TOAuth2StoreModule<S = IOAuth2State> = Omit<