[英]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.