public static async Task SendRequest(string passwordid, Microsoft.Extensions.Logging.LogLevel?logLevel)
        {
            var level = LoggerConfiguration.ReadFromJsonFile("appsettings.json");

            if (logLevel.HasValue)
            {
                level = logLevel.GetValueOrDefault();
            }

            ILoggerFactory loggerFactory = LoggerFactory.Create(builder =>
                                                                builder
                                                                .AddFilter("Password.Vault.Cli.Passwords", level)
                                                                .AddConsole()
                                                                .AddSimpleConsole(options =>
            {
                options.SingleLine      = true;
                options.TimestampFormat = "hh:mm:ss ";
            })

                                                                );

            PasswordConfiguration config = PasswordConfiguration.ReadFromJsonFile("appsettings.json");

            var appConfig = config.PublicClientApplicationOptions;
            var app       = PublicClientApplicationBuilder.CreateWithApplicationOptions(appConfig)
                            .WithDefaultRedirectUri()
                            .Build();

            ILogger <Passwords> logger = loggerFactory.CreateLogger <Passwords>();
            Passwords           p      = new Passwords(app, config, logger);
            await p.GetPasswordHistory(passwordid);
        }
Ejemplo n.º 2
0
        public Passwords(IPublicClientApplication app, PasswordConfiguration config, ILogger <Passwords> logger)
        {
            tokenAcquisitionHelper = new PublicAppUsingDeviceCodeFlow(app);
            protectedApiCallHelper = new ProtectedApiCallHelper <PasswordHistory>(client);

            this.PasswordEndPoint = config.PasswordApiEndpoint;
            this.PasswordApiCode  = config.PasswordApiCode;
            this.Scopes           = new string[] { config.PasswordApiScope };

            _logger = logger;
        }
Ejemplo n.º 3
0
        public static PasswordConfiguration ReadFromJsonFile(string path)
        {
            IConfigurationRoot Configuration;

            var builder = new ConfigurationBuilder()
                          .SetBasePath(AppContext.BaseDirectory)
                          .AddJsonFile(path);

            Configuration = builder.Build();
            PasswordConfiguration config = new PasswordConfiguration()
            {
                PublicClientApplicationOptions = new PublicClientApplicationOptions()
            };

            Configuration.Bind("Authentication", config.PublicClientApplicationOptions);

            config.PasswordApiEndpoint = Configuration.GetValue <string>("PasswordApi:Endpoint");
            config.PasswordApiCode     = Configuration.GetValue <string>("PasswordApi:ApiCode");
            config.PasswordApiScope    = Configuration.GetValue <string>("PasswordApi:Scope");

            return(config);
        }