简体   繁体   English

.NET 核心 Web API 身份验证和 .NET 身份

[英].NET Core Web API Authentication and .NET Identity

I recently took over a .NET core MVC project and have to extend it with an API.我最近接手了一个 .NET 核心 MVC 项目,并且必须使用 API 对其进行扩展。 For authentication .NET core Identity is used.对于身份验证,使用 .NET 核心身份。 Coming from swift iOS/Mac development i started a demo project getting into it and doing some basic authentication.来自 swift iOS/Mac 开发,我开始了一个演示项目,进入其中并进行一些基本的身份验证。

When reading up on the identity on Microsofts Docs they foucs on WebApps.在阅读Microsoft 文档上的身份时,他们专注于 WebApps。 So my questions are:所以我的问题是:

  • Should i use identity for API authentication or is it just for internal identity Management and WebApp stuff?我应该使用身份进行 API 身份验证还是仅用于内部身份管理和 WebApp 的东西?
  • Does identity/.NET core already offer me jwt and eg basic auth to initially obtain the jwt or do i have to create a lot myself?身份/.NET 核心是否已经为我提供了 jwt 和例如基本身份验证以最初获得 jwt 还是我必须自己创建很多?

My Goal rn is to just create jwt-auth protected routes and to be able to get a jwt with a username and a password.我的目标是创建受 jwt-auth 保护的路由,并能够获得带有用户名和密码的 jwt。

ASP.NET Core Identity isn't suitable for guarding APIs, usage of other identity providers is directed by the Docs : ASP.NET 核心身份不适合保护 API,其他身份提供者的使用由文档指导:

ASP.NET Core Identity adds user interface (UI) login functionality to ASP.NET Core web apps. ASP.NET Core Identity 向 ASP.NET Core web 应用程序添加了用户界面 (UI) 登录功能。 To secure web APIs and SPAs, use one of the following :要保护 web API 和 SPA,请使用以下方法之一:

  • Azure Active Directory Azure 活动目录
  • Azure Active Directory B2C (Azure AD B2C) Azure Active Directory B2C (Azure AD B2C)
  • IdentityServer4身份服务器4

and as per the previous link:并根据上一个链接:

IdentityServer4 is an OpenID Connect and OAuth 2.0 framework for ASP.NET Core. IdentityServer4 是用于 ASP.NET 核心的 OpenID Connect 和 OAuth 2.0 框架。 IdentityServer4 enables the following security features: IdentityServer4 启用以下安全功能:

  • Authentication as a Service (AaaS)身份验证即服务 (AaaS)
  • Single sign-on/off (SSO) over multiple application types多种应用程序类型的单点登录/注销 (SSO)
  • Access control for APIs API 的访问控制
  • Federation Gateway联合网关

So you will need to go with IdentityServer4所以你需要 go 和IdentityServer4

You should use identity server4 for this.为此,您应该使用身份 server4。

Refer a simple example of identity server 4 to protect client with token.请参考身份服务器 4 的简单示例,以使用令牌保护客户端。

identity-server4 simple example identity-server4 简单示例

There are a lot more things you will have to understand refer identity server 4 official doc .您还需要了解更多内容,请参阅身份服务器 4 官方文档

Moreover you can also follow step by step identity server setup video tutorial .此外,您还可以按照分步身份服务器设置视频教程进行操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM