0

I am getting following exception. I have use post method to get token using service principal Message = "IDX10708: 'System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler' cannot read this string

I am generating access token using ""https://login.microsoftonline.com/{TenantId}/oauth2/token" and trying to validate that

            SecurityToken securityToken;
            JwtSecurityTokenHandler handler = new JwtSecurityTokenHandler();
            IConfigurationManager<OpenIdConnectConfiguration> configurationManager =
                   new ConfigurationManager<OpenIdConnectConfiguration>(
                       $"https://login.microsoftonline.com/{tenantId}/.well-known/openid-configuration",
                       new OpenIdConnectConfigurationRetriever());

            OpenIdConnectConfiguration openIdConfig = await configurationManager.GetConfigurationAsync(CancellationToken.None);
            TokenValidationParameters validationParameters = new TokenValidationParameters()
            {
                ValidateLifetime = true,
                IssuerSigningKeys = openIdConfig.SigningKeys,
                ValidateIssuerSigningKey = true,
                RequireSignedTokens = true

            };

            var userClaims = handler.ValidateToken(token, validationParameters, out securityToken);
            return userClaims.Claims.Where(claim => claim.Type == "appid").FirstOrDefault().Value;

I am getting exception while validating

Agrawal Shraddha
  • 734
  • 1
  • 5
  • 18

1 Answers1

0

Please try to validate the code by putting try/catch block and review the claims value in the debugger e.g. uniquer_name etc

you can follow this thread for more clarity:-

When is JWTSecurityTokenHandler.ValidateToken() actually valid?

Hope it helps.

Mohit Verma
  • 5,140
  • 2
  • 12
  • 27