开发者可以使用 servicecomb-fence 给 servicecomb-java-chassis 微服务项目增加基于 OpenID Connect 的认证鉴权能力。
认证鉴权流程介绍
密码模式
- Client 输入用户名密码向 Authentication Server 请求 Token。
** HTTP Request **
POST http://localhost:9090/api/authentication-server/v1/oauth/token HTTP/1.1
Content-Type: application/x-www-form-urlencoded
grant_type=password&username=admin&password=changeMyPassword
-
Authentication Server 发送 Token 给 Client 。
-
Client 携带 Token 请求 Resource Server 。
** HTTP Request **
POST http://localhost:9090/api/resource-server/v1/auth/handler/adminSayHello?name=Hi HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Authorization: Bearer czZCaGRSa3F0MzpnWDFmQmF0M2JW
- Resource Server 返回对应的资源给 Client 。
开发 Authentication Server
Authentication Server 主要提供认证和授权等接口。
- 配置依赖
项目中引入
<dependency>
<groupId>org.apache.servicecomb.authentication</groupId>
<artifactId>authentication-server-api-endpoint</artifactId>
</dependency>
- 配置
Authentication Server 需要配置 PasswordEncoder、Signer、SignerVerifier、UserDetailsService 等