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 · 3 comments
Open

API Key Auth not correctly being assigned to header #104

millerdrew opened this issue Mar 15, 2023 · 3 comments
Assignees
Labels
bug Something isn't working

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants