我目前正在使用 ASP.NET Core 2.1 中的 KnockoutJS SPA 模板,并且我设法实现了与 Angular 中的授权流程完全相同的授权流程:
https://fullstackmark.com/post/13/jwt-authentication-with-aspnet-core-2-web-api-angular-5-net-core-identity-and-facebook-login
正如您在他们的用户前端服务中看到的那样,基本上唯一检查用户是否在客户端登录是检查客户端本地存储中是否存在“auth_token”密钥:
https://github.com/mmacneil/AngularASPNETCore2WebApiAuth/blob/master/src/src/app/shared/services/user.service.ts
this.loggedIn = !!localStorage.getItem('auth_token');
// ?? not sure if this the best way to broadcast the status but seems to resolve issue on page refresh where auth status is lost in
// header component resulting in authed user nav links disappearing despite the fact user is still logged in
简而言之,任何人都可以打开浏览器本地存储并使用“auth_token”密钥插入一个随机字符串,他们将能够在 UI 中看到与管理员相关的所有内容(即使他们在 API 请求上会失败)。
有人可以为此建议更好的流程吗?还是在“打开”管理页面时向 API 发送“登录请求”的唯一选项?
PS 我对身份验证方案方面比较陌生,JWT 可能不应该用于客户端内容验证吗?
米琪卡哇伊
相关分类