crowdin / crowdin-cli

A command-line client for the Crowdin API
https://crowdin.github.io/crowdin-cli
MIT License
248 stars 92 forks source link

Unable to set up CLI - authorization error #387

Closed AllTradesz closed 3 years ago

AllTradesz commented 3 years ago

Help would be massively appreciated!!

Describe the bug

Trying to set up CLI, and just can't get it to work. Keep getting

$ crowdin list -v project
❌ Fetching project info
❌ Failed to collect project info. Please contact our support team for help
❌ Couldn't authorize. Check your 'api_token'.

Brand new api_token generated and used.

This command works fine after editing the stub crowdin.yml generated by "crowdin init"

$ crowdin lint
Your configuration file looks good

To Reproduce

#

Choose file structure in Crowdin

e.g. true or false

# "preserve_hierarchy": true

#

Files configuration

# files: [ { "source": "src/locales/en/*.json", "translation": "src/locales/%two_letters_code%/%original_file_name%" } ]

Environment:

$ java --version
openjdk 11.0.12 2021-07-20
OpenJDK Runtime Environment (build 11.0.12+7-post-Debian-2deb10u1)
OpenJDK 64-Bit Server VM (build 11.0.12+7-post-Debian-2deb10u1, mixed mode, sharing)

$ crowdin --version
3.6.4

Additional context It could be my CrowdIn project is munged somehow. In efforts to troubleshoot, I deleted and created new api_tokens. I just noticed in the web UI that at some point a successful API connection was made, as shown below. I believe this was before I deleted and recreated the token. Obviously though I had never seen success when on the CLI, else I wouldn't have tried the recreation. I am left to speculate that somehow the project is rejecting new auth tokens? Weird. image

denisqua commented 3 years ago

Hey @AllTradesz !

I'm sorry for the issue you've faced!

I guess you've tried to generate new API token and paste it to the crowdin.yml, right?

I meant here: API_token1

Also, seems you need to add additional slashes at the beginning (before src/locales...), like:

"source": "/src/locales/en/*.json", "translation": "/src/locales/%two_letters_code%/%original_file_name%"

and one more thing, could you please confirm you've tried to generate crowdin.yml by running "crowdin generate" command?

Screenshot_12

If everything above doesn't help, our tech guys will definitely take a look at that

AllTradesz commented 3 years ago

Thanks for the prompt reply and hints!

The only real change was to add the initial slashes, thanks, but result is exactly the same output -- no joy. $ crowdin list -v project ❌ Fetching project info
❌ Failed to collect project info. Please contact our support team for help ❌ Couldn't authorize. Check your 'api_token'.

I also just tried using the crowdin generate you referenced, to confirm, but same result. Obviously crowdin init calls that command or is that command, and so generates the same crowdin.yml as I had already had, basically.

Like I said, it seems my project or user account is no longer accepting API access (remember it seems it did one time only, a week ago, that screenshot I shared above, but since then nothing in that UI, no error reports, nothing)? Maybe someone can view the account record and identify a hidden munge or misconfig..

Here is a screenshot of my "personal access token(s)" image

denisqua commented 3 years ago

Hi again,

Thanks a lot for all your efforts!

I do confirm that you're generating keys in the right place and even see API logs: https://crowdin.com/project/beefy-dashboard/integrations/api

I'll ask someone from the tech team to take a look at that, but assume it'll be on Monday (since they have a weekend already)

but rest assured, once we have any news - you'll be first to know!

AllTradesz commented 3 years ago

yes, I am quite interested to get this resolved. It's gotta be something simple. I could blow away my current CrowdIn project that's been operating actively for a few months, and then hard reset, but then I'd lose all the historical context right? Like older translations, comments, context. I'd like to avoid that.

ira-sem commented 3 years ago

Hi @AllTradesz! Could you please run the command with parameter --debug and share the output with us?

AllTradesz commented 3 years ago

Anything else I could try short of breaking out tcpdump? :)

