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

Fix example in README for self-hosted instances #49

Closed
wants to merge 1 commit into from

Conversation

phylor
Copy link

@phylor phylor commented Mar 25, 2021

For self-hosted servers, the base_url must not include a / at the end, because /api will be concatenated to it. If you do, the error message is quite vague:

rbw login: failed to log in to bitwarden instance: failed to parse JSON: .: EOF while parsing a value at line 1 column 0: EOF while parsing a value at line 1 column 0

Took me some time to read your code and figure out that the slash was the problem. I was mainly confused by the example https://api.bitwarden.com/ given, which has a trailing slash. So I included it in my self-hosted URL.

Alternatively, you could think about concatenating the URL using some library, which would drop a / if necessary (I don't know Rust, so I can't help).

Thank you for creating this tool! The pinentry and caching of the password in the agent is exactly what is missing from the official client.

For self-hosted servers, the `base_url` must not include a `/` at the end, because `/api` will be concatenated to it. If you do, the error message is quite vague:

```
rbw login: failed to log in to bitwarden instance: failed to parse JSON: .: EOF while parsing a value at line 1 column 0: EOF while parsing a value at line 1 column 0
```
@doy
Copy link
Owner

doy commented Apr 17, 2021

this isn't correct - i have always had my own private server configured with a trailing /, and it works fine. can you give more details about how you determined that this was the problem?

@phylor
Copy link
Author

phylor commented Apr 17, 2021

@doy Strange. There must be something different in our configurations/setups.

Here my flow to reproduce the issue:

$ cat ~/.config/rbw/config.json
{"email":"[email protected]","base_url":"https://bitwarden.example.com","identity_url":null,"lock_timeout":3600,"pinentry":"pinentry"}

$ rbw ls
# works fine

$ vim # add trailing slash
$ cat ~/.config/rbw/config.json
{"email":"[email protected]","base_url":"https://bitwarden.example.com/","identity_url":null,"lock_timeout":3600,"pinentry":"pinentry"}

$ rbw ls # I'm prompted for my password, I enter it and then the following error is displayed
rbw list: failed to log in to bitwarden instance: failed to parse JSON: .: EOF while parsing a value at line 1 column 0: EOF while parsing a value at line 1 column 0

Removing the trailing slash from the base_url, makes everything behave normally again.

The bitwarden server logs say:

bitwarden-api    | info: Microsoft.AspNetCore.Hosting.Diagnostics[1]
bitwarden-api    |       Request starting HTTP/1.0 POST http://bitwarden.example.com/accounts/prelogin application/json 24
bitwarden-api    | info: Microsoft.AspNetCore.Routing.EndpointMiddleware[0]
bitwarden-api    |       Executing endpoint 'Bit.Api.Controllers.AccountsController.PostPrelogin (Api)'
bitwarden-api    | info: Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker[3]
bitwarden-api    |       Route matched with {action = "PostPrelogin", controller = "Accounts"}. Executing controller action with signature System.Threading.Tasks.Task`1[Bit.Core.Models.Api.PreloginResponseModel] PostPrelogin(Bit.Core.Models.Api.PreloginRequestModel) on controller Bit.Api.Controllers.AccountsController (Api).
bitwarden-api    | info: Microsoft.AspNetCore.Mvc.Infrastructure.ObjectResultExecutor[1]
bitwarden-api    |       Executing ObjectResult, writing value of type 'Bit.Core.Models.Api.PreloginResponseModel'.
bitwarden-api    | info: Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker[2]
bitwarden-api    |       Executed action Bit.Api.Controllers.AccountsController.PostPrelogin (Api) in 146.5445ms
bitwarden-api    | info: Microsoft.AspNetCore.Routing.EndpointMiddleware[1]
bitwarden-api    |       Executed endpoint 'Bit.Api.Controllers.AccountsController.PostPrelogin (Api)'
bitwarden-api    | info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
bitwarden-api    |       Request finished in 160.1854ms 200 application/json; charset=utf-8
bitwarden-identity | info: Microsoft.AspNetCore.Hosting.Diagnostics[1]
bitwarden-identity |       Request starting HTTP/1.0 POST http://bitwarden.example.com//identity/connect/token application/x-www-form-urlencoded 245
bitwarden-identity | info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
bitwarden-identity |       Request finished in 1.3005ms 404

I guess it's notable that /accounts/prelogin does not have a double slash, but //identity/connect/token does. As that is the last request in the server logs, I gues rbw fails to parse its response (possibly because it's empty?).

I'm using the official bitwarden server and a traefik reverse proxy in front of that, if that matters.

@doy
Copy link
Owner

doy commented Apr 18, 2021

ah, this is probably a difference between the official bitwarden server and bitwarden_rs (which i use). it'll probably be easiest for me to just handle the concatenation properly.

@doy
Copy link
Owner

doy commented Apr 18, 2021

this should be fixed in 95c29fd

@doy doy closed this Apr 18, 2021
@phylor
Copy link
Author

phylor commented Apr 18, 2021

@doy Great, thank you!

@phylor phylor deleted the base-url-slash-at-end branch April 18, 2021 19:05
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

Successfully merging this pull request may close these issues.

2 participants