improve authorization

This commit is contained in:
SrGooglo 2024-04-21 22:24:47 +02:00
parent 64303dac7e
commit aa1f2f0913
9 changed files with 63 additions and 17 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@ragestudio/relic-core", "name": "@ragestudio/relic-core",
"version": "0.17.4", "version": "0.17.5",
"license": "MIT", "license": "MIT",
"author": "RageStudio", "author": "RageStudio",
"description": "RageStudio Relic, yet another package manager.", "description": "RageStudio Relic, yet another package manager.",

View File

@ -33,4 +33,12 @@ export default class ManifestAuthService {
return await db.data[pkg_id] return await db.data[pkg_id]
} }
static delete = async (pkg_id) => {
const db = await this.withDB()
return await db.update((data) => {
delete data[pkg_id]
})
}
} }

View File

@ -0,0 +1,28 @@
import ManifestAuthDB from "../classes/ManifestAuthDB"
import DB from "../db"
import Logger from "../logger"
const Log = Logger.child({ service: "AUTH" })
export default async (pkg_id) => {
if (!pkg_id) {
Log.error("pkg_id is required")
return false
}
const pkg = await DB.getPackages(pkg_id)
if (!pkg) {
Log.error("Package not found")
return false
}
Log.info(`Deleting auth for [${pkg_id}]`)
await ManifestAuthDB.delete(pkg_id)
global._relic_eventBus.emit("pkg:deauthorized", pkg)
return true
}

View File

@ -43,6 +43,8 @@ export default async function execute(pkg_id, { useRemote = false, force = false
return false return false
} }
BaseLog.info(`Executing manifest > [${manifestPath}]`)
global._relic_eventBus.emit(`pkg:update:state`, { global._relic_eventBus.emit(`pkg:update:state`, {
id: pkg.id, id: pkg.id,
last_status: "loading", last_status: "loading",

View File

@ -17,6 +17,7 @@ import PackageApply from "./handlers/apply"
import PackageList from "./handlers/list" import PackageList from "./handlers/list"
import PackageRead from "./handlers/read" import PackageRead from "./handlers/read"
import PackageAuthorize from "./handlers/authorize" import PackageAuthorize from "./handlers/authorize"
import PackageDeauthorize from "./handlers/deauthorize"
import PackageCheckUpdate from "./handlers/checkUpdate" import PackageCheckUpdate from "./handlers/checkUpdate"
import PackageLastOperationRetry from "./handlers/lastOperationRetry" import PackageLastOperationRetry from "./handlers/lastOperationRetry"
@ -56,6 +57,7 @@ export default class RelicCore {
list: PackageList, list: PackageList,
read: PackageRead, read: PackageRead,
authorize: PackageAuthorize, authorize: PackageAuthorize,
deauthorize: PackageDeauthorize,
checkUpdate: PackageCheckUpdate, checkUpdate: PackageCheckUpdate,
lastOperationRetry: PackageLastOperationRetry, lastOperationRetry: PackageLastOperationRetry,
} }

View File

@ -16,13 +16,11 @@ export default class Auth {
} }
const result = await axios({ const result = await axios({
method: "POST", method: "GET",
url: this.manifest.authService.getter, url: this.manifest.authService.getter,
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
}, "Authorization": `Bearer ${storagedData}`
data: {
auth_data: storagedData,
} }
}).catch((err) => { }).catch((err) => {
global._relic_eventBus.emit("auth:getter:error", err) global._relic_eventBus.emit("auth:getter:error", err)

View File

@ -1,6 +1,6 @@
{ {
"name": "@ragestudio/relic-gui", "name": "@ragestudio/relic-gui",
"version": "0.17.4", "version": "0.17.5",
"description": "RageStudio Relic, yet another package manager.", "description": "RageStudio Relic, yet another package manager.",
"main": "./out/main/index.js", "main": "./out/main/index.js",
"author": "RageStudio", "author": "RageStudio",
@ -24,7 +24,7 @@
"@getstation/electron-google-oauth2": "^14.0.0", "@getstation/electron-google-oauth2": "^14.0.0",
"@imjs/electron-differential-updater": "^5.1.7", "@imjs/electron-differential-updater": "^5.1.7",
"@loadable/component": "^5.16.3", "@loadable/component": "^5.16.3",
"@ragestudio/relic-core": "^0.17.0", "@ragestudio/relic-core": "^0.17.5",
"antd": "^5.13.2", "antd": "^5.13.2",
"classnames": "^2.3.2", "classnames": "^2.3.2",
"electron-differential-updater": "^4.3.2", "electron-differential-updater": "^4.3.2",

View File

@ -65,6 +65,9 @@ export default class CoreAdapter {
"pkg:cancel_current_operation": async (event, pkg_id) => { "pkg:cancel_current_operation": async (event, pkg_id) => {
return await this.core.package.cancelCurrentOperation(pkg_id) return await this.core.package.cancelCurrentOperation(pkg_id)
}, },
"pkg:delete_auth": async (event, pkg_id) => {
return await this.core.package.deauthorize(pkg_id)
},
"core:open-path": async (event, pkg_id) => { "core:open-path": async (event, pkg_id) => {
return await this.core.openPath(pkg_id) return await this.core.openPath(pkg_id)
}, },
@ -109,6 +112,13 @@ export default class CoreAdapter {
description: `${pkg.name} has been authorized! You can start the package now.`, description: `${pkg.name} has been authorized! You can start the package now.`,
}) })
}, },
"pkg:deauthorized": (pkg) => {
sendToRender(`new:notification`, {
type: "success",
message: "Package deauthorized",
description: `${pkg.name} has been deauthorized`,
})
},
"pkg:error": (data) => { "pkg:error": (data) => {
sendToRender(`new:notification`, { sendToRender(`new:notification`, {
type: "error", type: "error",

View File

@ -237,16 +237,14 @@ const PackageOptions = (props) => {
</div> </div>
<div className="package_options-actions"> <div className="package_options-actions">
{ <antd.Button
manifest.auth && <antd.Button onClick={handleDeleteAuth}
onClick={handleDeleteAuth} type="default"
type="default" size="small"
size="small" disabled={loading}
disabled={loading} >
> Delete auth
Delete auth </antd.Button>
</antd.Button>
}
<antd.Button <antd.Button
onClick={handleReinstall} onClick={handleReinstall}