U9C单点登录方案

栏目:u9cloud知识作者:用友来源:用友发布:2024-08-20浏览:1

U9C单点登录方案

文档版本:2024010301

使用前提

安装U9CE.MIP产品补丁

1. 登录类型

  • 激活码单点登录
    • 支持:新版本(6.0以后)
  • 账户名+密码单点登录
    • 支持:新版本(6.0以后)+ 旧版本(6.0及以前):

1.1. 激活码单点登录

1.1.1. 创建第三方应用

使用EA管理员账户登录系统,在菜单栏,系统管理 > 系统管理下,找到【应用授权】中的【第三方应用接口授权】进行创建新应用。

在应用中输入应用ID,应用名称,其中【应用ID】对应代码中需要的clientId,【应用密钥】对应代码中需要的clientSecret

1.1.2. 域账户配置和绑定(不需要可以跳过)

使用EA管理员账户,在 系统管理 > 系统管理 菜单下,找到【参数设置】配置域名,与管理员用户。

然后再用户信息界面,将域名与用户绑定

1.1.3. 获取激活码

调用接口:/webapi/Oauth2/SSOLogin

调用方式:HTTPGET

query参数:

string clientid - 应用Id,第三方授权配置

string clientSecret - 应用密钥,第三方授权系统自动生成

string entCode - U9C企业编码,可在U9管理控制台查看

string userCode - U9C用户编码,根据loginType 参数的不同,可使用普通用户和域账户

string orgCode - U9C组织编码,与组织Id不同,可在数据库中查询

int loginType - 登陆方式,1 - 普通用户,2 - 域账户,域账户使用域账户UserName,不需要带域名

1.1.4. 使用激活码拼接地址

访问地址:/api/v1/autologin.aspx

query参数:

string apitoken,激活码

string return_url,单点登录后跳转的地址,需要UrlEncode

string t,d - 直接跳转到return_url上,如果没有设置t,则代表要跳转到首页然后用页签的方式直接 return_url

拼接示例:

http://{U9C地址_带U9C后缀}/api/v1/autologin.aspx?apitoken={激活码}&return_url={UrlEncode之后的登陆后跳转地址}&t={跳转类型}

拼接成后可以直接访问,代码内可以Redirect的方式跳转目标地址。

1.2. 账户名+密码单点登录

1.2.1. 使用账户名和密码拼接地址

访问地址:/api/v1/autologin.aspx

query参数:

string user_code,用户编码

string user_password,用户密码

string enterprise_id,U9C企业编码,可在U9管理控制台查看

string organization_id,U9C组织Id,与组织编码不同,可在数据库中查询

string return_url,单点登录后跳转的地址,需要UrlEncode

string e,拼接地址中显示的密码形态,b - Base64加密,m - MD5加密,无参数,或者其他值,则此密码就是明文密码,在跳转的浏览器信息栏里能到直接看到

string t,d - 直接跳转到return_url上,如果没有设置t,则代表要跳转到首页然后用页签的方式直接 return_url

拼接示例:

http://{U9C地址_带U9C后缀}/api/v1/autologin.aspx?user_code={用户编码}&user_password={用户密码}&enterprise_id={企业编码}&organization_id={组织Id}&return_url={UrlEncode之后的登陆后跳转地址}&e={密码形态}&t={跳转类型}

1.3. 拼接地址使用方法

打开浏览器

输入拼接之后的地址

2. 使用u9c-sso-sdk-cs进行单点登录

目标框架:.NET Framework 4.5

2.1. 使用方法

引入包:UFIDA.U9.MIP.SSO.dll

在项目中初始化U9CSSOClient,软件版本举例:U9C

 U9CSSOClient u9cSSOClient = new U9CSSOClient(endPoint:"系统服务器地址,不用加U9C,比如http://localhost",appVersion:"软件版本,如U9C");

 

调用client方法获取拼接好的地址redirect_uri

使用地址进行跳转,比如在MVC方法中,return Redirect(redirect_uri)

2.2. API介绍

U9CSSOClient中实现如下方法,

AutoLoginWithAPIToken - 获取激活码登录方式的跳转拼接地址     

参数:

string clientId,U9C第三方授权中的应用Id

string clientSecret,U9C第三方授权中的应用密钥

string entCode,企业编码,管理控制台内设置

string userCode,用户编码

string orgCode,组织编码

string targetUrl,跳转目标Url,无需进行url encode

LoginType loginType,枚举,1 - Form 普通用户登录,2 - DomainAuth 域账户登录,默认1

bool isNewOpen,true会在单独页面打开,false会以页签的方式在首页打开,默认false

返回值:

string redirect_uri,可以直接使用的redirect地址

AutoLoginWithPwd - 获取账号密码登录方式的跳转拼接地址     

参数:

string userCode,用户编码

string userPassword,用户密码

string entCode,企业编码,管理控制台内设置

string orgCode,组织编码

string targetUrl,跳转目标Url,无需进行url encode

PwdPattern pwdPattern,影响的是跳转的时候地址栏上显示的格式,0-明文,1-Base64加密,2-MD5加密,默认明文

bool isNewOpen,true会在单独页面打开,false会以页签的方式在首页打开,默认false

返回值:

string redirect_uri,可以直接使用的redirect地址

GetAPIToken - 获取激活码     

参数:

