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

API Key Auth not correctly being assigned to header #104

Open
millerdrew opened this issue Mar 15, 2023 · 5 comments
Open

API Key Auth not correctly being assigned to header #104

millerdrew opened this issue Mar 15, 2023 · 5 comments
Assignees
Labels
bug Something isn't working Investigate Needs more investigation, before next steps can be defined. question/validate Further information or Validation is requested from the reporter

Comments

@millerdrew
Copy link

We have the following logic in lib\auth\apikey.js

const aid = require('../aid');

class ApiKeyAuth {
  constructor(settings) {
    const params = settings.parameters();
    const key = params.get('key');
    const value = aid.evalString(params.get('value'));

    if (params.get('in') === 'header') {
      this.logic = '' + `config.headers['${key}'] = ${value};`;
    } else {
      this.logic = '' + `config.options['${key}'] = ${value};`;
    }
  }
}

module.exports = ApiKeyAuth;

I have my Postman collection auth defined like this:

image

A snippet from the json output from my exported collection:

	"auth": {
		"type": "apikey",
		"apikey": [
			{
				"key": "value",
				"value": "{{Authorization}}",
				"type": "string"
			},
			{
				"key": "key",
				"value": "Authorization",
				"type": "string"
			}
		]
	},

It appears to be incorrectly using config.options instead of config.headers so my auth to fail when using the generated k6s output. If I manually change that part the auth works.

Perhaps something has changed in the output from Postman that's causing the line if (params.get('in') === 'header') { to not work as expected?

Here is my Postman version:

image

@millerdrew
Copy link
Author

millerdrew commented Mar 15, 2023

I notice in the test (test\material\2\apikey.json) we're expecting this:

{
	"info": {
		"_postman_id": "3cb6376b-535c-4c2f-a5d6-7bf193bcc6b9",
		"name": "Request",
		"schema": "https://schema.getpostman.com/json/collection/v2.0.0/collection.json"
	},
	"item": [
		{
			"name": "TestRequest",
			"request": {
				"auth": {
					"type": "apikey",
					"apikey": {
						"key": "Authorization",
						"value": "secretApiKey",
						"in": "header"
					}
				},
				"method": "GET",
				"header": [],
				"body": {
					"mode": "raw",
					"raw": ""
				},
				"url": "example.com"
			},
			"response": []
		}
	]
}

@thim81
Copy link
Collaborator

thim81 commented Mar 21, 2023

hi @millerdrew

Thanks for providing the details for what seems to be a bug.
Would it be possible to share your Postman collection or a simplified format of the collection?
That way we can try to reproduce the issue.

@thim81 thim81 added the bug Something isn't working label Mar 21, 2023
@thim81 thim81 self-assigned this Mar 21, 2023
@millerdrew
Copy link
Author

millerdrew commented Mar 21, 2023

@thim81 Sure. Here's a simplified export:

API Example.postman_collection.zip

The major difference from what's in the test appears to be this line is missing:

"in": "header"

instead there's only key, value, and type

thanks for the response appreciate your help! let me know if anything else would be useful

@thim81
Copy link
Collaborator

thim81 commented Jul 11, 2024

hi @millerdrew

Is this issue still happening?

@thim81 thim81 added the Investigate Needs more investigation, before next steps can be defined. label Jul 11, 2024
@thim81
Copy link
Collaborator

thim81 commented Jul 20, 2024

hi @millerdrew

I tried to reproduce your case, but I'm not able to fully understand your issue.
What you would expect?

This is the converted result:

group("Workflow", function() {
    postman[Request]({
      name: "dosomething",
      id: "c36db191-2918-4b63-af77-66300146301e",
      method: "POST",
      address: "{{BaseUrl}}/SomeAPI/dosomething",
      post(response) {
        pm.test("Status code is 200", function() {
          pm.response.to.have.status(200);
        });
      },
      auth(config, Var) {
        config.options["Authorization"] = `${pm[Var]("Authorization")}`;
      }
    });
  });

@thim81 thim81 added the question/validate Further information or Validation is requested from the reporter label Jul 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Investigate Needs more investigation, before next steps can be defined. question/validate Further information or Validation is requested from the reporter
Projects
None yet
Development

No branches or pull requests

2 participants