public async Task <ServiceResult <object> > Path([FromServices] IServicePartProvider servicePartProvider, string path, [FromBody] Dictionary <string, object> model) { string serviceKey = this.Request.Query["servicekey"]; if (model == null) { model = new Dictionary <string, object>(); } foreach (string n in this.Request.Query.Keys) { model[n] = this.Request.Query[n].ToString(); } ServiceResult <object> result = ServiceResult <object> .Create(false, null); path = path.ToLower() == GateWayAppConfig.TokenEndpointPath.ToLower() ? GateWayAppConfig.AuthorizationRoutePath : path.ToLower(); if (servicePartProvider.IsPart(path)) { result = ServiceResult <object> .Create(true, await servicePartProvider.Merge(path, model)); result.StatusCode = (int)ServiceStatusCode.Success; } else if (OnAuthorization(path, model, ref result)) { if (path == GateWayAppConfig.AuthorizationRoutePath) { var token = await _authorizationServerProvider.GenerateTokenCredential(model); if (token != null) { result = ServiceResult <object> .Create(true, token); result.StatusCode = (int)ServiceStatusCode.Success; } else { result = new ServiceResult <object> { IsSucceed = false, StatusCode = (int)ServiceStatusCode.AuthorizationFailed, Message = "Invalid authentication credentials" }; } } else { if (!string.IsNullOrEmpty(serviceKey)) { result = ServiceResult <object> .Create(true, await _serviceProxyProvider.Invoke <object>(model, path, serviceKey)); result.StatusCode = (int)ServiceStatusCode.Success; } else { result = ServiceResult <object> .Create(true, await _serviceProxyProvider.Invoke <object>(model, path)); result.StatusCode = (int)ServiceStatusCode.Success; } } } return(result); }
public async Task <ServiceResult <object> > Path([FromServices] IServicePartProvider servicePartProvider, string path, [FromBody] Dictionary <string, object> model) { string serviceKey = this.Request.Query["servicekey"]; path = path.IndexOf("/") < 0 ? $"/{path}" : path; if (model == null) { model = new Dictionary <string, object>(); } foreach (string n in this.Request.Query.Keys) { model[n] = this.Request.Query[n].ToString(); } ServiceResult <object> result = ServiceResult <object> .Create(false, null); path = String.Compare(path, GateWayAppConfig.TokenEndpointPath, true) == 0 ? GateWayAppConfig.AuthorizationRoutePath : path.ToLower(); if (await GetAllowRequest(path) == false) { return new ServiceResult <object> { IsSucceed = false, StatusCode = (int)ServiceStatusCode.RequestError, Message = _servicesLocalizer["RequestError"] } } ; if (servicePartProvider.IsPart(path)) { result = ServiceResult <object> .Create(true, await servicePartProvider.Merge(path, model)); result.StatusCode = (int)ServiceStatusCode.Success; } else { var auth = await OnAuthorization(path, model); result = auth.Item2; if (auth.Item1) { if (path == GateWayAppConfig.AuthorizationRoutePath) { var token = await _authorizationServerProvider.GenerateTokenCredential(model); if (token != null) { result = ServiceResult <object> .Create(true, token); result.StatusCode = (int)ServiceStatusCode.Success; } else { result = new ServiceResult <object> { IsSucceed = false, StatusCode = (int)ServiceStatusCode.AuthorizationFailed, Message = "Invalid authentication credentials" }; } } else {
public async Task <ServiceResult <object> > Path([FromServices] IServicePartProvider servicePartProvider, string path, [FromBody] Dictionary <string, object> model) { var serviceKey = this.Request.Query["servicekey"]; if (model == null) { model = new Dictionary <string, object>(); } foreach (string n in this.Request.Query.Keys) { model[n] = this.Request.Query[n].ToString(); } var result = ServiceResult <object> .Create(false, null); path = path.ToLower(); if (await GetAllowRequest(path) == false) { return(new ServiceResult <object> { IsSucceed = false, StatusCode = (int)MessageStatusCode.RequestError, Message = "请求错误" }); } var appConfig = GateWayAppConfig.ServicePart; if (servicePartProvider.IsPart(path)) { var data = (string)await servicePartProvider.Merge(path, model); return(CreateServiceResult(data)); } else { if (path == GateWayAppConfig.AuthenticationRoutePath) { try { var token = await _authorizationServerProvider.GenerateTokenCredential(model); if (token != null) { result = ServiceResult <object> .Create(true, token); result.StatusCode = (int)MessageStatusCode.Ok; } else { result = new ServiceResult <object> { IsSucceed = false, StatusCode = (int)MessageStatusCode.UnAuthentication, Message = "不合法的身份凭证" }; } } catch (CPlatformException ex) { result = new ServiceResult <object> { IsSucceed = false, StatusCode = (int)MessageStatusCode.CPlatformError, Message = ex.Message }; } catch (Exception ex) { result = new ServiceResult <object> { IsSucceed = false, StatusCode = (int)MessageStatusCode.UnKnownError, Message = ex.Message }; } } else { if (OnAuthorization(path, model, ref result)) { try { if (!string.IsNullOrEmpty(serviceKey)) { var data = await _serviceProxyProvider.Invoke <object>(model, path, serviceKey); return(CreateServiceResult(data)); } else { var data = await _serviceProxyProvider.Invoke <object>(model, path); if (data == null) { return(new ServiceResult <object> { IsSucceed = false, StatusCode = (int)MessageStatusCode.UnKnownError, Message = "服务异常" }); } return(CreateServiceResult(data)); } } catch (CPlatformException ex) { return(new ServiceResult <object> { IsSucceed = false, StatusCode = (int)ex.ExceptionCode, Message = ex.Message }); } catch (Exception ex) { return(new ServiceResult <object> { IsSucceed = false, StatusCode = (int)MessageStatusCode.UnKnownError, Message = ex.Message }); } } } } return(result); }
public async Task <Surging.Core.ApiGateWay.ServiceResult <object> > Path([FromServices] IServicePartProvider servicePartProvider, string path, [FromBody] Dictionary <string, object> model) { string serviceKey = this.Request.Query["servicekey"]; path = path.IndexOf("/") < 0 ? $"/{path}" : path; if (model == null) { model = new Dictionary <string, object>(); } foreach (string n in this.Request.Query.Keys) { model[n] = this.Request.Query[n].ToString(); } Surging.Core.ApiGateWay.ServiceResult <object> result = Surging.Core.ApiGateWay.ServiceResult <object> .Create(false, null); path = String.Compare(path.ToLower(), GateWayAppConfig.TokenEndpointPath, true) == 0 ? GateWayAppConfig.AuthorizationRoutePath : path.ToLower(); var route = await _serviceRouteProvider.GetRouteByPathRegex(path); var httpMethods = route.ServiceDescriptor.HttpMethod(); if (!string.IsNullOrEmpty(httpMethods) && !httpMethods.Contains(Request.Method)) { return new Surging.Core.ApiGateWay.ServiceResult <object> { IsSucceed = false, StatusCode = (int)ServiceStatusCode.Http405Endpoint, Message = "405 HTTP Method Not Supported" } } ; if (!GetAllowRequest(route)) { return new Surging.Core.ApiGateWay.ServiceResult <object> { IsSucceed = false, StatusCode = (int)ServiceStatusCode.RequestError, Message = "Request error" } } ; if (servicePartProvider.IsPart(path)) { //result = ServiceResult<object>.Create(true, await servicePartProvider.Merge(path, model)); //result.StatusCode = (int)ServiceStatusCode.Success; var data = (string)await servicePartProvider.Merge(path, model); return(AuthenticationCommon.CreateServiceResult(data)); } else { var auth = await OnAuthorization(path, route, model); result = auth.result; if (auth.isSuccess) { if (path == GateWayAppConfig.AuthorizationRoutePath) { var oAuthUser = await _authorizationServerProvider.GenerateTokenCredential(model); if (oAuthUser.IsSucceed) { result = Surging.Core.ApiGateWay.ServiceResult <object> .Create(true, oAuthUser); result.StatusCode = (int)ServiceStatusCode.Success; } else { result = new Surging.Core.ApiGateWay.ServiceResult <object> { IsSucceed = false, StatusCode = (int)ServiceStatusCode.AuthorizationFailed, Entity = oAuthUser }; } } else { if (String.Compare(route.ServiceDescriptor.RoutePath, path, true) != 0) { var pamars = RouteTemplateSegmenter.Segment(route.ServiceDescriptor.RoutePath, path); foreach (KeyValuePair <string, object> item in pamars) { model.Add(item.Key, item.Value); } } if (!string.IsNullOrEmpty(serviceKey)) { //result = ServiceResult<object>.Create(true, await _serviceProxyProvider.Invoke<object>(model, route.ServiceDescriptor.RoutePath, serviceKey)); //result.StatusCode = (int)ServiceStatusCode.Success; var data = await _serviceProxyProvider.Invoke <object>(model, path, serviceKey); return(AuthenticationCommon.CreateServiceResult(data)); } else { //result = ServiceResult<object>.Create(true, await _serviceProxyProvider.Invoke<object>(model, route.ServiceDescriptor.RoutePath)); //result.StatusCode = (int)ServiceStatusCode.Success; var data = await _serviceProxyProvider.Invoke <object>(model, path); return(AuthenticationCommon.CreateServiceResult(data)); } } } } return(result); }
public async Task <ServiceResult <object> > Path([FromServices] IServicePartProvider servicePartProvider, string path, [FromBody] Dictionary <string, object> model) { string serviceKey = this.Request.Query["servicekey"]; path = path.IndexOf("/") < 0 ? $"/{path}" : path; if (model == null) { model = new Dictionary <string, object>(); } foreach (string n in this.Request.Query.Keys) { model[n] = this.Request.Query[n].ToString(); } ServiceResult <object> result = ServiceResult <object> .Create(false, null); path = String.Compare(path.ToLower(), GateWayAppConfig.TokenEndpointPath, true) == 0 ? GateWayAppConfig.AuthorizationRoutePath : path.ToLower(); var route = await _serviceRouteProvider.GetRouteByPathRegex(path); if (!GetAllowRequest(route)) { return new ServiceResult <object> { IsSucceed = false, StatusCode = (int)ServiceStatusCode.RequestError, Message = "Request error" } } ; if (servicePartProvider.IsPart(path)) { result = ServiceResult <object> .Create(true, await servicePartProvider.Merge(path, model)); result.StatusCode = (int)ServiceStatusCode.Success; } else { var auth = OnAuthorization(route, model); result = auth.Item2; if (auth.Item1) { if (path == GateWayAppConfig.AuthorizationRoutePath) { var token = await _authorizationServerProvider.GenerateTokenCredential(model); if (token != null) { result = ServiceResult <object> .Create(true, token); result.StatusCode = (int)ServiceStatusCode.Success; } else { result = new ServiceResult <object> { IsSucceed = false, StatusCode = (int)ServiceStatusCode.AuthorizationFailed, Message = "Invalid authentication credentials" }; } } else { if (String.Compare(route.ServiceDescriptor.RoutePath, path, true) != 0) { var pamars = RouteTemplateSegmenter.Segment(route.ServiceDescriptor.RoutePath, path); foreach (KeyValuePair <string, object> item in pamars) { model.Add(item.Key, item.Value); } } if (!string.IsNullOrEmpty(serviceKey)) { result = ServiceResult <object> .Create(true, await _serviceProxyProvider.Invoke <object>(model, route.ServiceDescriptor.RoutePath, serviceKey)); result.StatusCode = (int)ServiceStatusCode.Success; } else { result = ServiceResult <object> .Create(true, await _serviceProxyProvider.Invoke <object>(model, route.ServiceDescriptor.RoutePath)); result.StatusCode = (int)ServiceStatusCode.Success; } } } } return(result); }