diff options
author | vnugent <public@vaughnnugent.com> | 2024-01-04 11:13:31 -0500 |
---|---|---|
committer | vnugent <public@vaughnnugent.com> | 2024-01-04 11:13:31 -0500 |
commit | e87c4b69036e32b4fcf3df89e8158fb52df6a4e0 (patch) | |
tree | 83ce96172100abb0949f60e3c733daf738cbcf2d /extension/src/entries/store | |
parent | 8dec218a1aa259f83b8178265a7d0d0f08817cac (diff) |
package updates & partial account page added
Diffstat (limited to 'extension/src/entries/store')
-rw-r--r-- | extension/src/entries/store/features.ts | 25 | ||||
-rw-r--r-- | extension/src/entries/store/identity.ts | 18 | ||||
-rw-r--r-- | extension/src/entries/store/index.ts | 9 | ||||
-rw-r--r-- | extension/src/entries/store/mfaconfig.ts | 67 |
4 files changed, 109 insertions, 10 deletions
diff --git a/extension/src/entries/store/features.ts b/extension/src/entries/store/features.ts index c619b0e..9f9a4db 100644 --- a/extension/src/entries/store/features.ts +++ b/extension/src/entries/store/features.ts @@ -1,7 +1,22 @@ +// Copyright (C) 2023 Vaughn Nugent +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see <https://www.gnu.org/licenses/>. import 'pinia' import { } from 'lodash' import { PiniaPluginContext } from 'pinia' +import type { IMfaFlowContinuiation } from '@vnuge/vnlib.browser' import { useAuthApi, @@ -14,7 +29,8 @@ import { useForegoundFeatures, useEventTagFilterApi, useInjectAllowList, - onWatchableChange + onWatchableChange, + useMfaConfigApi } from "../../features" import { ChannelContext } from '../../messaging' @@ -25,6 +41,7 @@ export type BgPluginState<T> = { plugins: BgPlugins } & T declare module 'pinia' { export interface PiniaCustomProperties { plugins: BgPlugins + mfaStatus: Partial<IMfaFlowContinuiation> | null } } @@ -41,7 +58,8 @@ const usePlugins = (context: ChannelContext) => { localPki: use(useLocalPki), pki: use(usePkiApi), tagFilter: use(useEventTagFilterApi), - allowedOrigins: use(useInjectAllowList) + allowedOrigins: use(useInjectAllowList), + mfaConfig: use(useMfaConfigApi) } } @@ -56,9 +74,10 @@ export const useBackgroundPiniaPlugin = (context: ChannelContext) => { //watch for status changes onWatchableChange(user, async () => { //Get status update and set the values - const { loggedIn, userName } = await user.getStatus(); + const { loggedIn, userName, mfaStatus } = await user.getStatus(); store.loggedIn = loggedIn; store.userName = userName; + store.mfaStatus = mfaStatus }, { immediate: true }) diff --git a/extension/src/entries/store/identity.ts b/extension/src/entries/store/identity.ts index ef1941e..5bbc67a 100644 --- a/extension/src/entries/store/identity.ts +++ b/extension/src/entries/store/identity.ts @@ -1,3 +1,17 @@ +// Copyright (C) 2023 Vaughn Nugent +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see <https://www.gnu.org/licenses/>. import 'pinia' import { } from 'lodash' @@ -13,6 +27,7 @@ declare module 'pinia' { createIdentity(id: Partial<NostrPubKey>): Promise<NostrPubKey>; updateIdentity(id: NostrPubKey): Promise<NostrPubKey>; selectKey(key: NostrPubKey): Promise<void>; + refreshIdentities(): Promise<void>; } } @@ -40,6 +55,7 @@ export const identityPlugin = ({ store }: PiniaPluginContext) => { selectKey: identity.selectKey, deleteIdentity: identity.deleteIdentity, createIdentity: identity.createIdentity, - updateIdentity: identity.updateIdentity + updateIdentity: identity.updateIdentity, + refreshIdentities: identity.refreshKeys } }
\ No newline at end of file diff --git a/extension/src/entries/store/index.ts b/extension/src/entries/store/index.ts index 07fce6d..e3eef2f 100644 --- a/extension/src/entries/store/index.ts +++ b/extension/src/entries/store/index.ts @@ -23,6 +23,7 @@ export type * from './types' export * from './allowedOrigins' export * from './features' export * from './identity' +export * from './mfaconfig' export const useStore = defineStore({ id: 'main', @@ -34,8 +35,8 @@ export const useStore = defineStore({ }), actions: { - async login (token: string) { - await this.plugins.user.login(token); + async login (usernameOrToken: string, password?: string) { + await this.plugins.user.login(usernameOrToken, password); }, async logout () { @@ -49,10 +50,6 @@ export const useStore = defineStore({ async toggleDarkMode(){ await this.plugins.settings.setDarkMode(this.darkMode === false) }, - - checkIsCurrentOriginAllowed() { - - } }, getters:{ diff --git a/extension/src/entries/store/mfaconfig.ts b/extension/src/entries/store/mfaconfig.ts new file mode 100644 index 0000000..6a5116d --- /dev/null +++ b/extension/src/entries/store/mfaconfig.ts @@ -0,0 +1,67 @@ +// Copyright (C) 2023 Vaughn Nugent +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see <https://www.gnu.org/licenses/>. + +import 'pinia' +import { } from 'lodash' +import { PiniaPluginContext } from 'pinia' +import { shallowRef } from 'vue'; +import { MfaUpdateResult, PkiPubKey, onWatchableChange } from '../../features'; +import { MfaMethod } from '@vnuge/vnlib.browser'; + +declare module 'pinia' { + export interface PiniaCustomProperties { + readonly mfaEnabledMethods: Array<MfaMethod>; + readonly pkiServerKeys: Array<PkiPubKey>; + mfaUpsertMethod(method: MfaMethod, password: string): Promise<MfaUpdateResult>; + mfaDisableMethod(method: MfaMethod, password: string): Promise<void>; + mfaRefresh(): void; + pkiAddKey(key: PkiPubKey): Promise<void>; + pkiRemoveKey(key: PkiPubKey): Promise<void>; + } +} + +export const mfaConfigPlugin = ({ store }: PiniaPluginContext) => { + + const mfaEnabledMethods = shallowRef<MfaMethod[]>() + const pkiServerKeys = shallowRef<PkiPubKey[]>() + const { mfaConfig, pki } = store.plugins + + onWatchableChange(mfaConfig, async () => { + //store enabled methods + mfaEnabledMethods.value = await mfaConfig.getMfaMethods() + }, { immediate: true }) + + onWatchableChange(pki, async () => { + //store pki keys + pkiServerKeys.value = await pki.getAllKeys() + }, { immediate: true }) + + return { + mfaEnabledMethods, + pkiServerKeys, + mfaUpsertMethod: (method: MfaMethod, password: string) => { + return mfaConfig.enableOrUpdate(method, password) + }, + mfaDisableMethod: async (method: MfaMethod, password: string) => { + await mfaConfig.disableMethod(method, password) + }, + mfaRefresh: () => { + mfaConfig.refresh() + pki.refresh() + }, + pkiAddKey: pki.addOrUpdate, + pkiRemoveKey: pki.removeKey + } +} |