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

Basic auth on windows is broken when using Credential Manager #789

Open
ktaeleman opened this issue Oct 18, 2024 · 0 comments
Open

Basic auth on windows is broken when using Credential Manager #789

ktaeleman opened this issue Oct 18, 2024 · 0 comments

Comments

@ktaeleman
Copy link

Describe the bug
On Windows Platforms, when using Credential Manager to store the basic Auth user/pass, the base64 encoded string will be wrong, causing authentication to fail.

Please provide following details

  1. JiraCLI Version: 1.5.2
  2. Are you using Jira cloud or on-premise jira server? Local
  3. What operating system are you using? Windows 10
  4. What terminal are you using? Neovide nvim cmd.exe terminal

To Reproduce

  • Set up jira-cli init using basic auth
  • In Windows Credential Manager, create new generic key in the following format:
    • Internet or Network address: jira-cli:[username]
    • Username: [username]
    • Password: [password]

Expected behavior

Authentication works with properly encoded base64

Additional context
What seems to be happening is that the keyring/credman go packages return stored secrets as utf16(?) encoded strings, containing \0 bytes after every character byte. This results in a base64 encoded string that is around double the size of the expected base64 string.
Using --debug will show the wrong base64 auth header being sent.

A hacky solution taken from stackoverflow is to fix the apitoken where it is set in client.go:44

import {
...
++  "runtime"
...
}

...

func Client(config jira.Config) *jira.Client {
...
	if config.APIToken == "" {
		secret, _ := keyring.Get("jira-cli", config.Login)
++		if runtime.GOOS == "windows" {
++			secret = string(bytes.Replace([]byte(secret), []byte("\000"), nil, -1))
++		}
		config.APIToken = secret
	}

...
}

I'm not a go user and took a quick look at Go strings, but couldn't figure out the proper way to deal with this. Happy to create a pull request if you'd want to move forward with this solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant