feat: enable / disable authorization

This commit is contained in:
liyasthomas
2021-08-12 13:56:11 +05:30
parent 971b35a252
commit b18f7af28f
12 changed files with 172 additions and 108 deletions

View File

@@ -155,28 +155,28 @@ export const spotlight = [
label: "shortcut.navigation.back",
action: "navigation.jump.back",
icon: "arrow_forward",
keywords: ["back", "jump", "page", "navigation"],
keywords: ["back", "jump", "page", "navigation", "go"],
},
{
keys: [getPlatformSpecialKey(), "→"],
label: "shortcut.navigation.forward",
action: "navigation.jump.forward",
icon: "arrow_forward",
keywords: ["forward", "jump", "page", "navigation"],
keywords: ["forward", "jump", "page", "navigation", "go"],
},
{
keys: [getPlatformAlternateKey(), "R"],
label: "shortcut.navigation.rest",
action: "navigation.jump.rest",
icon: "arrow_forward",
keywords: ["rest", "jump", "page", "navigation"],
keywords: ["rest", "jump", "page", "navigation", "go"],
},
{
keys: [getPlatformAlternateKey(), "Q"],
label: "shortcut.navigation.graphql",
action: "navigation.jump.graphql",
icon: "arrow_forward",
keywords: ["graphql", "jump", "page", "navigation"],
keywords: ["graphql", "jump", "page", "navigation", "go"],
},
{
keys: [getPlatformAlternateKey(), "W"],
@@ -192,6 +192,7 @@ export const spotlight = [
"socket",
"mqtt",
"sse",
"go",
],
},
{
@@ -199,7 +200,7 @@ export const spotlight = [
label: "shortcut.navigation.documentation",
action: "navigation.jump.documentation",
icon: "arrow_forward",
keywords: ["documentation", "jump", "page", "navigation"],
keywords: ["documentation", "jump", "page", "navigation", "go"],
},
{
keys: [getPlatformAlternateKey(), "S"],
@@ -213,6 +214,7 @@ export const spotlight = [
"navigation",
"account",
"theme",
"go",
],
},
],

View File

@@ -1,9 +1,11 @@
export type HoppRESTAuthNone = {
authType: "none"
authActive: true
}
export type HoppRESTAuthBasic = {
authType: "basic"
authActive: true
username: string
password: string
@@ -11,6 +13,7 @@ export type HoppRESTAuthBasic = {
export type HoppRESTAuthBearer = {
authType: "bearer"
authActive: true
token: string
}

View File

@@ -115,11 +115,13 @@ export function parseOldAuth(x: any): HoppRESTAuth {
if (!x.auth || x.auth === "None")
return {
authType: "none",
authActive: true,
}
if (x.auth === "Basic Auth")
return {
authType: "basic",
authActive: true,
username: x.httpUser,
password: x.httpPassword,
}
@@ -127,8 +129,9 @@ export function parseOldAuth(x: any): HoppRESTAuth {
if (x.auth === "Bearer Token")
return {
authType: "bearer",
authActive: true,
token: x.bearerToken,
}
return { authType: "none" }
return { authType: "none", authActive: true }
}

View File

@@ -41,21 +41,23 @@ export function getEffectiveRESTRequest(
}))
// Authentication
// TODO: Support a better b64 implementation than btoa ?
if (request.auth.authType === "basic") {
effectiveFinalHeaders.push({
active: true,
key: "Authorization",
value: `Basic ${btoa(
`${request.auth.username}:${request.auth.password}`
)}`,
})
} else if (request.auth.authType === "bearer") {
effectiveFinalHeaders.push({
active: true,
key: "Authorization",
value: `Bearer ${request.auth.token}`,
})
if (request.auth.authActive) {
// TODO: Support a better b64 implementation than btoa ?
if (request.auth.authType === "basic") {
effectiveFinalHeaders.push({
active: true,
key: "Authorization",
value: `Basic ${btoa(
`${request.auth.username}:${request.auth.password}`
)}`,
})
} else if (request.auth.authType === "bearer") {
effectiveFinalHeaders.push({
active: true,
key: "Authorization",
value: `Bearer ${request.auth.token}`,
})
}
}
return {