Function DC_SSO_YF() If %SignonUserId = "DC_SSO" Then Local string &logstr; Local string &yfToken = %Request.GetParameter("token");/*获取请求body中的token值*/ Local string &reqUrl = %Request.FullURI;/*获取请求URI*/ Local string &qryString = %Request.QueryString;/*获取请求中的QueryString,即url上?号后面的key+value*/ Local string &fullUrl; &fullUrl = &reqUrl; If All(&yfToken) Then Local DC_SSO:SSO &oauth1 = create DC_SSO:SSO(); &userID = &oauth1.getYfUserInfo(&yfToken);/*调用外部系统方法,验证token同时获取用户ID*/ REM:判断PS系统中是否存在用户ID; SQLExec("SELECT 'X' FROM PSOPRDEFN WHERE OPRID =:1 AND ACCTLOCK=0", &userID, &exist); If %SqlRows > 0 Then SetAuthenticationResult( True, &userID, "", False);/*根据存在的用户ID登陆PS系统*/ &authMethod = "DC_SSO_YF";/*全局变量赋值,用以后续处理*/ End-If; End-If; End-If; End-Function;
Function DC_SSO() If &authMethod <> "DC_SSO_YF" And %SignonUserId = "DC_SSO" Then Local string &logstr; Local string &code = %Request.GetParameter("code");/*获取请求body中的code值*/ Local string &reqUrl = %Request.FullURI;/*获取请求URI*/ Local string &qryString = %Request.QueryString;/*获取请求中的QueryString,即url上?号后面的key+value*/ Local string &fullUrl; If All(&qryString) Then &fullUrl = &reqUrl | "?" | &qryString; /*根据URI+QueryString拼接出URL全路径*/ Else &fullUrl = &reqUrl; End-If; rem 文件下载组件不需要登录,跳过单点直接公共账号登录 ; If Find("DC_MENU.LH_VIEW_FILE_COM", &reqUrl) > 0 Then SetAuthenticationResult( True, %SignonUserId, "", False); Return; End-If; If None(&code) Then /* 第一次访问的URL的情况*/ Local string &l_strRedirectURL = GetURL(URL.DC_SSO_URL) | "authorize?response_type=code&client_id=" | GetURL(URL.DC_SSO_CLIENT_ID) | "&redirect_uri=" | EncodeURLForQueryString(&fullUrl); /*这时没有code,跳转到SSO的登陆地址*/ SetAuthenticationResult( True, %SignonUserId, &l_strRedirectURL, False); Else /* SSO登陆后跳转回PS的情况*/ Local DC_SSO:SSO &oauth = create DC_SSO:SSO(); &accessToken = &oauth.getAccessToken(&code, &fullUrl);/*这时根据code去获取AccessToken*/ &userID = &oauth.getUserInfo(&accessToken);/*再根据AccessToken去获取用户*/ REM:判断PS系统中是否存在用户; SQLExec("SELECT 'X' FROM PSOPRDEFN WHERE OPRID =:1 AND ACCTLOCK=0", &userID, &exist); If %SqlRows > 0 Then SetAuthenticationResult( True, &userID, "", False); &authMethod = "DC_SSO"; Else /*不存在账号则退出*/ SetAuthenticationResult( False, "", "", False); End-If; End-If; End-If; End-Function;