$ crowdin list -v --debug project
❌ Fetching project info     
java.lang.RuntimeException: Failed to collect project info. Please contact our support team for help
        at com.crowdin.cli.utils.console.ConsoleSpinner.execute(ConsoleSpinner.java:29)
        at com.crowdin.cli.commands.actions.ListProjectAction.act(ListProjectAction.java:32)
        at com.crowdin.cli.commands.actions.ListProjectAction.act(ListProjectAction.java:15)
        at com.crowdin.cli.commands.picocli.GenericActCommand.run(GenericActCommand.java:37)
        at picocli.CommandLine.executeUserObject(CommandLine.java:1939)
        at picocli.CommandLine.access$1300(CommandLine.java:145)
        at picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent(CommandLine.java:2352)
        at picocli.CommandLine$RunLast.handle(CommandLine.java:2346)
        at picocli.CommandLine$RunLast.handle(CommandLine.java:2311)
        at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2179)
        at picocli.CommandLine.execute(CommandLine.java:2078)
        at com.crowdin.cli.commands.picocli.PicocliRunner.execute(PicocliRunner.java:37)
        at com.crowdin.cli.Cli.main(Cli.java:16)
Caused by: java.lang.RuntimeException: Couldn't authorize. Check your 'api_token'.
        at com.crowdin.cli.client.CrowdinClientCore$1.(CrowdinClientCore.java:33)
        at com.crowdin.cli.client.CrowdinClientCore.(CrowdinClientCore.java:30)
        at com.crowdin.cli.client.Clients.getProjectClient(Clients.java:35)
        at com.crowdin.cli.commands.picocli.ActCommandWithFiles.getClient(ActCommandWithFiles.java:30)
        at com.crowdin.cli.commands.picocli.ActCommandWithFiles.getClient(ActCommandWithFiles.java:11)
        at com.crowdin.cli.commands.picocli.GenericActCommand.run(GenericActCommand.java:36)
        ... 9 more
andrii-bodnar commented 3 years ago

Hi @AllTradesz!

We can't reproduce this issue. Could you please check if any other CLI commands are working? For example, crowdin status

AllTradesz commented 3 years ago

crowdin lint and crowdin init work. crowdin status does not

$ crowdin -v --debug status
❌ Fetching project info     
java.lang.RuntimeException: Failed to collect project info. Please contact our support team for help
        at com.crowdin.cli.utils.console.ConsoleSpinner.execute(ConsoleSpinner.java:29)
        at com.crowdin.cli.commands.actions.StatusAction.act(StatusAction.java:33)
        at com.crowdin.cli.commands.actions.StatusAction.act(StatusAction.java:15)
        at com.crowdin.cli.commands.picocli.GenericActCommand.run(GenericActCommand.java:37)
        at picocli.CommandLine.executeUserObject(CommandLine.java:1939)
        at picocli.CommandLine.access$1300(CommandLine.java:145)
        at picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent(CommandLine.java:2352)
        at picocli.CommandLine$RunLast.handle(CommandLine.java:2346)
        at picocli.CommandLine$RunLast.handle(CommandLine.java:2311)
        at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2179)
        at picocli.CommandLine.execute(CommandLine.java:2078)
        at com.crowdin.cli.commands.picocli.PicocliRunner.execute(PicocliRunner.java:37)
        at com.crowdin.cli.Cli.main(Cli.java:16)
Caused by: java.lang.RuntimeException: Couldn't authorize. Check your 'api_token'.
        at com.crowdin.cli.client.CrowdinClientCore$1.<init>(CrowdinClientCore.java:33)
        at com.crowdin.cli.client.CrowdinClientCore.<clinit>(CrowdinClientCore.java:30)
        at com.crowdin.cli.client.Clients.getProjectClient(Clients.java:35)
        at com.crowdin.cli.commands.picocli.ActCommandWithFiles.getClient(ActCommandWithFiles.java:30)
        at com.crowdin.cli.commands.picocli.ActCommandWithFiles.getClient(ActCommandWithFiles.java:11)
        at com.crowdin.cli.commands.picocli.GenericActCommand.run(GenericActCommand.java:36)
        ... 9 more

