csharp icon indicating copy to clipboard operation
csharp copied to clipboard

GetServiceAccountIssuerOpenID Unable to deserialize the response

Open vturecek opened this issue 3 years ago • 2 comments

The methods that deal with Service Account issuer Open ID are unable to deserialize the response in the .NET client:

GetServiceAccountIssuerOpenIDConfigurationAsync
GetServiceAccountIssuerOpenIDKeysetAsync

The problem seems to be that both of these methods return a string. The JSON serializer is unable to deserialize the JSON response to a string type and so you get a JSON exception:

Microsoft.Rest.SerializationException: Unable to deserialize the response.\r\n ---\u003E Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: {. Path \u0027\u0027, line 1, position 1.\r\n  

I'm currently testing with cluster version 1.22.4, client package version 6.0.28, but even in the latest 8.0.12 package the return type is still a string. Is there a way to work around this, like getting the raw response without it trying to deserialize first?

vturecek avatar Aug 03 '22 21:08 vturecek

I was able to work around this by using my own class that derives from k8s.Kubernetes and overrides this method:

Task<HttpOperationResponse<T>> CreateResultAsync<T>(HttpRequestMessage httpRequest, HttpResponseMessage httpResponse, bool? watch, CancellationToken cancellationToken)

It checks if the type T is a string, and if so, doesn't try to deserialize, it just sets the raw string from the response. This isn't ideal though because there are references to other internal types in there that I had to deal with.

I'm not entirely sure why GetServiceAccountIssuerOpenIDKeysetAsync returns a string, I'm guessing because there isn't enough info in the swagger spec that this is autogenerated from? We could probably do a couple things though:

  1. Update CreateResultAsync to check for string types as I described above. That will at least make this API work without throwing and will cover any future cases where an API returns a string.
  2. If there's a way to manually specify the return type for the GetServiceAccountIssuerOpenIDKeysetAsync autogenerated method, the model would be simple since this is returning a list of keys:
    public class ServiceAccountIssuerKeySet
    {
        public IEnumerable<Microsoft.IdentityModel.Tokens.JsonWebKey> Keys { get; set; }
    }

This works nicely with Microsoft.IdentityModel.JsonWebTokens.JsonWebTokenHandler which can take the list in Keys directly when validating a token using a set of issuer signing keys (using an autogenerated model here that doesn't derive from Microsoft.IdentityModel.Tokens.SecurityKey or JsonWebKey would be cumbersome for consumers).

vturecek avatar Aug 04 '22 01:08 vturecek

checked swagger, it is defined as string

tg123 avatar Aug 04 '22 12:08 tg123

The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle stale
  • Mark this issue or PR as rotten with /lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

k8s-triage-robot avatar Nov 02 '22 13:11 k8s-triage-robot

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

k8s-triage-robot avatar Dec 02 '22 13:12 k8s-triage-robot

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Reopen this issue with /reopen
  • Mark this issue as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close not-planned

k8s-triage-robot avatar Jan 01 '23 14:01 k8s-triage-robot

@k8s-triage-robot: Closing this issue, marking it as "Not Planned".

In response to this:

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Reopen this issue with /reopen
  • Mark this issue as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close not-planned

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

k8s-ci-robot avatar Jan 01 '23 14:01 k8s-ci-robot