cas5.x接收oauth2.0协议认证

官网地址:

https://apereo.github.io/cas/5.3.x/installation/OAuth-OpenId-Authentication.html 
https://apereo.github.io/cas/5.3.x/installation/Configuration-Properties.html#oauth2
 

1.pom添加依赖

<dependency>
    <groupId>org.apereo.cas</groupId>
    <artifactId>cas-server-support-oauth-webflow</artifactId>
    <version>${cas.version}</version>
</dependency>

2.application.properties添加参数

############oauth###########
cas.server.name=http://localhost:8080
cas.server.prefix=http://localhost:8080/cas
cas.authn.oauth.refreshToken.timeToKillInSeconds=2592000
cas.authn.oauth.code.timeToKillInSeconds=30
cas.authn.oauth.code.numberOfUses=1
cas.authn.oauth.accessToken.releaseProtocolAttributes=true
cas.authn.oauth.accessToken.timeToKillInSeconds=7200
cas.authn.oauth.accessToken.maxTimeToLiveInSeconds=28800
cas.authn.oauth.grants.resourceOwner.requireServiceHeader=true
cas.authn.oauth.userProfileViewType=NESTED

3.添加json文件

在路径如下:

文件说明OAuthService-(内容id)。

json内容如下:

{
"@class" : "org.apereo.cas.support.oauth.services.OAuthRegisteredService",
"clientId": "100001",
"clientSecret": "123456",
"serviceId" : "^(https|http|imaps)://.*",
"name" : "OAuthService",
"id" : 1000001
}

4.启动应用

测试共三个接口:

a./oauth2.0/authorize方法介绍

请求地址请求方法
http://localhost:8080/cas/oauth2.0/authorize?response_type=code&client_id=100001&redirect_uri=http://www.baidu.comGET

页面跳转到登录页面:

输入用户名密码后:

点击allow后,浏览器返回code:

b./oauth2.0/accessToken方法介绍

请求地址请求方法
http://localhost:8080/cas/oauth2.0/accessToken?grant_type=authorization_code&client_id=100001&client_secret=123456&code=OC-6-9fyi8ATtmB3VLpHRNEhV-aQ91eKX9Zhy&redirect_uri=http://www.baidu.comGET

 

浏览器返回token:

3./oauth2.0/profile方法介绍

请求地址请求方法
http://localhost:8080/cas/oauth2.0/profile?access_token=AT-2-dAz4wPm1LxVRu4IDjHyMq3WWsGaXrfsQ&expires_in=28800GET

浏览器返回结果信息:

 

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值