public async Task Invoke(HttpContext context, IAuthenticatedService authenticatedService, ISqlService sqlService) { var token = authenticatedService.Token(); var uri = context.Request.Path.ToUriComponent(); var path = "/users"; Validate(token, uri, path); var paths = uri.Replace(path, string.Empty).Split('/', StringSplitOptions.RemoveEmptyEntries); var parameter = string.Empty; if (paths.Length > 0) { parameter = paths[0]; } if (Int32.TryParse(parameter, out int value)) { await Authorize(value, token, sqlService); } await _next(context); }
private static async Task TryAuth(IAuthenticationService auth, IAuthenticatedService authed) { try { await auth.TryAuthenticateAsync(authed, new CancellationTokenSource (5000).Token); } catch (OperationCanceledException) { } }
public UserRepository( ILogger <UserRepository> logger, ISqlService sqlService, IAuthenticatedService authenticatedService) { _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _sqlService = sqlService ?? throw new ArgumentNullException(nameof(sqlService)); _authenticatedService = authenticatedService ?? throw new ArgumentNullException(nameof(authenticatedService)); }
public ServicoFuncionarioService( IValidator <ServicoFuncionario> servicoFuncionarioValidator, ISqlService sqlService, IValidationService validationService, IAuthenticatedService authenticatedService, ILogger <ServicoFuncionarioService> logger) { _servicoFuncionarioValidator = servicoFuncionarioValidator; _sqlService = sqlService; _validationService = validationService; _authenticatedService = authenticatedService; _logger = logger; }
public EnderecosFuncionarioService( IValidator <EnderecoFuncionario> enderecoFuncionarioValidator, ISqlService sqlService, IValidationService validationService, IAuthenticatedService authenticatedService, ILogger <EnderecosFuncionarioService> logger) { _enderecoFuncionarioValidator = enderecoFuncionarioValidator; _sqlService = sqlService; _validationService = validationService; _authenticatedService = authenticatedService; _logger = logger; }
public EnderecosClienteService( IValidator <EnderecoCliente> enderecoClienteValidator, ISqlService sqlService, IValidationService validationService, IAuthenticatedService authenticatedService, ILogger <EnderecosClienteService> logger) { _enderecoClienteValidator = enderecoClienteValidator; _sqlService = sqlService; _validationService = validationService; _authenticatedService = authenticatedService; _logger = logger; }
public VeiculoService( IValidator <Veiculo> veiculoValidator, ISqlService sqlService, IValidationService validationService, IAuthenticatedService authenticatedService, ILogger <VeiculoService> logger) { _veiculoValidator = veiculoValidator; _sqlService = sqlService; _validationService = validationService; _authenticatedService = authenticatedService; _logger = logger; }
public ContatosClienteService( IValidator <ContatoCliente> contatoClienteValidator, ISqlService sqlService, IValidationService validationService, IAuthenticatedService authenticatedService, ILogger <ContatosClienteService> logger) { _contatoClienteValidator = contatoClienteValidator; _sqlService = sqlService; _validationService = validationService; _authenticatedService = authenticatedService; _logger = logger; }
public ContatosFuncionarioService( IValidator <ContatoFuncionario> contatoFuncionarioValidator, ISqlService sqlService, IValidationService validationService, IAuthenticatedService authenticatedService, ILogger <ContatosFuncionarioService> logger) { _contatoFuncionarioValidator = contatoFuncionarioValidator; _sqlService = sqlService; _validationService = validationService; _authenticatedService = authenticatedService; _logger = logger; }
public async Task LogoutAsync(IAuthenticatedService service) { if (service is null) { throw new ArgumentNullException(nameof(service)); } string serviceName = service.GetType().GetSimpleTypeName(); SecureStorage.Remove(serviceName); await service.LogoutAsync(); }
public ProductService( IValidator <Product> productValidator, ISqlService sqlService, IValidationService validationService, IAuthenticatedService authenticatedService, ILogger <ProductService> logger) { _productValidator = productValidator; _sqlService = sqlService; _validationService = validationService; _authenticatedService = authenticatedService; _logger = logger; }
public UserService( IValidator <User> userValidator, ISqlService sqlService, IValidationService validationService, IAuthenticatedService authenticatedService, ILogger <UserService> logger) { _userValidator = userValidator; _sqlService = sqlService; _validationService = validationService; _authenticatedService = authenticatedService; _logger = logger; }
public async Task <bool> TryAuthenticateAsync(IAuthenticatedService service, CancellationToken cancellationToken) { if (service is null) { throw new ArgumentNullException(nameof(service)); } if (service.IsLoggedIn) { return(true); } IOAuthedService oauth = service as IOAuthedService; if (oauth == null) { throw new NotSupportedException(); } string serviceName = service.GetType().GetSimpleTypeName(); string refreshToken = await SecureStorage.GetAsync(serviceName); if (String.IsNullOrWhiteSpace(refreshToken)) { return(false); } try { var refreshResult = await oauth.RefreshTokenAsync(refreshToken, cancellationToken); if (refreshResult != null) { await SecureStorage.SetAsync(serviceName, refreshResult.RefreshToken); return(true); } } catch { } return(false); }
public async Task <bool> AuthenticateAsync(IAuthenticatedService service) { if (service is null) { throw new ArgumentNullException(nameof(service)); } IOAuthedService oauth = service as IOAuthedService; if (oauth == null) { throw new NotSupportedException(); } if (await TryAuthenticateAsync(service, CancellationToken.None)) { return(true); } string serviceName = service.GetType().GetSimpleTypeName(); try { var result = await WebAuthenticationBroker.AuthenticateAsync(WebAuthenticationOptions.None, oauth.AuthUri, oauth.CallbackUri); if (result.ResponseStatus == WebAuthenticationStatus.Success) { string code = oauth.GetCode(result.ResponseData); var authResult = await oauth.AuthenticateAsync(code, CancellationToken.None); if (authResult != null) { await SecureStorage.SetAsync(serviceName, authResult.RefreshToken); return(true); } } } catch { } return(false); }
public UserService( ILogger <UserService> logger, IAuthenticatedService authenticatedService, IValidator <User> userValidator, IValidationService validationService, IUserRepository userRepository, IMessagingFactory messagingFactory, ICacheFactory cacheFactory, IMessagingService messagingService, ICacheService cacheService, IOptions <Messaging> messaging) { _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _authenticatedService = authenticatedService ?? throw new ArgumentNullException(nameof(authenticatedService)); _userValidator = userValidator ?? throw new ArgumentNullException(nameof(userValidator)); _validationService = validationService ?? throw new ArgumentNullException(nameof(validationService)); _userRepository = userRepository ?? throw new ArgumentNullException(nameof(userRepository)); _messagingFactory = messagingFactory ?? throw new ArgumentNullException(nameof(messagingFactory)); _cacheFactory = cacheFactory ?? throw new ArgumentNullException(nameof(cacheFactory)); _messagingService = messagingService ?? throw new ArgumentNullException(nameof(messagingService)); _cacheService = cacheService ?? throw new ArgumentNullException(nameof(cacheService)); _messaging = messaging.Value ?? throw new ArgumentNullException(nameof(messaging)); }
public AuthenticatedController(IAuthenticatedService authenticatedService) { this.authenticatedService = authenticatedService; }