string clientId,U9C第三方授权中的应用Id

string clientSecret,U9C第三方授权中的应用密钥

string entCode,企业编码,管理控制台内设置

string userCode,用户编码

string orgCode,组织编码

LoginType loginType,枚举,1 - Form 普通用户登录,2 - DomainAuth 域账户登录,默认1

返回值:

string apiToken,激活码

GetSaltFromBI - 获取企业内指定用户盐值     

参数:

string entCode,企业编码,管理控制台内设置

string userCode,用户编码

返回值:

string salt,指定企业内的指定用户盐值

2.3. 示例

示例项目MVC,.NET Framework 4.5

如果使用的是准备好SSODemo,确认引入UFIDA.U9.MIP.SSO.dll后,无需添加代码,只需要重新配置用户

2.3.1. 修改View/Shared/_Layout.cshtml

在菜单目录下直接添加

 


 

  • @Html.ActionLink("主页", "Index", "Home")
  • @Html.ActionLink("关于", "About", "Home")
  • @Html.ActionLink("联系方式", "Contact", "Home")
  • @Html.ActionLink("单点登录--激活码", "AutoLoginWithAPIToken", "SSO")
  • @Html.ActionLink("单点登录--明文密码", "AutoLoginWithPlainPwd", "SSO")
  • @Html.ActionLink("单点登录--Base64密码", "AutoLoginWithBase64Pwd", "SSO")
  • @Html.ActionLink("单点登录--带盐密码", "AutoLoginWithSaltPwd", "SSO")


 



 

 

2.3.2. 创建SSOController

在SSOController添加对应Action,注意,Controller里的配置是自己的配置

public class SSOController : Controller
{
// U9C单点登录服务器地址,一般为U9C服务器地址
private static readonly string openApiUrlBase = "http://localhost";
private static readonly string appVersion = "U9C";

// 需要根据用户情况自行配置
        // clientId+clientSecret 以及 用户登录信息 
private static readonly string clientId = "SSOTEST";
private static readonly string clientSecret = "e9d739126cbe4ae39340ff7a1e088c8a";

private static readonly string entCode = "002";
private static readonly string userCode = "admin1";
private static readonly string userPassword = "123456";
private static readonly string orgCode = "001";

// u9c登录首页仪表板,会出现两个页签的一场情况,用户最好配置上其他的页面,
private static readonly string u9cTargetPage = "http://localhost/U9C/mvc/dashboards/index";

// u9c 登录sdk
private readonly U9CSSOClient u9CSSOClient = new U9CSSOClient(openApiUrlBase, appVersion);

///


/// 单点登录--激活码
///
/// 
public ActionResult AutoLoginWithAPIToken()
{
string redirect_uri = u9CSSOClient.AutoLoginWithAPIToken(clientId, clientSecret, entCode, userCode, orgCode, u9cTargetPage);

return Redirect(redirect_uri);
}

///
/// 单点登录--明文密码
///
/// 
public ActionResult AutoLoginWithPlainPwd()
{
string redirect_uri = u9CSSOClient.AutoLoginWithPwd(userCode, userPassword, entCode, orgCode, u9cTargetPage);
return Redirect(redirect_uri);
}

///
/// 单点登录--Base64密码
///
/// 
public ActionResult AutoLoginWithBase64Pwd()
{
string redirect_uri = u9CSSOClient.AutoLoginWithPwd(userCode, userPassword, entCode, orgCode, u9cTargetPage, PwdPattern.Base64);
return Redirect(redirect_uri);
}

///
/// 单点登录--带盐密码
///
/// 
public ActionResult AutoLoginWithSaltPwd()
{
string redirect_uri = u9CSSOClient.AutoLoginWithPwd(userCode, userPassword, entCode, orgCode, u9cTargetPage, PwdPattern.MD5);
return Redirect(redirect_uri);
}

}

 

 

2.3.3. 运行Demo,在页面上点击菜单进行测试

3. 常见问题

3.1. 如何获取跳转目标页面url?

成功登录U9C后,在页面内打开目标页面(以出货计划页面为例)。此时会出现目标页面的页签,浏览器的地址栏内地址不变,仍为http://YOUR_HOST/U9C/mvc/main/index

右击页签【出货计划】,选择在【新窗口中打开】

浏览器会自动新增一个页面,同时地址栏内的地址会发生变化,即为目标页面的地址

3.2. 跳转页面失败

3.2.1. 跳转失败后,停留在登录页面

一般原因是,用户名/用户密码/企业编码/组织编码等信息不对,匹配后可以直接跳转到U9C内的页面

3.3. 跳转成功,但页面打开异常

3.3.1. 主页/U9C/mvc/main/index,不能直接进行跳转,会多次内嵌,建议不要设置直接跳转主页

3.3.2. 首页仪表板U9C/mvc/dashboards/index,页面会额外打开一个页签(一个默认首页仪表板,另一个是空白页签但有内容)。建议不要设置直接跳转首页仪表板

U9C单点登录方案

文档版本:2024010301使用前提安装U9CE.MIP产品补丁1. 登录类型激活码单点登录支持:新版本(6.0以后)账户名+密码单点登录支持:新版本(...
点击下载文档
标签: # U9C
分享:
确认删除?
回到顶部
客服QQ
  • 客服QQ点击这里给我发消息