Example #1
0
        public async Task <UserMo> ValidateUser(string userName, string password)
        {
            var uri = $"{_consulHelper.GetUri("UserService")}/native/user/{userName}";

            try
            {
                var res = await _httpClient.GetStringAsync(uri);

                return(JsonConvert.DeserializeObject <UserMo>(res));
            }
            catch (Exception)
            {
                return(null);
            }
        }
Example #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

            services.AddDbContext <DataContext>(option => option.UseSqlServer(Configuration.GetConnectionString("dbconnection")));

            var          consulClient = new ConsulClient(c => c.Address = new Uri($"http://{ Configuration["Consul:IP"] }:{Configuration["Consul:Port"] }"));
            ConsulHelper helper       = new ConsulHelper(consulClient);

            services.AddAuthentication(Configuration["Identity:Scheme"])
            .AddIdentityServerAuthentication(ops =>
            {
                ops.RequireHttpsMetadata = false;
                //ops.Authority = $"http://{Configuration["Identity:IP"]}:{Configuration["Identity:Port"]}";
                ops.Authority = helper.GetUri("IdentityService");
                ops.ApiName   = Configuration["Service:Name"];
            });

            services.AddSingleton(consulClient);
        }