csharp
csharp copied to clipboard
GetServiceAccountIssuerOpenID Unable to deserialize the response
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?
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:
- Update
CreateResultAsyncto check forstringtypes as I described above. That will at least make this API work without throwing and will cover any future cases where an API returns astring. - 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).
checked swagger, it is defined as string
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/staleis applied - After 30d of inactivity since
lifecycle/stalewas applied,lifecycle/rottenis applied - After 30d of inactivity since
lifecycle/rottenwas 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
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/staleis applied - After 30d of inactivity since
lifecycle/stalewas applied,lifecycle/rottenis applied - After 30d of inactivity since
lifecycle/rottenwas 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
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/staleis applied - After 30d of inactivity since
lifecycle/stalewas applied,lifecycle/rottenis applied - After 30d of inactivity since
lifecycle/rottenwas 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: 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/staleis applied- After 30d of inactivity since
lifecycle/stalewas applied,lifecycle/rottenis applied- After 30d of inactivity since
lifecycle/rottenwas applied, the issue is closedYou 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.