官网地址:
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.com | GET |
页面跳转到登录页面:
输入用户名密码后:
点击allow后,浏览器返回code:
b./oauth2.0/accessToken方法介绍
浏览器返回token:
3./oauth2.0/profile方法介绍
请求地址 | 请求方法 |
http://localhost:8080/cas/oauth2.0/profile?access_token=AT-2-dAz4wPm1LxVRu4IDjHyMq3WWsGaXrfsQ&expires_in=28800 | GET |
浏览器返回结果信息: