private NuGetAuthenticationResult Fail(string message, bool includeRealm)
        {
            var realm = includeRealm ? $"{_settings.ServerName} Package Registry" : null;

            _logger.LogWarning($"Failed login from {Connection.RemoteIpAddress} (Realm: {realm})\n{message}");
            return(NuGetAuthenticationResult.Fail(message, _settings.ServerName, realm));
        }
        protected override async Task <NuGetAuthenticationResult> IsAuthorized(IPackageAuthenticationService authenticationService)
        {
            GetUserCredentials(out var username, out var password);
            var result = await authenticationService.AuthenticateAsync(username, password, default);

            if (!result.Succeeded && string.IsNullOrEmpty(result.Realm))
            {
                return(NuGetAuthenticationResult.Fail(result.Message, result.Server, "AvantiPoint Package Feed"));
            }

            return(result);
        }
        private NuGetAuthenticationResult Authenticate(string apiKey)
        {
            // No authentication is necessary if there is no required API key.
            if (string.IsNullOrEmpty(_apiKey))
            {
                return(NuGetAuthenticationResult.Success());
            }

            if (string.IsNullOrEmpty(apiKey))
            {
                return(NuGetAuthenticationResult.Fail("No Api Token provided.", "AvantiPoint Package Server"));
            }

            return(_apiKey == apiKey?NuGetAuthenticationResult.Success() : NuGetAuthenticationResult.Fail("Invalid Api Token provided.", "AvantiPoint Package Server"));
        }
        public Task <NuGetAuthenticationResult> AuthenticateAsync(string username, string token, CancellationToken cancellationToken)
        {
            var result = username == "skroob" && token == "12345" ? NuGetAuthenticationResult.Success(DemoUser) : NuGetAuthenticationResult.Fail("Invalid username or token", "Demo Authenticated Feed");

            return(Task.FromResult(result));
        }
        public Task <NuGetAuthenticationResult> AuthenticateAsync(string apiKey, CancellationToken cancellationToken)
        {
            var result = apiKey == "12345" ? NuGetAuthenticationResult.Success(DemoUser) : NuGetAuthenticationResult.Fail("Unauthorized apiKey", "Demo Authenticated Feed");

            return(Task.FromResult(result));
        }