public BaseController(IService <TModel> service, IHttpAuthService authService) { this.service = service ?? throw new ArgumentNullException(nameof(service)); this.authService = authService ?? throw new ArgumentNullException(nameof(authService)); this.service.ValidationDictionary = new ModelStateWrapper(ModelState); this.service.AuthService = authService; }
public AuthController(IService <AuthToken> service, IHttpAuthService authService) : base(service, authService) { }
public void Configure(IApplicationBuilder app, IHostingEnvironment env, IHttpAuthService httpAuthService, ILogger logger) { // cors config app.UseCors(c => { c.AllowAnyHeader(); c.AllowAnyMethod(); c.AllowAnyOrigin(); c.AllowCredentials(); }); // ocelot config var ocelotConfiguration = new OcelotPipelineConfiguration { PreErrorResponderMiddleware = async(ctx, next) => { await next.Invoke(); }, AuthenticationMiddleware = async(ctx, next) => { try { if (string.IsNullOrEmpty(ctx?.DownstreamReRoute?.AuthenticationOptions?.AuthenticationProviderKey)) { await next.Invoke(); return; } var token = GetAuthToken(ctx.HttpContext); if (httpAuthService == null) { ctx.HttpContext.Response.StatusCode = 401; await next.Invoke(); return; } var user = await httpAuthService.GetUser(token); if (user == null || user.Data == null || !user.IsSuccess) { ctx.HttpContext.Response.StatusCode = 401; await next.Invoke(); return; } var userIdString = AttachUserId(ctx.HttpContext, user.Data.Id); if (!string.IsNullOrEmpty(userIdString)) { ctx.DownstreamRequest.AbsolutePath = userIdString; ctx.DownstreamRequest.Query = $"userId={user.Data.Id}"; } await next.Invoke(); } catch (Exception ex) { var errors = ctx.Errors.Select(a => $"{a.Message}; "); logger.Error(ex, $"KnotDiary.ApiGateway.Startup | AuthenticationMiddleware | Authentication has thrown an error | {errors}"); ctx.HttpContext.Response.StatusCode = 401; await next.Invoke(); } } }; app.UseOcelot(ocelotConfiguration).Wait(); }
public UsersController(IService <User> service, IHttpAuthService authService) : base(service, authService) { }
public OAuth2AuthenticationFilter(IHttpAuthService authService, IService <AuthToken> tokenService) { this.authService = (OAuth2AuthService)authService ?? throw new ArgumentNullException(nameof(authService)); this.tokenService = tokenService ?? throw new ArgumentNullException(nameof(tokenService)); }
public CrudController(IService <TModel> service, IHttpAuthService authService) : base(service, authService) { }