If you'd like me to send you my api_token and whatever else would be needed to reproduce, I'd be happy to out of band. I'm anxious to get past this roadblock, that's for sure.

andrii-bodnar commented 3 years ago

@AllTradesz thanks for the details provided. Could you invite me to your project as a manager? My username in Crowdin - andrii-bodnar. I will try to execute CLI commands using your project ID and my own token.

AllTradesz commented 3 years ago

Absolutely @andrii-bodnar! Thanks for taking a closer look. Am hooking this up immediately.

andrii-bodnar commented 3 years ago

@AllTradesz, checked everything and it works great for my token and your project:

Screenshot from 2021-08-11 17-09-31

Other CLI commands are also working.

Please make sure you are using a token generated under the account that has owner or manager access to your project. Also, please try to generate a new token.

Actually, it's a very strange issue :confused:

AllTradesz commented 3 years ago

So good news that we've isolated things somewhat further. But the key step of reproduction eludes us. As I noted from the outset, I've already regenerated the token a few times to no avail. I will try again though and fiddle with the options you're showing in your interesting command line, and report back.

If it still doesn't work after that, it must be something off-kilter in my system or my account. I don't know if this will jar an idea loose in you, but my account was set up via the GitHub OAuth mechanism, I believe, and continues to use that.

andrii-bodnar commented 3 years ago

I'm sure it's not related to the account creation way.

AllTradesz commented 3 years ago

@andrii-bodnar Did as you suggested and precisely the same result. Revoked the two existing tokens and created another with a different name.

How about I send you out-of-band my new token, and you try it with your system? You're already manager at the moment, so should work. That would isolate it down to my system or my personal account. I'm accessible via Discord, Telegram, email, or I could add a special string for you in CrowdIn itself, should be easy & safe for us.

Also seems worth mentioning I recall that I did change the name & email & GitHub name associated with my account a month or so ago. So I'm leaning heavily that the cause lies in my personal CrowdIn account (record) and not with my seemingly oh-so-generic cloud-based Debian system.

andrii-bodnar commented 3 years ago

@AllTradesz ok, I can try to run CLI with your token. Please send it using this form - https://crowdin.com/contacts. You can mention this issue and our support team will pass this token to me.

andrii-bodnar commented 3 years ago

@AllTradesz just checked the token you've sent to our support team and it works fine :thinking:

On the Integrations > API tab in the project settings, there are new API logs that refer to this token

andrii-bodnar commented 3 years ago

@AllTradesz could you please check on another computer?

Also, you could try to use Postman on the current computer and make some API calls to Crowdin using your token. Just to be sure

If you are using some proxy on your computer, CLI requires some additional configuration - Using Crowdin CLI with Proxy Server

Velliz commented 3 years ago

Is there any probability api_token inside generated crowdin.yml file have expire time?

I also noticed for my generated crowdin.yml on 13 july 2021 now turns into Couldn't authorize. Check your 'api_token'..

Delete the crowdin.yml file, repeat crowdin init command solve the issue for me.

Trying to find in documentation to how re-generate api_token but no results.

andrii-bodnar commented 3 years ago

@Velliz if a token is generated in account settings, it has no expiration.

But in the case of authorization via browser using the crowdin init command, a token has an expiration - 1 month.

Velliz commented 3 years ago

Thanks for mentioning authorization via browser. That's excactly what i do. 😅

I will replace the token with-from account settings. 👍

AllTradesz commented 3 years ago

All right. Finally freaking resolved. As expected, something incredibly dumb at fault.

Per the security suggestion in the docs, early on I had placed my api_token in a .crowdin.yml file in my home directory. Eventually I forgot about it. Well, that bugger silently overrides anything placed in that property in the normal yml file!

I suppose it would make sense for the code to spit out a warning when this is encountered, so consider that a tiny feature request. 🙂

I discovered this cause by actually stepping through the code in the JDK's text-based debugger jdb, my first time using this. Works pretty well for something so lightweight, can set breakpoints, switch stack frames, inspect objects, remote debug. So at least I got that knowledge out of this ordeal, haha.