Skip to content

Commit

Permalink
fix the bug that postman V2.0 auth apiKey can not be parsed when impo…
Browse files Browse the repository at this point in the history
…rting (#8241)
  • Loading branch information
yaoweiprc authored Dec 16, 2024
1 parent 5f4f39d commit cdb2e5d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"editor.defaultFormatter": "vscode.json-language-features"
},
"cSpell.words": [
"apikey",
"Dismissable",
"getinsomnia",
"inso",
Expand Down
39 changes: 26 additions & 13 deletions packages/insomnia/src/utils/importers/importers/postman.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const description = 'Importer for Postman collections';
type PostmanCollection = V200Schema | V210Schema;
type EventList = V200EventList | V210EventList;

type Authetication = V200Auth | V210Auth;
type Authentication = V200Auth | V210Auth;

type Body = V200Request1['body'] | V210Request1['body'];

Expand Down Expand Up @@ -479,7 +479,7 @@ export class ImportPostman {
};
};

importAuthentication = (authentication?: Authetication | null, originalHeaders: Header[] = []) => {
importAuthentication = (authentication?: Authentication | null, originalHeaders: Header[] = []) => {
const isAuthorizationHeader = ({ key }: Header) => key === 'Authorization';
const authorizationHeader = originalHeaders.find(isAuthorizationHeader)?.value;

Expand Down Expand Up @@ -586,7 +586,7 @@ export class ImportPostman {
}
};

importAwsV4Authentication = (auth: Authetication) => {
importAwsV4Authentication = (auth: Authentication) => {
if (!auth.awsv4) {
return {};
}
Expand Down Expand Up @@ -652,7 +652,7 @@ export class ImportPostman {
};
};

importBasicAuthentication = (auth: Authetication) => {
importBasicAuthentication = (auth: Authentication) => {
if (!auth.basic) {
return {};
}
Expand Down Expand Up @@ -701,7 +701,7 @@ export class ImportPostman {
return item;
};

importBearerTokenAuthentication = (auth: Authetication) => {
importBearerTokenAuthentication = (auth: Authentication) => {
if (!auth.bearer) {
return {};
}
Expand Down Expand Up @@ -742,7 +742,7 @@ export class ImportPostman {
};
};

importDigestAuthentication = (auth: Authetication) => {
importDigestAuthentication = (auth: Authentication) => {
if (!auth.digest) {
return {};
}
Expand Down Expand Up @@ -783,7 +783,7 @@ export class ImportPostman {
return item;
};

importOauth1Authentication = (auth: Authetication) => {
importOauth1Authentication = (auth: Authentication) => {
if (!auth.oauth1) {
return {};
}
Expand Down Expand Up @@ -859,20 +859,33 @@ export class ImportPostman {

};

importApiKeyAuthentication = (auth: Authetication) => {
importApiKeyAuthentication = (auth: Authentication) => {
if (!auth.apikey) {
return {};
}
const apikey = auth.apikey as V210Auth['apikey'];
const apikey = auth.apikey as V200Auth['apikey'] | V210Auth['apikey'];
let keyVal, valueVal, inVal: string;
if (Array.isArray(apikey)) {
// V2.1
keyVal = this.findValueByKey(apikey, 'key');
valueVal = this.findValueByKey(apikey, 'value');
inVal = this.findValueByKey(apikey, 'in');
} else {
// V2.0
keyVal = apikey?.key as string;
valueVal = apikey?.value as string;
inVal = apikey?.in as string;
}

return {
type: 'apikey',
key: this.findValueByKey(apikey, 'key'),
value: this.findValueByKey(apikey, 'value'),
addTo: this.findValueByKey(apikey, 'in') === 'query' ? 'queryParams' : 'header',
key: keyVal,
value: valueVal,
addTo: inVal === 'query' ? 'queryParams' : 'header',
disabled: false,
};
};
importOauth2Authentication = (auth: Authetication): AuthTypeOAuth2 | {} => {
importOauth2Authentication = (auth: Authentication): AuthTypeOAuth2 | {} => {
if (!auth.oauth2) {
return {};
}
Expand Down

0 comments on commit cdb2e5d

Please sign in to comment.