简体   繁体   English

如何使用.Net Core cookie中间件ticketdataformat将Jwt令牌从Api保存到C#中的cookie

[英]How to save Jwt token from Api to cookie in c# using .Net Core cookie middleware ticketdataformat

I am learning .net core jwt, writing my own Api and consumed by MVC front end using c#, they will be hosted in the same domain, but different subdomain 我正在学习.net核心jwt,编写我自己的Api并由使用c#的MVC前端使用,它们将托管在相同的域中,但位于不同的子域中

I have alredy build .Net core Api returning a Jwt token using examples and tutorials from the internet, so the back end (Api coding) is done. 我已经构建了.Net核心Api,使用来自互联网的示例和教程返回了Jwt令牌,因此完成了后端(Api编码)。 It already validates token by cookie or by header. 它已经通过cookie或标头验证令牌。

After the GetToken Api call, I want to store this token in httpcookie cookie (not accessible by javscript) in .Net core MVC front end, using .Net core cookie middleware to do it. 在GetToken Api调用之后,我想使用.Net核心cookie中间件来将此令牌存储在.Net核心MVC前端的httpcookie cookie中(无法通过javscript访问)。 What is the best way to do it? 最好的方法是什么?

I am aware TicketDataFormat is the clue? 我知道TicketDataFormat是线索吗? How should I do it so that it reads the jwt token from the Api, and stored it exactly the same in the mvc front end? 我应该如何做,以便它从Api读取jwt令牌,并将其完全相同地存储在mvc前端中?

I would like the answer in c#, not javascript, since I already stated that this is a httponly cookie, and not accessible by javascript. 我想用c#而不是javascript来回答,因为我已经说过这是一个httponly cookie,不能被javascript访问。

I end up just use Response.Append(cookie) to add a token there. 我最后只是使用Response.Append(cookie)在此处添加令牌。 It is not dependent on the web site cookiemiddleware 它不依赖于网站cookiemiddleware

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 cookie 中存储 JWT 令牌后如何打破该 cookie 并在 ASP.NET Core 3.1 中获取信息 - After store JWT token in cookie how to break that cookie and get information in ASP.NET Core 3.1 .Net Core 2.1 Web API 同时使用 JWT 和 JWT Cookie - .Net Core 2.1 Web API using JWT and JWT Cookie at the same time 如何在Asp.NET Core WEB API中使用.Net(C#)在有效载荷中使用自定义JSON声明创建JWT令牌 - How to create a JWT token with custom JSON claims in Payload using .Net (C#) in Asp.NET Core WEB API 在 ASP.NET Core 中,从 Cookie 而不是 Headers 中读取 JWT 令牌 - In ASP.NET Core read JWT token from Cookie instead of Headers 在C#.NET中保存Cookie的最佳方法? - Best way to save cookie in C# .NET? .NET Core API-中间件是否在标头中设置了JWT承载令牌? - .NET Core API - does the middleware set the JWT bearer token in the header? 使用 cookie 身份验证的 ASP.NET Core 2.0 自定义中间件 - ASP.NET Core 2.0 custom middleware using cookie authentication 如何使用 C# ASP.Net Core 3.1 在服务器端检查 cookie 选项 - How to check cookie options on server side using C# ASP.Net Core 3.1 如何使用 JWT + HttpOnly Cookie 正确刷新令牌? - How to properly refresh a token using JWT + HttpOnly Cookie? 使用.Net Core C#从Microsoft验证JWT - Validate JWT from Microsoft using .Net Core C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM