public override Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
        {
            string function = context.Request + " " + context.Request.Method;

            try
            {
                _Logging.Start(function);
                _Logging.WriteTransactionLog(function, "Login validation işlemi başlatıldı...", Helpers.Messages.ErrorMessageCode.Authorization);
                bool isSuccess = true;
                //string clientId = string.Empty;
                //string clientSecret = string.Empty;

                //if (!context.TryGetBasicCredentials(out clientId, out clientSecret))
                //{
                //    context.TryGetFormCredentials(out clientId, out clientSecret);
                //}

                //if (context.ClientId == null)
                //{
                //    isSuccess = false;
                //    context.SetCustomError("Kullanıcının tanımlayıcı bilgileri eksik");
                //}
                //else
                //{

                var dictionary = new Dictionary <string, string>
                {
                    { "appId", context.Parameters["AppID"] }, { "companyId", context.Parameters["CompanyId"] }
                };

                foreach (var item in dictionary)
                {
                    if (string.IsNullOrWhiteSpace(item.Value))
                    {
                        _Logging.WriteTransactionLog(function, string.Format("Parametre [{0}] bilgisi set edilmemiş.", item.Key), Helpers.Messages.ErrorMessageCode.UnAuthorized);
                        _Logging.WriteApplicationLog(function, string.Format("Parametre [{0}] bilgisi set edilmemiş.", item.Key), Helpers.Messages.ErrorMessageCode.UnAuthorized);

                        context.SetCustomError(string.Format("Parametre [{0}] bilgisi set edilmemiş.", item.Key));
                        isSuccess = false;
                    }
                }

                context.OwinContext.Set("as:clientAppID", dictionary["appId"]);
                context.OwinContext.Set("as:clientCompanyID", dictionary["companyId"]);

                if (isSuccess)
                {
                    context.Validated();
                }
                //}
                _Logging.WriteTransactionLog(function, "Login validation işlemi tamamlandı.", Helpers.Messages.ErrorMessageCode.Authorization);
            }
            catch (Exception ex)
            {
                _Logging.WriteApplicationLog(function, ex.Message, Helpers.Messages.ErrorMessageCode.TryCatchMessage);
                context.SetCustomError(ex.Message);
            }
            return(Task.FromResult <object>(null));
        }
Example #2
0
 /// <summary>
 /// 第二步验证失败执行
 /// </summary>
 /// <param name="context"></param>
 /// <returns></returns>
 public override Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
 {
     return(Task.Factory.StartNew(() =>
     {
         if (context.HasError)
         {
             context.SetCustomError(context.Error);
         }
         else if (context.TryGetFormCredentials(out string clientId, out string clientSecret))
         {
             context.Validated();
         }
         else
         {
             context.SetCustomError("客户端相关参数有误");
         }
     }));
 }