钉钉微应用OAuth2授权打开一个应用时提示对不起您无权限查看该页面,但是打开同企业其他应用没有问题,同企业其他人打开该应用没有问题,问下可能的原因是什么?
//简化代码如下:
public ActionResult Index()
{
string q="/Mobile/Mobile/Index";
string appId = Request["appid"];
if (string.IsNullOrEmpty(appId))
{
//判断是否存在code
string code = Request["code"];
if (!string.IsNullOrEmpty(code))
{
#region 钉钉oauth登陆
string appid = Session["AppId"].ToString();
string agentid = Session["AgentId"].ToString();
//此处调用接口获取部门信息
string corpid = Session["CorpId"].ToString();
string corpSecret = Session["CorpSecret"].ToString();
var tokenModel = EnterpriseBusiness.GetToken(corpid, corpSecret);
var access_token = tokenModel.access_token;
//---------------利用access_token和code去换取当前用户
var userModel = EnterpriseBusiness.GetCurrentUser(access_token, code);
//登录
if (userModel != null)
{
string dingtalkAccount = userModel.userid;
int lefttimes = 0;
Clusterware.ConnectionResult result = UserContextFactory.Login(HttpContext,
H3.Clusterware.AccountType.DingTalkAccount,
"",
dingtalkAccount,
"",
out lefttimes);
if (result != Clusterware.ConnectionResult.Success)
{
return Redirect(MobileLoginPath + "?q=" + q);
}
else
{
return View();
}
}
else
{
return Redirect(MobileLoginPath + "?q=" + q);
}
#endregion
}
else
{
//判断pc端登陆
if (this.UserContext != null)
{
return View();
}
else
{
return Redirect(MobileLoginPath + "?q=" + q);
}
}
}
else
{
string corpId = Request["corpid"];
string corpSecret = Request["corpsecret"];
string agentId = Request["agentid"];
Session["CorpId"] = corpId;
Session["AppId"] = appId;
Session["CorpSecret"] = corpSecret;
Session["AgentId"] = agentId;
//判断是否存在cookie
if (Request.Cookies[corpId] != null && Request.Cookies[corpId].Value != "")
{
//登录并直接跳转
string userId = H3.Security.DESEncryptor.DecryptDES(
Request.Cookies[corpId].Value,
UserContextFactory.Cookie_encrytkey);
int lefttimes = 0;
Clusterware.ConnectionResult result = UserContextFactory.Login(HttpContext,
H3.Clusterware.AccountType.DingTalkAccount,
"",
userId,
"",
out lefttimes);
if (result == Clusterware.ConnectionResult.Success)
{
return View();
}
}
string callback = Request.Url.ToString().Split('?')[0];
string authUrl = string.Format("https://oapi.dingtalk.com/connect/oauth2/authorize?appid={0}&redirect_uri={1}&response_type=code&scope=SCOPE&state=State", corpId, callback);
return Redirect(authUrl);
}
}
-------------------------
-------------------------
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。