IdentityServer4
IdentityServer4实现了OpenID Connect 和Oauth 2.0 protocol协议的ASP.NET Core框架。
Notes:IdentityServer4推出了一个新公司,Duende IdentityServer,IdentityServer4会继续维护到2022年11月。
• Authentication as a service
集中管理应用(web,native,mobile,services)的登录和工作流,IdentityServer是官方认证的实现了OpenID Connect。
• Single Sign-on / Sign-out
通过多种应用类型进行单点登录(登出)
• Access Control for APIs
为多种类型的客户端颁发access token,例如:server to server,web application,SPAs和native/mobile apps。
• Federation Gateway
支持像Azure Active Directory,Google, Facebook等外部身份提供商,这对于你的应用程序来说可以不用关心是如何连接到外部身份提供商的。
• Focus on Customization
支持自定义。因为IdentityServer4是一个框架不是一个封闭的产品,你可以通过写code来作用于你的应用。
• Mature Open Source
• Free and Commercial Support
现代应用程序工作流(大部分)
常见的交互方式有以下几种
通常项目中都需要实现认证(Authentication)和授权(Authorization)来保护受保护的资源,这些Security function会设计在外围来阻止重复性访问 认证/授权 服务器带来的性能损耗。
重构上面的application,支持Security token service,结构图如下:
Authentication(认证)
认证:应用程序需要知道(当前登录)用户是谁,用户能访问哪些资源,比较常见的就是(web applications),当然本地和JS-based的应用程序也需要认证身份。常见的认证协议(protocol):SAML2p,WS-Federation 和OpenID Connect.
Authorization(授权)
授权:授予用户某些权限通过应用程序访问受保护资源。
OpenID Connect & OAuth 2.0
OpenID认证
OAuth授权
IdentityServer4就是两者的实现,并且优化解决了现在mobile,native和web applications的安全问题。实际上OpenID是OAuth 2.0上的扩展。
Terminology(术语)
Identity Token:identity token代表认证返回的结果,包含少量identity信息。
Endpoint
GET /connect/authorize? client_id=client1& scope=openid email api1& response_type=id_token token& redirect_uri=https://myapp/callback& state=abc& nonce=xyz
POST /connect/token CONTENT-TYPE application/x-www-form-urlencoded client_id=client1& client_secret=secret& grant_type=authorization_code& code=hdh922& redirect_uri=https://myapp.com/callback
GET /connect/userinfo Authorization: Bearer <access_token>
HTTP/1.1 200 OK Content-Type: application/json { "sub": "248289761001", "name": "Bob Smith", "given_name": "Bob", "family_name": "Smith", "role": [ "user", "admin" ] }
最后总结下IdentityServer能干什么: