Example #1
0
        //private static async Task<Resp> ServerAppCheck(HttpContext context, IAppAuthProvider provider, AppIdentity appInfo)
        //{
        //    var secretKeyRes = await provider.IntialAuthAppConfig(context, appInfo);
        //    if (!secretKeyRes.IsSuccess())
        //        return secretKeyRes;

        //    const int expireSecs = 60 * 60 * 2;
        //    if (!appInfo.CheckSign(secretKeyRes.data.AppSecret, expireSecs).IsSuccess()
        //        || !AppInfoHelper.FormatAppIdInfo(appInfo))
        //        return new Resp(RespTypes.SignError, "签名错误!");

        //    return secretKeyRes;
        //}


        private static async Task <Resp> TenantFormatAndCheck(HttpContext context, AppIdentity appInfo, AppAuthOption appOption)
        {
            if (appInfo.SourceMode == AppSourceMode.PartnerServer ||
                appOption?.TenantProvider == null ||
                TenantContext.Identity != null)
            {
                return(new Resp());
            }

            var identityRes = await appOption.TenantProvider.CheckAndInitialIdentity(context, appInfo);

            if (!identityRes.IsSuccess())
            {
                return(identityRes);
            }

            TenantContext.SetIdentity(identityRes.data);
            return(identityRes);
        }
        public static async Task <Resp> FormatAndCheck(HttpContext context, AppIdentity appInfo, AppAuthOption appOption)
        {
            if (appInfo.is_partner || appOption.TenantProvider == null || TenantContext.Identity != null)
            {
                return(new Resp());
            }

            // 服务api请求时,必须有值
            if (!appOption.IsWebSite && string.IsNullOrEmpty(appInfo.tenant_id))
            {
                return(new Resp().WithResp(RespTypes.ObjectNull, "未发现租户信息!"));
            }

            var identityRes = await appOption.TenantProvider.InitialAuthTenantIdentity(context, appInfo);

            if (!identityRes.IsSuccess())
            {
                return(identityRes);
            }

            TenantContext.SetIdentity(identityRes.data);
            return(identityRes);
        }