# 集成第三方登录认证
# OAuth2集成方案
AFCenter提供了默认的基于(授权码模式)OAuth2-Client实现,只需要稍加配置即可使用,如果认证服务器有特殊需求可在此基础上进行修改或者参照去实现就行。
默认实现
后端配置:
#开启oauth2-sso开关,默认为false
afc.sso.oauth2.enable=true
#授权地址
afc.sso.oauth2.authorize-url=http://localhost:1111/oauth/authorize
#获取token地址
afc.sso.oauth2.token-url=http://localhost:1111/oauth/token
#clientid
afc.sso.oauth2.client-id=xxx
#clientSecret
afc.sso.oauth2.client-secret=$2a$10$is2AxEqDRjwUNM2sxcxxxxx
#认证中心,认证成功之后携带code参数跳转afcenter的地址,这里的ip和端口是afcenter的后端地址,路由是一个无用的虚拟路由保证不是白名单路由即可,只做跳转使用
afc.sso.oauth2.redirect-url=http://localhost:28083/token
#afcenter的登录地址
afc.sso.oauth2.login-url=http://localhost:28083/#/login
#获取用户信息的地址
afc.sso.oauth2.userinfo-url=http://localhost:1111/user
#如果获取的用户信息是json对象,映射关系是某个属性,则填写属性名称,否则默认返回的数据就是映射关系值,例如返回的userId
afc.sso.oauth2.user-key=username
#使用code获取access_token时,如果直接返回值,则无需配置,返回的是json对象,需要配置access_token属性名称
afc.sso.oauth2.access-token-key=access_token
AFCenter和微应用使用oauth2-sso时都需要配置这个属性,其中微应用的redirect-url和login-url都是AFCenter的地址
自定义实现
如果默认实现不满足需求,比如认证服务器的所有接口都是post请求(默认的获取token的接口是post请求,获取用户信息的是get请求),则可以继承
com.primeton.gocom.afcenter.common.oauth2.DefaultOauth2ClientServiceImpl,
重写对应的方法,或者参考该类,实现
com.primeton.gocom.afcenter.api.oauth.IOauthClientService
接口,重新实现自己的认证逻辑。实现完成后,确保该实现可以被spring的ioc容器管理即可。
注意:afc.sso.oauth2.enable配置是必须的,如果重新实现认证逻辑并且定义配置,则默认配置其他属性不需要配置。重新定义参数后,参考
com.primeton.gocom.afcenter.sdk.SdkDefaultOauth2ClientServiceImpl
实现,完成微应用的认证重定向逻辑。
前端配置:
如果获取到token,也可以直接访问前端地址后添加Authorization参数 http://localhost:8000?Authorization={你的token}
# CAS集成方案
后端集成说明
文件位置:config/application-afc.properties
# cas sso
# 是否启用cas
afc.sso.cas.enable=true
# ticket校验url
afc.sso.cas.server-validate-url=https://127.0.0.1:8443/sso-server/serviceValidate
# 代理回调URL(可以没有)
afc.sso.cas.server-proxy-callback-url=
前端说明
1、config/app-config.json配置文件
# 是否启用sso登陆
"loginType": 'sso',
# sso登录url
"ssoLoginUrl": "https://127.0.0.1:8443/sso-server/login",
# sso登出url
"ssoLogoutUrl": "https://127.0.0.1:8443/default/loginout",
2、nginx配置
# 部署到nginx 服务器,修改nginx.conf添加配置,告诉afc已经登出
location / {
if ($request_method ~ ^(POST)$ ) {
proxy_pass http://127.0.0.1:13083;
}
}
# 集成企业微信
在AFCenter中,像企业微信、钉钉这些第三方认证可以配置多个,供用户登录时选择不同生态。集成时需要在AFCenter的组织权限中心-组织管理-机构管理-员工管理中给员工的详细信息中配置员工的电话(非工作电话),这个电话要和员工的第三方系统中使用的电话号码相同。
**注意:**如果只配置一种三方认证,且默认只使用第三方生态进行登录AFCenter时,可以配置afc.thrid-party.global-redirect.enable=true(默认是false),这样未认证时访问AFCenter,平台会直接跳转第三方登录入口。
AFCenter集成企业微信配置(application.properties中配置)
afc.third-party.wechat.enable=true afc.third-party.wechat.crop-id= afc.third-party.wechat.agent-id= afc.third-party.wechat.secret= afc.third-party.wechat.redirect-uri=http://PC端域名端口/#/login afc.third-party.wechat.mobile-redirect-uri=http://移动端域名端口/#/login # 可选配置 afc.third-party.wechat.compatible-2-solutions=false
afc.third-party.wechat.enable配置为true即开启企业微信集成
afc.third-party.wechat.crop-id是企业的CorpID、afc.third-party.wechat.agent-id是应用的id、afc.third-party.wechat.secret是应用的密钥,在企业微信的后台管理功能中可以查询到
afc.third-party.wechat.redirect-uri是PC端前端的域名和端口(需要在企业微信的应用管理中开启企业微信授权登录,并配置Web网页授权回调域)
afc.third-party.wechat.mobile-redirect-uri是移动端前端的域名和端口(此域名需要在企业微信中配置可信回调域)
afc.third-party.wechat.compatible-2-solutions是一个可选配置,默认是false,此配置如果设置为true则不使用手机号进行用户身份认证,改用企业微信中的userId进行身份认证,注意,userId需要跟AFCenter中的员工编码一致,需要手动提前配置。
企业微信中配置afc移动端首页时需要增加type=weixin参数,例如:http://localhost:81/#/login?type=weixin
# 集成钉钉
公共说明参考集成企业微信。
AFCenter集成钉钉配置(application.properties中配置)
afc.third-party.ding.enable=false afc.third-party.ding.app-key= afc.third-party.ding.secret= afc.third-party.ding.agent-id= afc.third-party.ding.redirect-uri=http://域名和端口/#/login
afc.third-party.ding.enable配置为true即开启钉钉集成
afc.third-party.ding.app-key是钉钉中应用的唯一标识、afc.third-party.ding.secret是钉钉中应用的密钥、afc.third-party.ding.agent-id是微应用的agent_id
afc.third-party.ding.redirect-uri是PC端集成钉钉时的前端域名和端口,移动端的配置在钉钉中进行配置
集成钉钉时还需要给该应用下的组织机构人员在钉钉中配置权限,需要个人手机号信息、通讯录个人信息读权限、邮箱等个人信息、企业员工手机号信息、成员信息读权限、根据手机号姓名获取成员信息的接口访问权限、企业微应用后台免登接口的访问权限、调用OpenApp专有API时需要具备的权限。具备以上这些权限才能保证AFCenter中钉钉集成相关功能可用。
钉钉中配置afc移动端首页时需要增加type=dingding参数和corpId=$CORPID$参数,其中corpId=$CORPID$参数是钉钉官方定义的参数会把corpId通过这种方式再访问时携带上,例如:http://localhost:81/#/login?corpId=$CORPID$&type=dingding
# 集成飞书
公共说明参考集成企业微信。
AFCenter集成飞书配置(application.properties中配置)
afc.third-party.feishu.enable=true afc.third-party.feishu.appId=xxx afc.third-party.feishu.appSecret=xxx afc.third-party.feishu.redirectUri=http://127.0.0.1:13382/#/login afc.third-party.feishu.mobile-redirect-uri=http://移动端域名端口/#/login # 飞书集成权限信息包含用户信息权限及消息发送权限,如果有其他改造需求只需在此添加相应权限按空格隔开 afc.third-party.feishu.scope=contact:contact.base:readonly contact:user.base:readonly contact:user.phone:readonly contact:user.id:readonly contact:contact:readonly_as_app contact:user.employee_id:readonly im:message im:message:send_as_bot im:message:send_multi_users
afc.third-party.feishu.enable配置为true即开启飞书集成
afc.third-party.feishu.appId飞书appId配置
afc.third-party.feishu.appSecret飞书secret配置
afc.third-party.feishu.redirectUri飞书认证后的回调地址只需要修改端口和域名
afc.third-party.feishu.mobile-redirect-uri移动端飞书认证后的回调地址只需要修改端口和域名
afc.third-party.feishu.scope飞书集成权限信息包含用户信息权限及消息发送权限,如果有其他改造需求只需在此添加相应权限按空格隔开
飞书如果要使用发消息的功能,还需要在对应的飞书应用中添加机器人功能,并搭配上述scope中的所有权限
飞书中配置afc移动端首页时需要增加type=feishu参数,例如:http://localhost:81/#/login?type=feishu
# 集成申石(IDMesh)
公共说明参考集成企业微信。
AFCenter集成申石配置(application.properties种配置)
afc.third-party.idmesh.enable=true afc.third-party.idmesh.appId=xxx afc.third-party.idmesh.appSecret=xxx # 申石应用配置地址 afc.third-party.idmesh.host=https://afcenter1.idmesh.top afc.third-party.idmesh.redirectUri=http://localhost:14382/#/login
afc.third-party.idmesh.enable配置为true即为开启申石集成
afc.third-party.idmesh.appId申石appId
afc.third-party.idmesh.appSecret申石appSecret
afc.third-party.idmesh.host申石应用配置地址从申石应用管理页面获取
afc.third-party.idmesh.redirectUri申石认证后的回调地址只需要修改端口和域名
在申石的应用管理-认证配置种需要开启OAuth2.0认证方式,同时配置授权范围如下图,否则无法集成成功