Closed mitchellgarner closed 3 years ago
Hi,
OpenIddict 3.0 comes with a dedicated validation stack that works with JWT and Data Protection access tokens. It uses a modern JWT stack and is natively compatible with ASP.NET 4.x via OWIN. Consider replacing the JWT/app.UseOAuthBearerAuthentication()
middleware by OpenIddict's validation middleware, as it's the recommended option in recent versions of OpenIddict.
We are updating to the latest version of OpenIdDict and are running into a challenge with one of our .net framework 4.6.1 web applications. This application uses authorization code flow to get the token from the openiddict idp. The mobile app also does this using the same application registration in openiddict. Mobile then attaches the access token to calls to the api back-end.
Authentication done by the web api calling to openiddict is successful, however calls from the mobile app result only in a 401 unauthorized.
I initially thought this was due to not including all required claims in the access token, however upon inspected the production system's token returned claims are the same.
I am under the impression validation within the api application may not be set correctly, but it does not look different than what I have found in documentation, and I haven't changed it from our current production version's settings.
Here is the configuration of our .net framework application's validation:
`var jwtFormat = new JwtFormat( new TokenValidationParameters { AuthenticationType = "Bearer", ValidIssuer = ConfigurationManager.AppSettings["ExternalAuth.SevanIdentity.Authority"], NameClaimType = "sub", RoleClaimType = System.Security.Claims.ClaimTypes.Role, ValidateIssuerSigningKey = true, ValidateAudience = false, IssuerSigningKey = new InMemorySymmetricSecurityKey( Encoding.UTF8.GetBytes(ConfigurationManager.AppSettings["ExternalAuth.SevanIdentity.JWTSigningKey"])) }) { TokenHandler = new CustomJwtSecurityTokenHandler(IocManager.Instance) };
and Authentication configuration:
`app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, LoginPath = new PathString("/Account/Index"), Provider = IocManager.Instance.Resolve(),
});
I am unsure if related, but since upgrading to openiddict 3.1 tokens are being labeled as "Invalid Signature" when put into jwt.io. Here is our current configuration for our IdP running openiddict.
`public void ConfigureServices(IServiceCollection services) { Logger.LogError("Starting");
Our implementation utilizes client credentials, implicit (w resource server & needed introspection), and code flow. (password of cert is removed)
Here is our Authorization controller as well. Each part of this seems to work except logout which i have not yet looked at.
`namespace SevanIdentity.Controllers { using System; using System.Collections.Generic; using System.Collections.Immutable; using System.Diagnostics; using System.Linq; using System.Security.Claims; using System.Threading.Tasks; using Microsoft.AspNetCore; using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http.Extensions; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Microsoft.IdentityModel.Tokens; using OpenIddict.Abstractions; using OpenIddict.Core; using OpenIddict.EntityFrameworkCore.Models; using OpenIddict.Server.AspNetCore; using SevanIdentity.Models; using SevanIdentity.Models.AuthorizationViewModel; using static OpenIddict.Abstractions.OpenIddictConstants;
}`
Any ideas would be appreciated. All other flows are working as expected after adding required rst entries to application permissions.