question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[GO] Bad Multiple Authentication Key setting

See original GitHub issue
Description

Multiple Authentication settings won’t work, since the API is setting the same key for multiple Headers.

openapi-generator version

3.1

OpenAPI declaration file content or url

in yaml:

[...]
security:
  - ApiKeyAuth1: []
  - ApiKeyAuth2: []
[...]
components:
  securitySchemes:
    ApiKeyAuth1:
      type: apiKey
      in: header
      name: X-Auth-Key-1
    ApiKeyAuth2:
      type: apiKey
      in: header
      name: X-Auth-Key-2

in go:

	if ctx != nil {
		// API Key Authentication
		if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok {
			var key string
			if auth.Prefix != "" {
				key = auth.Prefix + " " + auth.Key
			} else {
				key = auth.Key
			}
			localVarHeaderParams["X-Auth-Key-1"] = key
		}
	}

	if ctx != nil {
		// API Key Authentication
		if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok {
			var key string
			if auth.Prefix != "" {
				key = auth.Prefix + " " + auth.Key
			} else {
				key = auth.Key
			}
			localVarHeaderParams["X-Auth-Key-2"] = key
		}
	}

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:1
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
nmueschcommented, Jun 21, 2019

I added a second commit to the compare link from my last message. I’m not personally using Prefix and I wasn’t able to find docs surrounding its use case, so I’m not sure if I’m missing something surrounding that. The second commit I made is based off of @adamdecaf’s suggestion and just means you have to set the context value for each key you want to pass in.

1reaction
nmueschcommented, Jun 21, 2019

Hey @wing328 👋 Do you know if this is being actively worked on? I started looking into it to see if I could offer a contribution (my first 😄). I think one approach to resolving this would be to make the APIKey struct have one field per APIKey attribute from the openapi spec. I have the start of something thats working locally for me here - https://github.com/OpenAPITools/openapi-generator/compare/master...nmuesch:nick/fix_go_api_key?expand=1 Its not quite ready for a full PR yet so I wanted to post it here and get some thoughts!

A caveat I noticed here is that:

  • the name of the APIKey in the spec would have to be capitalized so that its exported in the autogenerated spec
  • I’m not sure if there are use cases for having different prefixes per key, but this would still use the same prefix on each key.

Would appreciate any feedback/thoughts 🙇

Read more comments on GitHub >

github_iconTop Results From Across the Web

Use a security key for 2-Step Verification - Google Account Help
Security keys can be used with 2-Step Verification to help you keep hackers out ... If you have other second steps set up,...
Read more >
Common problems with two-step verification for a work or ...
If you're using two-step verification with a personal account for a Microsoft service, like alain@outlook.com, you can turn the feature on and off....
Read more >
Two-factor authentication for Apple ID
On your iPhone, iPad, or iPod touch: Go to Settings > your name > Password & Security. Tap Turn On Two-Factor Authentication.
Read more >
How do I turn two-factor authentication on Instagram for ...
How do I turn two-factor authentication on Instagram for multiple devices on or off? ; 1. Tap or your profile picture in the...
Read more >
How To Set Up Multi-Factor Authentication for SSH on Ubuntu ...
If you need to log in to your server but don't have access to your TOTP app to get your verification code, you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found