English 中文(简体)
蚊帐芯片:根据装入AddBearer Token的参数,产生 j。
原标题:.net core: generate jwt token based on parameters passed into AddBearerToken

当我考虑为网站APIC进行认证时,我看到以下进程:

您的服务:

services.AddAuthentication().AddJwtBearer(o =>
{
    o.TokenValidationParameters = new TokenValidationParameters
    { 
        IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(configuration["secrets"]))
    };
});

Next step all documentations I have seen talk about is: in order to generate the token, use some helper classes and pass the configurations such as secrets and issuer again. This never made much sense to me. Since the AddJwtBearer function has already taken in all configurations, isn t there a function as straightforward as httpContext.GenerateJwt(new Claims[]{}) that would generate the token? Why would we need to use so much boilerplate?

我自那以来就一直在寻找这样的职能。 NET 2.0。 我创立了一个新集团,以完成这项工作(我知道我所谈论的内容是可行和直截了当的)。 然而,NuGet公司不再工作。 NET 6.0。 我不想确定我的NuGet,而是想检查一下。 NET Core有一个清洁的解决方案,可以生成JWT信号。

问题回答

“AddJwtBearer tokenhandler”只是用于接收APIC信号的APIC。 没有任何逻辑可以产生《维也纳条约法公约》。 JWT 标的通常是由贵重供应商(如身份识别器)生成的。

产生你自己的象征的问题是签字,你必须通过公开签字,这是AddJwtBearer的关键,以便它能够接受JWT的象征。

If you want to generate your own token for testing, then there is a tool called user-jwts. Manage JSON Web Tokens in development with dotnet user-jwts

I also have a set of blog posts about the JWtBearer handler here: https://nestenius.se/2023/02/21/troubleshooting-jwtbearer-authentication-problems-in-asp-net-core/





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签