Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for Digest authorization #4339

Merged
merged 21 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: account for inherited auth with the inspector warning
  • Loading branch information
jamesgeorge007 committed Oct 29, 2024
commit df61ac58d12a031ec54f6f70721dc351516b8d9c
2 changes: 1 addition & 1 deletion packages/hoppscotch-common/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@
"client_nonce": "Client Nonce",
"opaque": "Opaque",
"disable_retry": "Disable Retrying Request",
"inspector_warning": "Agent interceptor is recommended when using Digest Authorization"
"inspector_warning": "Agent interceptor is recommended when using Digest Authorization."
}
},
"collection": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ import { computed, markRaw, Ref } from "vue"
import { getI18n } from "~/modules/i18n"
import { AgentInterceptorService } from "~/platform/std/interceptors/agent"
import { InterceptorService } from "~/services/interceptor.service"
import { RESTTabService } from "~/services/tab/rest"
import IconAlertTriangle from "~icons/lucide/alert-triangle"
import { InspectionService, Inspector, InspectorResult } from ".."

/**
* This inspector is responsible for inspecting the response of a request.
* It checks if the response is successful and if it contains errors.
* This inspector is responsible for inspecting the authorization properties of a request.
* Only applies to REST tabs currently.
*
* NOTE: Initializing this service registers it as a inspector with the Inspection Service.
*/
Expand All @@ -30,11 +31,33 @@ export class AuthorizationInspectorService
private readonly inspection = this.bind(InspectionService)
private readonly interceptorService = this.bind(InterceptorService)
private readonly agentService = this.bind(AgentInterceptorService)
private readonly restTabService = this.bind(RESTTabService)

override onServiceInit() {
this.inspection.registerInspector(this)
}

private resolveAuthType(auth: HoppRESTRequest["auth"]) {
if (auth.authType !== "inherit") {
return auth.authType
}

const activeTabDocument =
this.restTabService.currentActiveTab.value.document

if (activeTabDocument.type === "example-response") {
return null
}

const { inheritedProperties } = activeTabDocument

if (!inheritedProperties) {
return null
}

return inheritedProperties.auth.inheritedAuth.authType
}

getInspections(
req: Readonly<Ref<HoppRESTRequest | HoppRESTResponseOriginalRequest>>
) {
Expand All @@ -55,7 +78,9 @@ export class AuthorizationInspectorService
this.interceptorService.currentInterceptorID.value !==
this.agentService.interceptorID

if (auth.authType === "digest" && isUnsupportedInterceptor) {
const resolvedAuthType = this.resolveAuthType(auth)

if (resolvedAuthType === "digest" && isUnsupportedInterceptor) {
results.push({
id: "url",
icon: markRaw(IconAlertTriangle),
Expand Down