5、用腾讯微校接口对接

CARSI IdP对接腾讯微校用户管理的方法:

1. 加入微校并注册应用

        在腾讯微校管理端,按照自建应用引导申请自建应用。

        CARSI logo:

        应用名称:CARSI资源共享

        简介:教育网联邦认证与资源共享基础设施CARSI是中国教育和科研计算机网联邦认证与资源共享基础设施,在国内高校已经普遍建设完成的校园网统一用户管理和身份认证系统基础上,面向中国高校和科研机构提供跨域身份认证和资源共享服务。

        业务域名:请填写idp域名,idp.xxx.xxx.xxx

        业务地址:请填写https://dspre.carsi.edu.cn/Shibboleth.sso/Login?SAMLDS=1&target=https%3A%2F%2Fdspre.carsi.edu.cn%2Fwxds&entityID=https%3A%2F%2F{SERVERNAME}%2Fidp%2Fshibboleth。注意:请将{SERVERNAME}替换成IdP域名,如idp.xxx.edu.cn

        记录应用AppKey和AppSecret,以备后用。

2. 腾讯微校后台配置

        进入配置,基本信息,获取学校code,记录以备后用。

        应用需要用到微校认证,获取用户信息,需要用到属性,eduPersonScopedAffiliation:核心属性,标识用户的身份,取值为:faculty, student, staff, alum, member, affiliate, employee, other,后面加上@xxx.edu.cn。对应的身份分别为:教师、学生、员工、校友、成员、附属人员,聘用人员、其他。

        微校后台默认身份取值其他(0)、学生(1)、教职工(4)、校友(5),请按照如下信息进行人员身份调整

{ 
    "errcode": 0, 
    "errmsg": "ok", 
    "list": 
    [ 
        { 
            "identity_type": 0, 
            "name": "其他", 
            "classification": 1, 
            "classification_name": "其他" 
        }, 
        { 
            "identity_type": 1, 
            "name": "学生", 
            "classification": 2, 
            "classification_name": "学生" 
        }, 
        { 
            "identity_type": 2, 
            "name": "教师", 
            "classification": 3, 
            "classification_name": "教师" 
        }, 
        { 
            "identity_type": 3, 
            "name": "员工", 
            "classification": 4, 
            "classification_name": "员工" 
        }, 
        { 
            "identity_type": 4, 
            "name": "成员", 
            "classification": 5, 
            "classification_name": "成员" 
        }, 
        { 
            "identity_type": 5, 
            "name": "校友", 
            "classification": 6, 
            "classification_name": "校友" 
        }, 
        { 
            "identity_type": 6, 
            "name": "附属人员", 
            "classification": 7, 
            "classification_name": "附属人员" 
        }, 
        { 
            "identity_type": 7, 
            "name": "聘用人员", 
            "classification": 8, 
            "classification_name": "聘用人员" 
        }
    ] 
}

3.IdP端,修改腾讯微校对接参数

[root@www ~]# vi /opt/shibboleth-idp/conf/idp.properties
#修改
idp.authn.flows=External
#新增,将{APPKEY}替换成应用的Appkey,将{APPSECRET}替换成应用的AppSecret,将{OCODE}替换成学校code,将{SERVERNAME}替换成idp的域名
shibcas.oauth2UrlPrefix = https://open.wecard.qq.com/connect/oauth/pc-authorize
shibcas.oauth2UrlPrefixH5 = https://open.wecard.qq.com/connect/oauth/authorize
shibcas.oauth2LoginUrl = ${shibcas.oauth2UrlPrefix}?app_key={APPKEY}&response_type=code&ocode={OCODE}&scope=snsapi_userinfo&state=STATE&connect=curLogin
shibcas.oauth2LoginUrlH5 = ${shibcas.oauth2UrlPrefixH5}?app_key={APPKEY}&response_type=code&ocode={OCODE}&scope=snsapi_userinfo&state=STATE
shibcas.serverName = https://{SERVERNAME}
shibcas.oauth2TokenUrl = https://open.wecard.qq.com/connect/oauth2/token
shibcas.oauth2ResourceUrl = https://open.wecard.qq.com/connect/oauth/get-user-info
shibcas.oauth2clientid = {APPKEY}
shibcas.oauth2clientsecret = {APPSECRET}
shibcas.oauth2redirecturi = https%3a%2f%2f{SERVERNAME}%2fidp%2fAuthn%2fExternal%3fconversation%3de1s1
shibcas.schoolurl = https://open.wecard.qq.com/cgi-bin/campus/school-info

4.IdP端,配置属性定义

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

        注:如果按照第2步骤中在腾讯微校后台配置好了用户属性,则此步骤不需要做任何修改

        注:只需要修改下述eduPersonScopedAffiliation属性定义即可,其他内容不需要修改

[root@www ~]# sudo vi /opt/shibboleth-idp/conf/attribute-resolver.xml
     <AttributeDefinition xsi:type="ScriptedAttribute" id="eduPersonScopedAffiliation">
        <Dependency ref="identity_type" />
        <Script><![CDATA[
        var localpart = "";
        if(typeof(identity_type)=="undefined"){
            localpart = "member";
        }else{
            if(identity_type.getValues().get(0)=="0") localpart = "member";
            else if(identity_type.getValues().get(0)=="1") localpart = "student";
            else if(identity_type.getValues().get(0)=="2") localpart = "faculty";
            else if(identity_type.getValues().get(0)=="3") localpart = "staff";
            else if(identity_type.getValues().get(0)=="4") localpart = "member";
            else if(identity_type.getValues().get(0)=="5") localpart = "alum";
            else if(identity_type.getValues().get(0)=="6") localpart = "affiliate";
            else if(identity_type.getValues().get(0)=="7") localpart = "employee";
            else localpart = "member";
        }
        eduPersonScopedAffiliation.addValue(localpart + "@%{idp.scope}");
            ]]></Script>
        <AttributeEncoder xsi:type="SAML1String" name="urn:mace:dir:attribute-def:eduPersonScopedAffiliation" encodeType="false" />
        <AttributeEncoder xsi:type="SAML2String" name="urn:oid:1.3.6.1.4.1.5923.1.1.1.9" friendlyName="eduPersonScopedAffiliation" encodeType="false" />
    </AttributeDefinition>
    <AttributeDefinition xsi:type="SubjectDerivedAttribute" id="identity_type" principalAttributeName="identity_type"></AttributeDefinition>
[root@www ~]# sudo systemctl restart tomcat9

        eduPersonTargtedID是一个永久可用的用户唯一id。通过hash算法加密之后,可读性不强。适用于需要区分不同用户的应用场景,同时保护了用户个人隐私。       

        修改eduPersonTargtedID加密盐值,可以使用如下指令生成随机字符串,并将idp.persistentId.salt = xxxxxxxxxxxxxxxxxxxx中的xxxxxxxxxxxxxxxxxxxx修改成生成的随机字符串

        注意:如果是进行IdP的升级,为了保证生成的eduPersonTargtedID一致,请沿用旧IdP的加密盐值,旧的加密盐值请参考IdP3.4.7备份恢复及高可用方案

[root@www ~]# openssl rand -base64 32
aesqnxtO+Di26xM78kXY6yD2m0QCK+0p68i7j7jQL8k=
[root@www ~]# vi /opt/shibboleth-idp/conf/saml-nameid.properties
idp.persistentId.sourceAttribute = eduPersonPrincipalName
idp.persistentId.salt = xxxxxxxxxxxxxxxxxxxx
idp.persistentId.encoding = BASE64
idp.persistentId.dataSource = MyDataSource

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