Skip to content

Commit

Permalink
fix: digest auth in cli
Browse files Browse the repository at this point in the history
  • Loading branch information
anwarulislam committed Oct 23, 2024
1 parent 45c65fc commit ee27463
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"id": "cm0dm70cw000687bnxi830zz7",
"auth": {
"authType": "digest",
"authActive": true,
"username": "<<username>>",
"password": "<<password>>",
"realm": "",
Expand Down
17 changes: 7 additions & 10 deletions packages/hoppscotch-cli/src/utils/auth/digest.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { md5 } from "js-md5";
import * as E from "fp-ts/Either";
import axios from "axios";

export interface DigestAuthParams {
username: string;
Expand Down Expand Up @@ -71,18 +71,15 @@ export async function fetchInitialDigestAuthInfo(
): Promise<DigestAuthInfo> {
console.log("Fetching initial digest auth info...");
try {
const service = getService(InterceptorService);
const initialResponse = await service.runRequest({
const initialResponse = await axios.request({
url,
method,
}).response;

if (E.isLeft(initialResponse))
throw new Error(`Unexpected response: ${initialResponse.left}`);
validateStatus: () => true, // Allow handling of all status codes
});

// Check if the response status is 401 (which is expected in Digest Auth flow)
if (initialResponse.right.status === 401) {
const authHeader = initialResponse.right.headers["www-authenticate"];
if (initialResponse.status === 401) {
const authHeader = initialResponse.headers["www-authenticate"];

if (authHeader) {
const authParams = parseDigestAuthHeader(authHeader);
Expand All @@ -105,7 +102,7 @@ export async function fetchInitialDigestAuthInfo(
"Failed to parse authentication parameters from WWW-Authenticate header"
);
} else {
throw new Error(`Unexpected response: ${initialResponse.right.status}`);
throw new Error(`Unexpected response: ${initialResponse.status}`);
}
} catch (error) {
console.error("Error fetching initial digest auth info:", error);
Expand Down
2 changes: 0 additions & 2 deletions packages/hoppscotch-cli/src/utils/pre-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,6 @@ export async function getEffectiveRESTRequest(
// Step 3: Generate the Authorization header
const authHeaderValue = await generateDigestAuthHeader(digestAuthParams);

console.log("Digest Auth Header:", authHeaderValue);

effectiveFinalHeaders.push({
active: true,
key: "Authorization",
Expand Down

0 comments on commit ee27463

Please sign in to comment.