简体   繁体   中英

When to get JWT token in ASP.NET Core SPA App

I have an ASP.NET Core app with React frontend and I'm trying to figure out when and how to get a JWT token .

I've already implemented the necessary backend work to produce and return a JWT but I'm not exactly sure when and how to get the token after user authentication.

I have a login page that uses social logins. Once social provider authenticates the user, the call comes back to my Callback() action method that receives the cookie from social network which is where I do my work to make sure the user is a registered user.

Currently, right at this point, I destroy the social cookie and create my own and do a redirect to the home page where the user simply downloads the JS files that include all the frontend React stuff.

Just not sure how to do a redirect while returning a JWT token in my Callback() method.

Once your user authenticates with the third-party social network, you should receive an access token. Your callback will need to pass that access token to your api to validate the token, check authorization for your app, and create a JWT token. So, this authentication method should receive an access token and return the JWT token in between your login and first call to the api in your React app. Your login front-end will need to store the JWT somewhere that your React front-end can retrieve it (local storage, session storage, or cookie). If your login and React app aren't on the same domain, then you will need to pass it in the request to the React entry point.

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