connect-sdk-go icon indicating copy to clipboard operation
connect-sdk-go copied to clipboard

Trim newlines of token

Open rickdgeerling opened this issue 2 years ago • 2 comments

Summary

A token with additional newlines is not considered valid and results in a rather unhelpful error message: Failed to retrieve item: Get "http://onepassword-connect:8080/v1/vaults?filter=title+eq+%22engineering%22": net/http: invalid header field value for "Authorization". Trimming newlines would resolve the problem.

This is not a bug, because headers shouldn't contain newlines, but trimming the token string would result in a better developer-experience. It's rather easy to create such an invalid token with kubectl create secret generic op-token --from-file=token=token.txt because a lot of text editors are configured to add a trailing newline.

Use cases

Can save a few hours of debugging for anyone that doesn't follow the getting started guide exactly. In my case I integrated it into an existing Kustomize setup. Kustomize emphasises a declarative approach and loading the secret from a file is therefore not a strange approach.

Proposed solution

Please trim the token. I'd open up a PR but I'm not familiar with Go and its toolchain

Is there a workaround to accomplish this today?

Yes, remove newlines with some bash-fu

cat token.txt | tr -d "\n" > trimmed_token.txt

References & Prior Work

n/a

rickdgeerling avatar Mar 01 '23 18:03 rickdgeerling

Hey @tuxmachine! 👋

Thank you for raising this enhancement for the SDK. I can see this come in handy to ensure any leading or following whitespaces and newlines don't break the flow of using the token. We've tracked this internally and keep you updated when there's progress on it. 😄

edif2008 avatar Dec 01 '23 15:12 edif2008

This issue just caused me two hours of infuriating troubleshooting, please improve this handling.

bo0tzz avatar Jun 02 '25 14:06 bo0tzz