示例#1
0
        public async Task InvokeAsync(HttpContext context)
        {
            //RequestLoggerInterceptors.LogRequest(new object[] { context.Request.Body, context.Request.Headers });
            CodeLabException codelabExp = AuthenticationInterceptor.AuthenticateUser(context.Request);

            if (codelabExp != null)
            {
                context.Response.StatusCode  = 490;
                context.Response.ContentType = "application/json";
                string jsonString = JsonConvert.SerializeObject(codelabExp);
                await context.Response.WriteAsync(jsonString, Encoding.UTF8);

                // to stop futher pipeline execution
                return;
            }

            // Call the next delegate/middleware in the pipeline
            await _next(context);
        }
        public static CodeLabException AuthenticateUser(HttpRequest request)
        {
            if (request.Method.ToLower() == "post")
            {
                string  requestBody = ReadBodyAsString(request);
                JObject body        = JObject.Parse(requestBody);
                if (body["token"] == null)
                {
                    CodeLabException codelabExp = new CodeLabException
                    {
                        ErrorCode            = (int)ErrorCode.General_Error,
                        SubErrorCode         = (int)GeneralError.Token_Not_Exist,
                        ErrorReferenceNumber = "UU-266169856"
                    };

                    //codelabExp.ExtraInfoMessage = "call failed because " + Constants.GeneralErrorDic[GeneralError.Some_Thing_Went_Wrong];
                    codelabExp.ExtraInfoMessage = Constants.GeneralErrorDic[GeneralError.Token_Not_Exist];

                    return(codelabExp);
                }
            }
            return(null);
        }
示例#3
0
        public IActionResult ValidateCredentials([FromBody] LoginRequest request)
        {
            try
            {
                return(Ok(Authentication.ValidateCredentials(request)));
            }
            catch (CodeLabException ex)
            {
                return(ExceptionHandeling.GenerateErrorResponse(ex));
            }
            catch (Exception ex)
            {
                CodeLabException codelabExp = new CodeLabException
                {
                    ErrorCode            = (int)ErrorCode.General_Error,
                    SubErrorCode         = (int)GeneralError.Some_Thing_Went_Wrong,
                    ErrorReferenceNumber = "UU-266169856"
                };

                //codelabExp.ExtraInfoMessage = "call failed because " + Constants.GeneralErrorDic[GeneralError.Some_Thing_Went_Wrong];
                codelabExp.ExtraInfoMessage = ex.Message;
                return(ExceptionHandeling.GenerateErrorResponse(codelabExp));
            }
        }