Example #1
0
        public static int ForceLoadUserGrantRight(int appId, int userId, string scope, out IEnumerable <int>[] value)
        {
            value = new List <int> [2];
            try
            {
                Tauth_Token daToken = new Tauth_Token();
                if (!daToken.SelectByAppId_UserId(appId, userId))
                {
                    Log.Info("未找到授权记录");
                    return(-1);
                }
                string[] scopeArray = null;
                if (scope.Contains(","))
                {
                    scopeArray = scope.Split(',');
                }
                else
                {
                    scopeArray = new string[] { scope };
                }
                var scopeRights = ScopeRightProvider.GetScopeApis(scopeArray);
                //如果作用域不包含任何权限(仅OpenID),返回已经授权过
                if (scopeRights == null || scopeRights.Count <= 0)
                {
                    Log.Info("授权作用域不包含任何权限");
                    return(1);
                }
                Log.Info("授权作用域包含权限数量{0}", scopeRights.Count);
                var tmp = new List <int>();
                foreach (var sr in scopeRights)
                {
                    tmp.Add(sr.Api_Id);
                }
                value[0] = tmp;
                //value[0] = scopeRights.Select(it => it.Api_Id);
                Tauth_Token_RightCollection daRightCollection = new Tauth_Token_RightCollection();
                daRightCollection.ListEffectiveByTokenId(daToken.Token_Id);

                List <TokenRightApi> apis = MapProvider.Map <TokenRightApi>(daRightCollection.DataTable);
                Log.Info("已经获得的权限有{0}个", apis?.Count);
                var tmp2 = new List <int>();
                foreach (var a in apis)
                {
                    tmp2.Add(a.Api_Id);
                }
                value[1] = tmp2;
                return(0);
            }
            catch (Exception ex)
            {
                Log.Error("检查是否已授权出现错误", ex);
                return(-1);
            }
        }
Example #2
0
        public ActionResult Apis()
        {
            OAuth2.Token.UserToken userToken = Token.UserToken.FromCipherToken(Package.Token);
            Tauth_Token            daToken   = new Tauth_Token();

            if (!daToken.SelectByAppId_UserId(userToken.AppId, Package.UserId))
            {
                return(FailResult("未找到授权访问令牌,Token无效", (int)ApiStatusCode.OPERATOR_FORBIDDEN));
            }
            Tauth_Token_RightCollection daRightCollection = new Tauth_Token_RightCollection();

            daRightCollection.ListEffectiveByTokenId(daToken.Token_Id);
            List <ScopeApiResult> list = MapProvider.Map <ScopeApiResult>(daRightCollection.DataTable);

            if (list == null || list.Count <= 0)
            {
                return(Json(FuncResult.SuccessResult(list)));
            }
            var apis = from scope in list where scope.Status == 1 select scope.Api_Url;

            return(Json(FuncResult.SuccessResult(apis)));
        }