StrawberryShake: Generating classes using a client that needs token authentication

82 Views Asked by At

I am following the StrawberryShake documentation to create a console application to download data from a GraqhQL API. The difference in my case is that my server has a URL and one does not get access to it without an authentication token. But in the example in the doc, they are building a simple server and have easy access to it.

From the 4th step, Add a GraphQL client to your project using the CLI tools, I cannot go further because I cannot generate C# classes based on the schema. I suppose I should download the schema file first and then build the classes, neither of which I can accomplish this way.

The error message I get is:

error HTTP_ERROR: Response status code does not indicate success: 403 (Forbidden).

Is there anyone who has done this?

Installed NuGet packages in the Visual Studio project:

  • StrawberryShake (13.8.1)
  • StrawberryShake.CodeGeneration.CSharp (12.22.2)
  • StrawberryShake.Transport.Http (13.9.1)
1

There are 1 best solutions below

0
On

If you are able to initially generate the authentication token manually, you should then be able to get this working with additional parameters in your init-command, see : https://chillicream.com/docs/strawberryshake/v13/tooling

So this should be possible by adding something like, for example

--headers X-Hasura-Admin-Secret={ADMIN_SECRET}

or

--scheme Bearer --token {AUTHORIZATION_TOKEN}

This is quite easy to miss if you're just following along the Get Started-pages, as there are no mentions of/references to the Tooling/CLI-page where this is explained.