Ejemplo n.º 1
0
        private AppConfig Valid(String appId, String secret, String token)
        {
            if (appId.IsNullOrEmpty() && !token.IsNullOrEmpty())
            {
                var ap1 = _tokenService.DecodeToken(token, Setting.Current);
                appId = ap1?.Name;
            }

            var ap = _tokenService.Authorize(appId, secret, Setting.Current.AutoRegister);

            var app = AppConfig.FindByName(appId);
            if (app == null)
            {
                app = new AppConfig
                {
                    Name = ap.Name,
                    Enable = ap.Enable,
                };

                app.Insert();
            }

            // 检查应用有效性
            if (!app.Enable) throw new ArgumentOutOfRangeException(nameof(appId), $"应用[{appId}]已禁用!");

            return app;
        }
Ejemplo n.º 2
0
        private (AppConfig, ConfigOnline) Valid(String appId, String secret, String clientId, String token)
        {
            var set = Setting.Current;

            if (appId.IsNullOrEmpty() && !token.IsNullOrEmpty())
            {
                var ap1 = _tokenService.DecodeToken(token, set);

                appId = ap1?.Name;
            }

            var ap = _tokenService.Authorize(appId, secret, set.AutoRegister);

            // 新建应用配置
            var app = AppConfig.FindByName(appId);

            if (app == null)
            {
                app = AppConfig.Find(AppConfig._.Name == appId);
            }
            if (app == null)
            {
                var obj = AppConfig.Meta.Table;
                lock (obj)
                {
                    app = AppConfig.FindByName(appId);
                    if (app == null)
                    {
                        app = new AppConfig
                        {
                            Name   = ap.Name,
                            Enable = ap.Enable,
                        };

                        app.Insert();
                    }
                }
            }

            var ip = HttpContext.GetUserHost();

            if (clientId.IsNullOrEmpty())
            {
                clientId = ip;
                if (!token.IsNullOrEmpty())
                {
                    var(jwt, _) = _tokenService.DecodeToken(token, set.TokenSecret);
                    clientId    = jwt?.Id;
                }
            }

            // 更新心跳信息
            var online = ConfigOnline.UpdateOnline(app, clientId, ip, token);

            // 检查应用有效性
            if (!app.Enable)
            {
                throw new ArgumentOutOfRangeException(nameof(appId), $"应用[{appId}]已禁用!");
            }

            return(app, online);
        }