Skip to content

Commit

Permalink
Copy api key #217
Browse files Browse the repository at this point in the history
  • Loading branch information
Levminer committed Jul 10, 2022
1 parent d19552e commit 9e2ec88
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 8 deletions.
10 changes: 8 additions & 2 deletions app/codes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,9 +340,15 @@ const generateCodeElements = (data) => {
"Access-Control-Allow-Origin": "*",
}

const key = "asd"
/** @type{LibStorage} */ const storage = dev ? JSON.parse(localStorage.getItem("dev_storage")) : JSON.parse(localStorage.getItem("storage"))

const key = storage.apiKey
const url = req.url
const param = req.url.split("apiKey=")[1]
let param = req.url.split("apiKey=")[1]

if (param !== undefined) {
param = aes.hash(param)
}

if (url.startsWith("/codes") && param === key) {
res.writeHead(200, headers)
Expand Down
32 changes: 27 additions & 5 deletions app/settings/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1200,11 +1200,6 @@ const resetShortcut = (value) => {

/* Integrations */
const integrations = () => {
const key = aes.generateRandomKey(aes.generateSalt())
const hash = aes.hash(key)

console.log(hash)

if (integrations_state === true) {
settings.settings.integrations = false

Expand All @@ -1215,6 +1210,33 @@ const integrations = () => {

integrations_state = false
} else {
const key = aes.generateRandomKey(aes.generateSalt()).toString("base64")
const hash = aes.hash(key)

/** @type{LibStorage} */ storage = dev ? JSON.parse(localStorage.getItem("dev_storage")) : JSON.parse(localStorage.getItem("storage"))

storage.apiKey = hash

dev ? localStorage.setItem("dev_storage", JSON.stringify(storage)) : localStorage.setItem("storage", JSON.stringify(storage))

const url = `http://localhost:1010/codes?apiKey=${key}`

dialog
.showMessageBox(BrowserWindow.getFocusedWindow(), {
title: "Authme",
buttons: [lang.button.copy, lang.button.close],
defaultId: 1,
cancelId: 1,
noLink: true,
type: "warning",
message: "You can copy your URL with your api key.\n\nYou can only copy the url once.",
})
.then(async (result) => {
if (result.response === 0) {
navigator.clipboard.writeText(url)
}
})

settings.settings.integrations = true

save()
Expand Down
6 changes: 5 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ const settings_file = {
language: null,
sort: null,
analytics: true,
integrations: true,
integrations: false,
},
security: {
require_password: null,
Expand Down Expand Up @@ -949,6 +949,8 @@ app.whenReady()

confirm_shown = true
}

logger.log("Showing security window")
}, 100)
}
})
Expand All @@ -968,6 +970,8 @@ app.whenReady()
window_codes.show()

codes_shown = true

logger.log("Showing codes window")
}

authenticated = true
Expand Down

0 comments on commit 9e2ec88

Please sign in to comment.