简体   繁体   中英

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

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. It already validates token by cookie or by header.

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. What is the best way to do it?

I am aware TicketDataFormat is the clue? 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?

I would like the answer in c#, not javascript, since I already stated that this is a httponly cookie, and not accessible by javascript.

I end up just use Response.Append(cookie) to add a token there. It is not dependent on the web site cookiemiddleware

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM