private bool Authenticate() { string id = Request.Headers["userId"]; string password = Request.Headers["userPass"]; return(Authentifier.Authenticate(id, password)); }
public async Task <TResponse> Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate <TResponse> next) { Type typeReponse = typeof(TResponse); Authentifier attributAuthentifier = (Authentifier)Attribute.GetCustomAttribute(typeof(TRequest), typeof(Authentifier)); if (attributAuthentifier == null || typeof(ReponseApi) != typeReponse.BaseType) { return(await next()); } else { if (string.IsNullOrEmpty(_utilisateurEnCoursService.IdUtilisateur)) { TResponse instance = Activator.CreateInstance <TResponse>(); PropertyInfo propertyInfo = typeReponse.GetProperty(nameof(ReponseApi.ReponseApiCodeStatut_)); propertyInfo.SetValue(instance, 401, null); propertyInfo = typeReponse.GetProperty(nameof(ReponseApi.ReponseApiMessage_)); propertyInfo.SetValue(instance, "Vous n'êtes pas autorisé.", null); return(await Task.FromResult(instance)); } return(await next()); } }
private bool Authenticate() { if (Authentifier.context == null) { Authentifier.context = context; } string id = Request.Headers["userId"]; string password = Request.Headers["userPass"]; return(Authentifier.Authenticate(id, password)); }