假設這個問題與How to authorize SignalR Core Hub method with JWT有關,我不建議你自己解密由OpenIddict發出的不透明訪問令牌。
如果你真的想自己做,你可以手動實例化一個TicketDataFormat
實例與OpenIddict使用ASP.NET核心數據保護「的宗旨字符串」:
// Resolve the data protection provider from the DI container.
// Depending on where this snippet is used, you must be able
// to directly use constructor injection (e.g in a controller).
var provider = app.ApplicationServices.GetRequiredService<IDataProtectionProvider>();
var protector = provider.CreateProtector(
nameof(OpenIdConnectServerHandler),
nameof(OpenIdConnectServerOptions.AccessTokenFormat),
OpenIdConnectServerDefaults.AuthenticationScheme);
var format = new TicketDataFormat(protector);
// If the access token is not malformed, a non-null value
// is returned. Note that you'll have to manually validate
// the expiration date and the audience of the ticket.
var ticket = format.Unprotect("your access token");