【问题标题】:Authentication between Projects in .net core.net core 中项目之间的身份验证
【发布时间】:2019-05-19 08:38:24
【问题描述】:

我正在尝试构建多层网络应用程序,用户可以通过 google auth 或 ldap acc 访问。

它有:

  • 核心层(库 - 所有模型)
  • 数据访问层(库)
  • 业务逻辑层(库)
  • API 层(.Net Core Web API)
  • Web 层(.Net Core MVC 项目)

当用户登录网站时,我必须使用 MVC 和 API 相同的身份验证。

我应该使用 aspnet 身份登录(使用自动生成的用户 db),如何将身份验证传递给 API 项目?

或者有没有办法当 google aut 或 ldap 登录成功时,我可以创建 Bearer 令牌(或类似的东西)并将其用于 MVC 和 API 项目作为经过身份验证的登录?

PS:我在 .net core 2.2 上工作

【问题讨论】:

  • Or is there a way when google aut or ldap login is successful then I can create Bearer token (or something like that) and use it both MVC and API projects as authenticated login? -> 这确实是正确的做法

标签: c# authentication asp.net-web-api model-view-controller asp.net-core


【解决方案1】:

您需要某种方式在两人之间共享会话。为防止用户自行访问您的 API,请考虑创建一个您的 MVC 运行的“用户”,并仅使用您的 api 对该用户进行身份验证。

这样

用户 -> MVC -> API

【讨论】:

    猜你喜欢
    • 2020-06-05
    • 2020-05-18
    • 2019-08-17
    • 2019-01-28
    • 1970-01-01
    • 2018-12-17
    • 2020-10-28
    • 2020-10-15
    • 1970-01-01
    相关资源
    最近更新 更多