ASP.NET Web API 2 - How to implement OAuth2.0 for SPA applications

懵懂的女人 提交于 2020-01-06 07:07:18

问题


I am trying to implement WEB API 2 (for Single Page App, not as part of Visual Studio project) OAuth2.0 protocol. As per Which OAuth 2.0 flow should I use, using refresh tokens is not an option. However, I am not sure I understand Implicit Grant flow with eventual Silent Authentication.

Does Implicit Flow mean only issuing normal access tokens? In that case, how do we allow user to stay logged in for long time? How should Silent Authentication endpoint look like, what should it receive and return to client? Is using refresh token really an issue - most of people have their usernames / passwords saved in browser?


回答1:


Does Implicit Flow mean only issuing normal access tokens? Yes.

In that case, how do we allow user to stay logged in for long time? You can set timeout using "expires_in" parameter.

Refer for Complete Detail here: https://oauth2.thephpleague.com/authorization-server/implicit-grant/

How should Silent Authentication endpoint look like, what should it receive and return to client? Upon authentication of the user during login, the server sends & set the authentication key in the session/browser. So, during every page call, only authentication key is send to server. You shall find many examples of implementation online.

Is using refresh token really an issue - most of people have their usernames / passwords saved in browser? No, it's not an issue. If token expires, you can easily reissue token after authentication. Password & username is not saved in the browser. Only authentication key is stored.



来源:https://stackoverflow.com/questions/49646561/asp-net-web-api-2-how-to-implement-oauth2-0-for-spa-applications

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!