热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

如何保护我的AngularJS和WebApi应用程序-HowtosecuremyAngularJSandWebApiapplication

IamusingAngularJSwithASP.NETWebApiserverside.Seemstomelikeauthenticationhasnowbecom

I am using AngularJS with ASP.NET Web Api server side. Seems to me like authentication has now become a breeze? Or is this too good to be true?

我在ASP.NET Web Api服务器端使用AngularJS。对我来说,身份验证现在变得轻而易举?或者这太好了,不是真的吗?

So I'm thinking of using the Web Api's "Individual User Accounts" authentication. And I am thinking that is all I need. As long as every request is authenticated and noone can get any data they shouldn't I shouldn't need to do much more right?

所以我正在考虑使用Web Api的“个人用户帐户”身份验证。而我认为这就是我所需要的。只要每个请求都经过身份验证,没有人可以获得任何数据,我就不应该做更多的权利吗?

Or am I missing some key security fundamentals?

或者我错过了一些关键的安全基础知识?

2 个解决方案

#1


15  

When it comes to securing the API you have two main approaches

在保护API方面,您有两种主要方法

  1. COOKIE based approach. This is the traditional way, where you use the standard form to authenticate the user and then set the form authentication COOKIE. All unauthorized request take the user to login page. If your API is always supported by UI front end to do login this method with work.
  2. 基于COOKIE的方法。这是传统方式,您使用标准表单对用户进行身份验证,然后设置表单身份验证COOKIE。所有未经授权的请求都会将用户带到登录页面如果UI前端始终支持您的API,请使用work登录此方法。
  3. Second is using the authorization token in the header of the request. Once the user is authenticated he get a auth token, which he has to attach to every subsequent request in the Authorize HTTP header. Learn more about it here Individual Accounts in ASP.NET Web API . The advantage here is that you can expose your API without requiring a login page.
  4. 其次是在请求的标头中使用授权令牌。一旦用户通过身份验证,他就会获得一个身份验证令牌,他必须将其附加到Authorize HTTP标头中的每个后续请求。在ASP.NET Web API中了解有关它的更多信息。这里的优点是您可以在不需要登录页面的情况下公开您的API。

But remember when using the second approach, the auth token has to be stored on the client side as all subsequent request require this token. Look at this blog post COOKIEs vs Tokens. Getting auth right with Angular.JS to understand how to work with token.

但请记住,在使用第二种方法时,身份验证令牌必须存储在客户端,因为所有后续请求都需要此令牌。看看这篇博客文章COOKIEs vs Tokens。使用Angular.JS获得认证,以了解如何使用令牌。

Hope it helps.

希望能帮助到你。

#2


9  

Here's a great article about using Angular JS with WebAPI 2.0 token based authentication.

这是一篇关于使用Angular JS和基于WebAPI 2.0令牌的身份验证的精彩文章。

http://bitoftech.net/2014/06/01/token-based-authentication-asp-net-web-api-2-owin-asp-net-identity/

http://bitoftech.net/2014/06/01/token-based-authentication-asp-net-web-api-2-owin-asp-net-identity/


推荐阅读
  • 一、域名解析记录说明记录类型A:用来指定域名的IPv4地址(如:8.8.8.8),如果需要将域名指向一个IP ... [详细]
  • 作业迁移
    背景:数据库服务器更换,1、数据库迁移(BACKUPRESTORE);2、数据库登录名用户迁移(注意孤立用户);3、作业迁移数据库迁移,备份数据库、拷贝备份文件到新服务器,还原数据 ... [详细]
  • post请求,携带json对象参数模拟获取tokenpublicstaticStringgetToken()throwsIOException{创建连接CloseableHttp ... [详细]
  • Xamarin.Android-用ZXing实现二维码扫描以及连续扫描
    一、前言本文的内容有两个基础:ZXing.Net和ZXing.Net.MobileZXing.Net:ZXing的C#实现,主要封装了各种二维码的编码、解码等跨平台的算法ZXing.Net.Mo ... [详细]
  • FroggerTimeLimit:1000MSMemoryLimit:65536KTotalSubmissions:32257Accepted:10396DescriptionFr ... [详细]
  • ajax 跨域webapi 最简单的demo(只介绍Get)
    这几天遇到一个nodejs的项目,使用VSCode开发,需要连接数据库的,但是用nodejs连接数据库比较繁琐,需要安装很多 ... [详细]
  • NSSROUND#8[Basic]
    文章目录一、[NSSRound#8Basic]MyDoor二、[NSSRound#8Basic]Upload_gogoggo三、[NSSRound#8Basic]MyPage四、[ ... [详细]
  • CAS介绍CAS(CentralAuthenticationService),是耶鲁大学开发的单点登录系统(SSO,singlesign-on),应用广泛,具有独立于平台的,易于理解,支持代 ... [详细]
  • 本文是《开发你的WordPress主题框架》专题的第10篇,共10篇:为你的WordPress主题框架添加动作挂钩WordPress主题框架是如何工作的决定如何开发你的WordPress主题框架为你的WordPress主题框架建立起始文件为你的Wo ... [详细]
  • Iamworkingonawindowsapplication.IneedtosimulateSession(thatwehaveinawebapp)inthe ... [详细]
  • 缓存的重要性就不用再强调了,@OutputCache给我们提供了一种声明的方式(对应的还有编程的方式)来控制页面和用户控件的缓存策略,这是一种最简单直接的网站优化方式。还是先来过一遍@ ... [详细]
  • 这是一份详细 & 清晰的计算机网络基础 学习指南
    前言计算机网络基础该是程序猿需掌握的知识,但往往会被忽略今天,我将献上一份详细&清晰的计算机网络基础学习指南,涵盖TCPUDP协议、Http协议、Socket等,希望你们会喜欢。目 ... [详细]
  • 如何配置mysql双主_MySQL双主配置_MySQL
    准备环境:服务器操作系统为RHEL6.4x86_64,为最小化安装。主机A和主机B均关闭防火墙和SELINUX,IP地址分别为192.168.131.1 ... [详细]
  • 使用ffmpeg进行视频格式转换的简单例子2006-12-1623:12主要参考FFMPEG里面的apiexample.c以及output_example.c编写intmain(in ... [详细]
  • linux 修改root密码_Linux强制用户首次登陆修改密码
    一个执着于技术的公众号地方前言Linux强制用户首次登陆修改密码,这应该是RHCE认证中用户管理部分,属于很基础的内容了。可是我忘记了,所 ... [详细]
author-avatar
爱啊诗的孩子
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有