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

Strawberry Shake Tooling download command does not send scope(s) to token endpoint #5319

Closed
1 task done
charristti opened this issue Aug 19, 2022 · 2 comments · Fixed by #5340
Closed
1 task done
Labels
Milestone

Comments

@charristti
Copy link
Contributor

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Trying to use the download command dotnet graphql download retrieving the token from azure ad to pass to our graphql endpoint in order to retrieve schema generates unhandled exception.

Steps to reproduce

  1. Attempt to run dotnet graphql download passing --tokenEndpoint --clientId --clientSecret and --scope

Relevant log output

Unhandled exception. System.Text.Json.JsonException: The input does not contain any JSON tokens. Expected the input to start with a valid JSON token, when isFinalBlock is true. Path: $ | LineNumber: 0 | BytePositionInLine: 0.
 ---> System.Text.Json.JsonReaderException: The input does not contain any JSON tokens. Expected the input to start with a valid JSON token, when isFinalBlock is true. LineNumber: 0 | BytePositionInLine: 0.
   at System.Text.Json.ThrowHelper.ThrowJsonReaderException(Utf8JsonReader& json, ExceptionResource resource, Byte nextByte, ReadOnlySpan`1 bytes)
   at System.Text.Json.Utf8JsonReader.Read()
   at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
   --- End of inner exception stack trace ---
   at System.Text.Json.ThrowHelper.ReThrowWithPath(ReadStack& state, JsonReaderException ex)
   at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
   at System.Text.Json.JsonSerializer.ReadCore[TValue](JsonConverter jsonConverter, Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
   at System.Text.Json.JsonSerializer.ReadCore[TValue](JsonReaderState& readerState, Boolean isFinalBlock, ReadOnlySpan`1 buffer, JsonSerializerOptions options, ReadStack& state, JsonConverter converterBase)
   at System.Text.Json.JsonSerializer.ContinueDeserialize[TValue](ReadBufferState& bufferState, JsonReaderState& jsonReaderState, ReadStack& readStack, JsonConverter converter, JsonSerializerOptions options)
   at System.Text.Json.JsonSerializer.ReadAllAsync[TValue](Stream utf8Json, JsonTypeInfo jsonTypeInfo, CancellationToken cancellationToken)
   at HotChocolate.Utilities.Introspection.IntrospectionClient.ExecuteIntrospectionAsync(HttpClient client, HttpQueryRequest request, CancellationToken cancellationToken) in /home/vsts/work/1/s/src/HotChocolate/Utilities/src/Utilities.Introspection/IntrospectionClient.cs:line 144
   at HotChocolate.Utilities.Introspection.IntrospectionClient.GetSchemaFeaturesAsync(HttpClient client, CancellationToken cancellationToken) in /home/vsts/work/1/s/src/HotChocolate/Utilities/src/Utilities.Introspection/IntrospectionClient.cs:line 92
   at HotChocolate.Utilities.Introspection.IntrospectionClient.DownloadSchemaAsync(HttpClient client, CancellationToken cancellationToken) in /home/vsts/work/1/s/src/HotChocolate/Utilities/src/Utilities.Introspection/IntrospectionClient.cs:line 67
   at HotChocolate.Utilities.Introspection.IntrospectionClient.DownloadSchemaAsync(HttpClient client, Stream stream, CancellationToken cancellationToken) in /home/vsts/work/1/s/src/HotChocolate/Utilities/src/Utilities.Introspection/IntrospectionClient.cs:line 49
   at StrawberryShake.Tools.DefaultFileSystem.WriteToAsync(String fileName, Func`2 write) in /home/vsts/work/1/s/src/StrawberryShake/Tooling/src/dotnet-graphql/DefaultFileSystem.cs:line 81
   at StrawberryShake.Tools.IntrospectionHelper.DownloadSchemaAsync(HttpClient client, IFileSystem fileSystem, IActivity activity, String fileName, CancellationToken cancellationToken) in /home/vsts/work/1/s/src/StrawberryShake/Tooling/src/dotnet-graphql/IntrospectionHelper.cs:line 21
   at StrawberryShake.Tools.DownloadCommandHandler.DownloadSchemaAsync(DownloadCommandContext context, CancellationToken cancellationToken) in /home/vsts/work/1/s/src/StrawberryShake/Tooling/src/dotnet-graphql/DownloadCommandHandler.cs:line 64
   at StrawberryShake.Tools.DownloadCommandHandler.ExecuteAsync(DownloadCommandArguments arguments, CancellationToken cancellationToken) in /home/vsts/work/1/s/src/StrawberryShake/Tooling/src/dotnet-graphql/DownloadCommandHandler.cs:line 49
   at McMaster.Extensions.CommandLineUtils.CommandLineApplication.ExecuteAsync(String[] args, CancellationToken cancellationToken)
   at StrawberryShake.Tools.Program.<Main>(String[] args)

Additional Context?

Running tooling code in debug the problem appears to be in hotchocolate-12.12.1\src\StrawberryShake\Tooling\src\dotnet-graphql\OAuth\AuthArgumentsBase.cs

Lines 62,63,64 currently are:

                IEnumerable<string> scopes = Scopes.HasValue()
                    ? Enumerable.Empty<string>()
                    : Scopes.Values.Where(t => t is { }).OfType<string>();

This code returns the Enumerable.Empty when Scopes.HasValue() is true.

It should be:

                IEnumerable<string> scopes = Scopes.HasValue()
                    ? Scopes.Values.Where(t => t is { }).OfType<string>()
                    : Enumerable.Empty<string>();

returning a collection of scopes if there are any and an empty collection if not.

Happy to submit this as a PR with a little guidance.

Product

Strawberry Shake

Version

12.12.1

@charristti charristti added the 🐛 bug Something isn't working label Aug 19, 2022
@michaelstaib
Copy link
Member

do you want to do a PR?

@charristti
Copy link
Contributor Author

charristti commented Aug 20, 2022 via email

charristti added a commit to charristti/hotchocolate that referenced this issue Aug 24, 2022
Scopes are not processed properly when provided on the command line
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants