question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

OpenIdConnectConfiguration not serializing properly

See original GitHub issue

The OpenIdConnectConfiguration is not serializing the field jwks_uri field, the bellow example show the incorrect field naming (jwksUri).

The package to reproduce the behavior is Microsoft.IdentityModel.Protocols.OpenIdConnect version 5.5.0.

The problem caused is that the authenticationservice could not ask the authority the public key set to validate a token.

{
  "additionalData": {},
  "acrValuesSupported": [],
  "authorizationEndpoint": "https://localhost:4000/connect/authorization",
  "checkSessionIframe": null,
  "claimsSupported": [], "claimsLocalesSupported": [],
  "claimsParameterSupported": false,
  "claimTypesSupported": [],
  "displayValuesSupported": [],
  "endSessionEndpoint": null,
  "frontchannelLogoutSessionSupported": null,
  "frontchannelLogoutSupported": null,
  "grantTypesSupported": [],
  "httpLogoutSupported": false,
  "idTokenEncryptionAlgValuesSupported": [],
  "idTokenEncryptionEncValuesSupported": [],
  "idTokenSigningAlgValuesSupported": [],
  "issuer": "https://localhost:4000",
  "jwksUri": "https://localhost:4000/.well-known/openid-configuration/jwks",
  "jsonWebKeySet": {
    "additionalData": {},
    "keys": [
      {
        "additionalData": {},
        "alg": null,
        "crv": null,
        "d": null,
        "dp": null,
        "dq": null,
        "e": "AQAB",
        "k": null,
        "keyId": "319D93355237260601A940A962991084B835681A",
        "keyOps": [],
        "kid": "319D93355237260601A940A962991084B835681A",
        "kty": "RSA",
        "n": "4wyItVfNjf/3NVwA8z1ijlAz/SmGSdQ+U2M22TwR/vQWGmT3Fivg7Do9otPwTQBTIVkU3NnTyhB8jH0pe2LSqkVJXzwQjtma3aH/GaHMYTArB36xf5YESPWb1tvVmbIFFxtqaMZYnvUOYqh4c6yYBLPbQkKE8aSvYtEfvucA5XPwQU11sA9fRuScWO0psKBD1xtXZDB3vzv0JSZFmWB6OSCQcrBiBLFsGUlDogOCuLqN8g5xxjUE7gv7hRnUu6sm9lhEdzTskDw5zjr0mh093/PZ1M0UYMCg/M6TZmz+mdrd3r0Yq97am6mdFACe2v2tNXryy2iLrVBred6W+g8tjQ==",
        "oth": null,
        "p": null,
        "q": null,
        "qi": null,
        "use": "sig",
        "x": null,
        "x5c": [],
        "x5t": "319D93355237260601A940A962991084B835681A",
        "x5tS256": null,
        "x5u": null,
        "y": null,
        "keySize": 2048,
        "hasPrivateKey": false,
        "cryptoProviderFactory": {
          "cryptoProviderCache": {},
          "customCryptoProvider": null,
          "cacheSignatureProviders": true
        }
      }
    ],
    "skipUnresolvedJsonWebKeys": true
  },
  "logoutSessionSupported": false,
  "opPolicyUri": null,
  "opTosUri": null,
  "registrationEndpoint": null,
  "requestObjectEncryptionAlgValuesSupported": [],
  "requestObjectEncryptionEncValuesSupported": [],
  "requestObjectSigningAlgValuesSupported": [],
  "requestParameterSupported": false,
  "requestUriParameterSupported": false,
  "requireRequestUriRegistration": false,
  "responseModesSupported": [],
  "responseTypesSupported": [],
  "serviceDocumentation": null,
  "scopesSupported": [],
  "signingKeys": [],
  "subjectTypesSupported": [],
  "tokenEndpoint": "https://localhost:4000/connect/authentication",
  "tokenEndpointAuthMethodsSupported": [],
  "tokenEndpointAuthSigningAlgValuesSupported": [],
  "uiLocalesSupported": [],
  "userInfoEndpoint": null,
  "userInfoEndpointEncryptionAlgValuesSupported": [],
  "userInfoEndpointEncryptionEncValuesSupported": [],
  "userInfoEndpointSigningAlgValuesSupported": []
}

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
clefermancommented, Aug 29, 2021

Stumbled upon this today and wrecked my head for a few hours until I finally retrieved the discovery document “manually”. I was sure I configured the JWT middleware correctly but it never hit my /keys endpoint. I inspected the url a dozen times, it was correct but it turns out it was a serialization issue…

I’ll just leave this chunk of code here

        [HttpGet]
        public IActionResult GetConfiguration(CancellationToken cancellationToken)
        {
            var requestedUrlBase = $"{Request.Scheme}://{Request.Host}/";

            var configuration = new OpenIdConnectConfiguration
            {
                Issuer = securitySettings.Issuer,
                TokenEndpoint = requestedUrlBase + "token",
                JwksUri = requestedUrlBase + "keys",
            };

            return Ok(configuration);
        }

I looked into the OkObjectResult class and it seems it’s using the System.Text.Json serializer. I tried forcing the controllers to use the Newtonsoft.Json one but with no success services.AddControllers().AddNewtonsoftJson();

Inheriting from the OpenIdConnectConfiguration class and adding the jwks_uri property as @RogerioWagner mentioned works like a charm.

Sorry for bumping this, but it still seems to be an issue. Here’s to hoping the next guy finds this before losing their minds like I almost did.

0reactions
brentschmaltzcommented, Nov 4, 2021

@RogerioWagner @cleferman @chwarr this item was fixed in 6.x. Please feel free to re-open if you see issues in 6.x.

Read more comments on GitHub >

github_iconTop Results From Across the Web

OpenIdConnectConfiguration Class
Gets a bool that determines if the 'acr_values_supported' (AcrValuesSupported) property should be serialized. This is used by Json.NET in order to conditionally ...
Read more >
How sensitive is the Google OpenID Discovery Document ...
The items in the document is pretty standardized but not every provider provides all the items. public class OpenIDSettings : IOpenIDSettings { ...
Read more >
Setting up your ASP.NET Core apps and services for Azure ...
Seems like the post back from the ADB2C tenant isn't able to serialize properly...is this a .net core dependency issue? ```info: Microsoft.
Read more >
Microsoft Authentication Library for .NET
Gets a bool that determines if the 'id_token_encryption_alg_values_supported' (IdTokenEncryptionAlgValuesSupported) property should be serialized.
Read more >
OpenID Connect | Kong Docs
OpenID Connect (1.0) plugin allows for integration with a third party identity provider (IdP) in a standardized way. This plugin can be used...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found