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添加依赖


    org.apereo.cas
    cas-server-support-oauth-webflow
    ${cas.version}

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文件

在路径如下:

cas5.x接收oauth2.0协议认证_第1张图片

文件说明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

页面跳转到登录页面:

cas5.x接收oauth2.0协议认证_第2张图片

输入用户名密码后:

cas5.x接收oauth2.0协议认证_第3张图片

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

cas5.x接收oauth2.0协议认证_第4张图片

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.com GET

 

浏览器返回token:

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

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

浏览器返回结果信息:

cas5.x接收oauth2.0协议认证_第5张图片

 

你可能感兴趣的:(理论,cas)