前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Apereo CAS(五)支持OAuth2

Apereo CAS(五)支持OAuth2

作者头像
dhyuan
发布2022-11-08 12:54:13
1.2K0
发布2022-11-08 12:54:13
举报
文章被收录于专栏:响应式编程响应式编程

Apereo CAS 通过使用bridge模式来支持多个协议:CAS、SAML2、OAuth2、OpenID Connect等。 CAS可部署软件包中已经包含了可以使用SAML2、OAuth2等协议的plugin/bridges/modules,这些plugins模块都是和CAS通信。可参考:https://apereo.github.io/cas/6.5.x/protocol/Protocol-Overview.html。

The right-hand side of that equation is always CAS when you consider, as an example, the following authentication flow with an OAuth2-enabled client application:

  1. The CAS deployment has turned on the OAuth2 plugin.
  2. An OAuth2 authorization request is submitted to the relevant CAS endpoint.
  3. The OAuth2 plugin verifies the request and translates it to a CAS authentication request!
  4. The authentication request is routed to the relevant CAS login endpoint.
  5. User authenticates and CAS routes the flow back to the OAuth2 plugin, having issued a service ticket for the plugin.
  6. The OAuth2 plugin attempts to validate that ticket to retrieve the necessary user profile and attributes.
  7. The OAuth2 plugin then proceeds to issue the right OAuth2 response by translating and transforming the profile and validated assertions into what the client application may need.

1. 添加依赖库

代码语言:javascript
复制
implementation "org.apereo.cas:cas-server-support-oauth-webflow"

2. Enable Actuator Endpoints (Optional)

添加依赖,并设置开放oauthd的actuator端点。

代码语言:javascript
复制
implementation "org.apereo.cas:cas-server-support-reports"

management.endpoint.oauthTokens.enabled=true
management.endpoints.web.exposure.include=oauthTokens
cas.monitor.endpoints.endpoint.oauthTokens.access=PERMIT

通过访问 https://localhost:8443/cas/actuator/ 应该可以看到OAuth相关endpoints。

3. 定义一个OAuth Client

可以通过设置

代码语言:javascript
复制
cas.service-registry.json.location=classpath:/services
cas.service-registry.core.init-from-json=true

在 cas-overlay-template的 resources/services 下定义文件 OAuth2DemoClient-2001.json 包含以下内容来把这个OAuth2 Client ‘OAuth2DemoClient’ 自动导入到MongoDB 的 cas_serviceregistry collection。

代码语言:javascript
复制
{
  "@class" : "org.apereo.cas.support.oauth.services.OAuthRegisteredService",
  "clientId": "oauth2DemoClientID",
  "clientSecret": "clientSecret",
  "serviceId" : "^(https|imaps)://<redirect-uri>.*",
  "name" : "OAuth2DemoClient",
  "id" : 2001,
  "supportedGrantTypes": [ "java.util.HashSet", [ "password", "authorization_code", "client_credentials", "refresh_token"] ],
  "supportedResponseTypes": [ "java.util.HashSet", [ "token", "code", "device_code"] ]
}

grant是获得AccessToken的方式/方法,这篇文章对此进行了详细介绍:https://alexbilbie.com/guide-to-oauth-2-grants/。

4. 重启、查看

运行 ./gradlew clean copyCasConfiguration build run 后,查看 db.getCollection('cas_serviceregistry').find({}) 应该可以看到id为2001的 OAutho client定义。

通过CAS Management UI也可以看到刚刚添加的‘OAuth2DemoClient’:

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2022-09-30,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 响应式编程 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 1. 添加依赖库
  • 2. Enable Actuator Endpoints (Optional)
  • 3. 定义一个OAuth Client
  • 4. 重启、查看
相关产品与服务
访问管理
访问管理(Cloud Access Management,CAM)可以帮助您安全、便捷地管理对腾讯云服务和资源的访问。您可以使用CAM创建子用户、用户组和角色,并通过策略控制其访问范围。CAM支持用户和角色SSO能力,您可以根据具体管理场景针对性设置企业内用户和腾讯云的互通能力。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档