有人可以在另一台服务器上使用我的服务吗? Angular 9

Can somebody use my service since another server? Angular 9

我正在学习 angular 并且对安全性有疑问。我正在使用 angular 9.

有人可以使用我的服务吗?

我这么说是因为我担心其他人使用服务 url 访问我的数据库。

例如: 这是我在 asp.net

中的控制器
[HttpGet]
    [Route("api/Producto/listarProductos")]
    public IEnumerable<ProductoCLS> listarProductos()
    {
        using (BDRestauranteContext bd=new BDRestauranteContext())
        {
            List<ProductoCLS> lista = (from producto in bd.Producto
                                       join categoria in bd.Categoria
                                       on producto.Iidcategoria equals
                                       categoria.Iidcategoria
                                       where producto.Bhabilitado == 1
                                       select new ProductoCLS
                                       {
                                           idproducto = producto.Iidproducto,
                                           nombre = producto.Nombre,
                                           precio =(Decimal)producto.Precio,
                                           stock =(int) producto.Stock,
                                           nombreCategoria = categoria.Nombre 
                                       }).ToList();

            return lista;

        }
    }

这是我在angular的服务:

    public getProducto() {
    return this.http.get(this.urlBase + 'api/Producto/listarProductos');
  }

您需要向客户端和服务器端添加授权逻辑。

来自Angular侧
https://jasonwatmore.com/post/2018/09/07/angular-6-basic-http-authentication-tutorial-example

来自 Dot Net Core 方面
https://jasonwatmore.com/post/2018/09/08/aspnet-core-21-basic-authentication-tutorial-with-example-api


登录后 - 您将获得 'authentication-token'。您所有后续的 HTTP 请求都将有一个 'Authorization' header,并且在服务器端 - 您需要对其进行配置,以便它只接受那些具有授权 headers 的 http 请求。

您可以使用多种不同的身份验证方法,例如 Azure AD 身份验证、Facebook、Google、github 等