Using my client app with SS with my current settings, I don’t see any issues.
I use the IdentityJwtAuthProvider, the AuthSecret and my custom Auth Provider derived from IdentityCredentialsAuthProvider.
Tokens are generated and signature validated correctly. I access all my api and the built-in ones like /ui and /admin-ui ok.
I think it happened when I accessed the admin-ui with the AuthSecret but now I can’t reproduce… I am the only one using the app.
I can see this error in log a dozen of times at the same second.
Error in GetSession() when ApplyPreAuthenticateFilters
System.ArgumentException: IDX12723: Unable to decode the payload '[PII of type 'System.String' is hidden. For more details, see https://aka.ms/IdentityModel/PII.]' as Base64Url encoded string.
---> System.Text.Json.JsonException: IDX11022: Expecting json reader to be positioned on 'JsonTokenType.String', reader was positioned at: 'Number', Reading: 'System.IdentityModel.Tokens.Jwt.JwtPayload.jti', Position: '544', CurrentDepth: '1', BytesConsumed: '546'.
at Microsoft.IdentityModel.Tokens.Json.JsonSerializerPrimitives.ReadString(Utf8JsonReader& reader, String propertyName, String className, Boolean read)
at System.IdentityModel.Tokens.Jwt.JwtPayload.CreatePayload(Byte[] bytes, Int32 length)
at Microsoft.IdentityModel.Tokens.Base64UrlEncoding.Decode[T](String input, Int32 offset, Int32 length, Func`3 action)
at System.IdentityModel.Tokens.Jwt.JwtSecurityToken.DecodeJws(String payload)
--- End of inner exception stack trace ---
at System.IdentityModel.Tokens.Jwt.JwtSecurityToken.DecodeJws(String payload)
at System.IdentityModel.Tokens.Jwt.JwtSecurityToken.Decode(String[] tokenParts, String rawData)
at System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler.ReadJwtToken(String token)
at System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler.ValidateJWS(String token, TokenValidationParameters validationParameters, BaseConfiguration currentConfiguration, SecurityToken& signatureValidatedToken, ExceptionDispatchInfo& exceptionThrown)
--- End of stack trace from previous location ---
at System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler.ValidateToken(String token, JwtSecurityToken outerToken, TokenValidationParameters validationParameters, SecurityToken& signatureValidatedToken)
at ServiceStack.Auth.IdentityJwtAuthProvider`3.PreAuthenticateAsync(IRequest req, IResponse res) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack.Extensions/Auth/IdentityJwtAuthProvider.cs:line 321
at ServiceStack.ServiceStackHost.ApplyPreAuthenticateFiltersAsync(IRequest httpReq, IResponse httpRes)
at ServiceStack.ServiceExtensions.GetSessionInternalAsync(IRequest httpReq, Boolean reload, Boolean async, CancellationToken token) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack/ServiceExtensions.cs:line 254
Do I miss something?
services.AddSingleton<IPostConfigureOptions<JwtBearerOptions>, JwtBearerPostConfigureOptions>();
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{
options.SaveToken = true;
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuerSigningKey = true,
ValidIssuer = builder.Configuration["JwtBearer:ValidIssuer"],
ValidAudience = builder.Configuration["JwtBearer:ValidAudience"]
};
});
public class JwtBearerPostConfigureOptions(ILogger<JwtBearerPostConfigureOptions> logger)
: IPostConfigureOptions<JwtBearerOptions>
{
public void PostConfigure(string? name, JwtBearerOptions options)
{
options.TokenValidationParameters.IssuerSigningKey =new RsaSecurityKey(SecurityContext.GetCertificate()?.GetRSAPrivateKey());
logger.LogDebug("IssuerSigningKey is set to RsaSecurityKey from SecurityContext certificate private key.");
}
}
var auth = new AuthFeature(IdentityAuth.For<ApplicationUser>(options =>
{
options.SessionFactory = () => new PEUserSession();
options.JwtAuth(x =>
{
x.IncludeConvertSessionToTokenService = true;
x.RequireSecureConnection = true;
x.HashAlgorithm = SecurityAlgorithms.RsaSha256;;
x.ExpireTokensIn = TimeSpan.FromDays(365 * 25);
x.RestoreSessionFromState = false;
x.PersistSession = true;
x.OnSessionCreated = (session, claims, req) =>
{
//...
};
x.OnTokenCreated = (req, user, claims) =>
{//...
});
}));
Is there a way to prevent this other than filter out these entries from log?