Help Running Server API locally

Note: Your question may already be answered in the Bitwarden Help Center.

Hi All. I’m trying to understand the codebase locally so that I can contribute.
I keep getting "System.FormatException: 'Settings must be of the form " on the line below. Has anyone encountered this before ? The input to Parse is “secret”
File : TableStorage\InstallationDeviceRepository.cs
Method : InstallationDeviceRepository(string storageConnectionString)
Line : CloudStorageAccount.Parse(storageConnectionString);

Welcome to the forums!

My guess is that your SQL connection string is not set properly.

Have you set up your user secrets, including sqlServer__connectionString, as described in CONTRIBUTING.md?

If yes, can you post a copy of your user secrets file? (make sure to redact any confidential info, e.g. keys or passwords) Can you also post a complete copy of the error message - it looks like you only copied half of it?

1 Like

Thanks, I missed the steps from the document. I will follow them and revert if I still have issues.

@eliykat So I followed the steps (1-5) to set up the secrets file.
Copy of user secrets file attached.Secrets File
now I have a new error:

An exception of type ‘System.Exception’ occurred in Core.dll but was not handled in user code
Invalid licensing certificate.

Your certificateThumbprints and installation id & key are all meant to be secret - you should remove them when sharing your secrets file with others. (It probably doesn’t matter in this case because it’s just a local dev environment, but you may want to regenerate them anyway as a matter of best practice.)

Anyway, your secrets file looks good to me.

Try making this change in your Core/Services/Implementations/LicensingService.cs:

Find the line that sets certThumbprint:

var certThumbprint = environment.IsDevelopment() ?

Add a bang (!) like so:

var certThumbprint = !environment.IsDevelopment() ?

I’m not sure why this is required, but I also hit this error and this fixed it for me.

Thanks! Yes I’ll regenerate once I can get it all running. I’m now able to set up the environment but I’m now getting an error when I try to Login. The Register endpoint worked fine but when I Login I get the frontend error “Unable to Fetch”. The console looks good below. Any thoughts?

> Microsoft.AspNetCore.Hosting.Diagnostics: Information: Request starting HTTP/1.1 POST http://localhost:4000/accounts/prelogin application/json; charset=utf-8 33
Microsoft.AspNetCore.Cors.Infrastructure.CorsService: Information: CORS policy execution successful.
Microsoft.AspNetCore.Routing.EndpointMiddleware: Information: Executing endpoint 'Bit.Api.Controllers.AccountsController.PostPrelogin (Api)'
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker: Information: 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).
Microsoft.AspNetCore.Mvc.Infrastructure.ObjectResultExecutor: Information: Executing ObjectResult, writing value of type 'Bit.Core.Models.Api.PreloginResponseModel'.
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker: Information: Executed action Bit.Api.Controllers.AccountsController.PostPrelogin (Api) in 16.9965ms
Microsoft.AspNetCore.Routing.EndpointMiddleware: Information: Executed endpoint 'Bit.Api.Controllers.AccountsController.PostPrelogin (Api)'
Microsoft.AspNetCore.Hosting.Diagnostics: Information: Request finished in 47.3292ms 200 application/json; charset=utf-8

I’ve received client errors like that if I haven’t set my client application environment correctly. You should have:

(Note the use of http instead of https - no idea why it would use http but it’s tripped me up before.)

That said, your api endpoint is clearly receiving the request. What about your identity server - is that set correctly and running? Does it give you any useful output?

I was using a local copy of the web application as client. I also used the extension after updating API and Identity URLs but still have same error.
Regarding the Identity server, I updated the secrets file to use the same secrets.json as Api. Also set selfHosted to true. I also updated the the connection string in appsettings.json. Now I get 404 (before these updates, I was getting “no license directory” error.
Thanks for all your help! I know the errors are quite many :slight_smile:

Hmm, that’s tricky. It sounds like your config is generally correct. The only issues I can think of are:

  • Have you started the identity server by navigating to its project directory and executing dotnet run? (You need to do this separately for the api and identity server projects)
  • Are there any errors in the identity server output?
  • Are you using the right port? The identity server output should tell you what port it’s listening on and whether it’s using http or https. (It may be different to mine for some reason)

Yes I started it (together with Api and alone just to troubleshoot). No errors. See below:

> info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[0] User profile is available. Using 'C:\Users\abc\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest. info: IdentityServer4.Startup[0] Starting IdentityServer4 version 4.0.4+1b36d1b414f4e0f965af97ab2a7e9dd1b5167bca info: IdentityServer4.Startup[0] Using the default authentication scheme idsrv for IdentityServer info: Bit.Identity.Startup[12482444] Identity started. info: Microsoft.Hosting.Lifetime[0] Now listening on: http://localhost:33656 info: Microsoft.Hosting.Lifetime[0] Application started. Press Ctrl+C to shut down. info: Microsoft.Hosting.Lifetime[0] Hosting environment: Development info: Microsoft.Hosting.Lifetime[0] Content root path: C:\Users\abc\source\repos\server\src\Identity info: Microsoft.AspNetCore.Hosting.Diagnostics[1] Request starting HTTP/1.1 GET http://localhost:33656/ info: Microsoft.AspNetCore.Hosting.Diagnostics[2] Request finished in 299.2732ms 404

Your GET request is being sent to the base URL of http://localhost:33656. That’s the correct URL for your client configuration, but not for testing whether it’s alive, which I assume is what you’re doing. To test if the identity server is alive, navigate to http://localhost:33656/.well-known/openid-configuration instead.

Assuming that works, and there are no errors in any server-side output, but your client is still giving you Unable to fetch… I’m not sure! I think you’ll have to do some more in depth debugging. e.g. trying with a different client, checking firewall rules, examining network traffic. Good luck!

If you get any more detailed debugging info (or if you solve it!), feel free to post it here.

It looks like the Identity app was the missing piece. Now I’m running both projects simultaneously on Visual Studio and everything is now working (web browser and extension)! Thanks a lot for your patience. I’ll probably be back as I dig into the code more. Thank You!!!

1 Like