IdP4:4-2 对接企业微信认证

        注:在继续操作前,请确认已经完成IdP4:4-1 对接企业微信准备


用企业微信接口对接IdP包括如下几个步骤:

1、在企业微信中创建“CARSI资源共享”应用;

2、通过回调地址的方式将该应用与CARSI IdP对接

3、在CARSI团队提供的IdP企业微信插件基础上,定义属性。该插件已经通过脚本自动安装,无需手工操作。


        CARSI IdP对接企业微信通讯录的方法:

1、在企业微信管理端,创建企业微信应用“CARSI资源共享”

        进入企业微信网站https://work.weixin.qq.com/,以管理员身份登录,选择“应用管理”标签-->自建,创建应用“CARSI资源共享”。如果已经创建过该应用,直接进入应用详情页面。


        在应用创建页面,输入应用名称: CARSI资源共享, 设置LOGO(使用CARSI LOGO)及可见范围并保存,如下图所示。

注:为了能获取到用户的完整信息,请授权该应用可访问最高级组织架构,即在设置应用可见范围时选择最大级别组织范围(最上面的组织部门)。

2、进入应用详情,记录AgentId和Secret,后续IdP配置需要用到这两个参数。



        进入我的企业,获取企业ID,后续IdP配置需要使用这个参数。

3、修改应用设置

        在“CARSI资源共享”应用中添加IdP授权回调域名,并设置域名为可信。

3.1 添加IdP授权回调域名

        在应用详情页面, --> 开发者接口,-->企业微信授权登录,点击设置,

        将授权回调域名改成学校IdP域名,例如idp.xxx.edu.cn,并保存。

3.2 设置IdP回调域名可信

        进入应用详情,-->开发者接口,-->网页授权及JS-SDK,点击“设置可信域名”


        如下图所示,将学校IdP域名输入下面的对话框,保存,如果有域名所有权校验不通过,则点击”申请校验域名“,按照提示进行域名校验。

3.3 在企业可访问ip中增加idp的ip地址



4、在IdP端,配置企业微信对接参数

[carsi@www ~]$ sudo vi /opt/shibboleth-idp/conf/authn/authn.properties
#将第85行配置由external.jsp修改为/Authn/External:
idp.authn.External.externalAuthnPath = contextRelative:/Authn/External

#新增以下内容,将其中的"abcdefghijklmnopqr"、"1234567"、"abcdefghijklmnopqrstuvwxyz1234567890123"分别替换为前面记录的企业ID、agentid和appsecret,将"https://idp.xxx.edu.cn"修改为学校实际IdP服务器域名。
# WechatWork properties
idp.authn.flows = External
shibcarsi.serverName = https://idp.xxx.edu.cn
shibcarsi.wechat.appid = abcdefghijklmnopqr
shibcarsi.wechat.agentid = 1234567
shibcarsi.wechat.appsecret = abcdefghijklmnopqrstuvwxyz1234567890123
shibcarsi.wechat.oauth2LoginUrl = https://open.work.weixin.qq.com/wwopen/sso/qrConnect?appid=${shibcarsi.wechat.appid}&agentid=${shibcarsi.wechat.agentid}&state=STATE
shibcarsi.wechat.oauth2LoginUrlh5 = https://open.weixin.qq.com/connect/oauth2/authorize?appid=${shibcarsi.wechat.appid}&response_type=code&scope=snsapi_base&state=STATE
shibcarsi.wechat.oauth2TokenUrl = https://qyapi.weixin.qq.com/cgi-bin/gettoken
shibcarsi.wechat.oauth2ResourceUrl = https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo
shibcarsi.wechat.oauth2GetUserUrl = https://qyapi.weixin.qq.com/cgi-bin/user/get
shibcarsi.wechat.oauth2clientid = ${shibcarsi.wechat.appid}
shibcarsi.wechat.oauth2clientsecret = ${shibcarsi.wechat.appsecret}

5、在IdP端,配置属性定义

        IdP安装脚本共配置了4个属性:eduPersonScopedAffiliation、eduPersonTargetedID(ePTID)、pairwise-id、eduPersonEntitlement(ePE)。eduPersonScopedAffiliation需要单独配置,其他属性已经在安装脚本中自动配置,其中的ePTID和pairwise-id根据用户登录uid计算获得,mariadb正常工作时两属性可用。ePE为固定取值,承诺线上CARSI访问的授权对象与线下采购合同一致。

        eduPersonScopedAffiliation属性,取值为用户在学校的身份,其中的“carsi_af”为企业微信中确定CARSI用户身份的属性名称。关于身份属性取值,需要将企业微信中用户身份的取值,对应到CARSI联盟标准取值,包括:faculty(教师),student(学生),staff(教工),employee(雇员),member(各类人员,包括faculty、student、staff、employee),alum(校友),affiliate(附属人员或临聘,常用),other(CARSI补充,不建议优先使用)。下面以“staff”、“student”、“member”为例,进行配置。学校可根据本地实际部署情况配置其他身份。不同SP对用户身份的要求不同,建议配置时尽可能细化用户身份分类,避免后期修改配置。

        例如某用户的部门为:学生/信息科学技术学院/大一,则可以用if(employeeType.getValues().get(0)=="student") localPart = "student"; 来将改用户身份映射成student。

        注:

1、为了能获取到用户的完整部门信息,请授权创建的企业微信应用有访问根目录的权限;

2、如下样例,可根据实际需释放的用户属性修改if...else部分,其他内容不需要修改;

3、该属性根据企业微信"carsi_af"字段识别用户的身份; 


[carsi@www ~]$ sudo vi /opt/shibboleth-idp/conf/attribute-resolver.xml
    <AttributeDefinition xsi:type="ScriptedAttribute" id="eduPersonScopedAffiliation">
        <InputAttributeDefinition ref="employeeType" />
        <Script><![CDATA[
        scopedValueType = Java.type("net.shibboleth.idp.attribute.ScopedStringAttributeValue");
        var localPart = "";
        if(typeof(employeeType)=="undefined"){
            localPart = "member";
        }else{
            if(employeeType.getValues().get(0)=="staff") localPart = "staff"; # if条件中“staff”为本地用户管理系统中属性取值,可能是“staf”或其他
            else if(employeeType.getValues().get(0)=="student") localPart = "student"; # if条件中“student”为本地用户管理系统中属性取值,可能是“stu”或其他
            else localPart = "member";
        }
        eduPersonScopedAffiliation.addValue(new scopedValueType(localPart, "%{idp.scope}"));
            ]]></Script>
    </AttributeDefinition>

    <AttributeDefinition xsi:type="SubjectDerivedAttribute" id="employeeType" principalAttributeName="carsi_af"></AttributeDefinition>

[carsi@www ~]$ sudo systemctl restart jetty

6、配置属性释放

        IdP安装脚本已经完成属性释放配置,可不修改。


版权所有©北京大学计算中心