// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var jwtSettings = new Logic.Options.JWTSettings(); Configuration.GetSection("JWTSettings").Bind(jwtSettings); services.AddSingleton(jwtSettings); var sessionCookieLifetime = Configuration.GetValue("SessionCookieLifetime", 60); services.AddScoped <IToken, TokenRepo>(); services.AddScoped <IUser, UserRepo>(); services.AddScoped <IUserInterfaces, UserService>(); var facebookSettings = new Repository.FacebookSettings.FacebookAuthSettings(); Configuration.GetSection("FacebookAuthSettings").Bind(facebookSettings); services.AddSingleton(facebookSettings); services.AddHttpClient("APIClient", client => { client.BaseAddress = new Uri("https://localhost:5201/"); client.DefaultRequestHeaders.Clear(); client.DefaultRequestHeaders.Add(HeaderNames.Accept, "application/json"); }); services.AddSingleton <IFacebookInterface, FacebookRepo>(); services.AddRouting(); services.AddControllersWithViews().AddNewtonsoftJson(options => options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore); var tokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters { ValidateIssuerSigningKey = true, IssuerSigningKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(jwtSettings.Secret)), ValidateIssuer = false, ValidateAudience = false, RequireExpirationTime = false, ValidateLifetime = true, }; services.AddSingleton(tokenValidationParameters); services.AddAuthentication(option => { option.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme; option.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme; } ).AddJwtBearer(x => { x.SaveToken = true; x.TokenValidationParameters = tokenValidationParameters; } ).AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, setup => setup.ExpireTimeSpan = TimeSpan.FromMinutes(sessionCookieLifetime) ).AddOpenIdConnect(OpenIdConnectDefaults.AuthenticationScheme, option => { option.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme; option.Authority = "https://localhost:5101/"; option.ClientId = "pokolokoshop"; option.ResponseType = "code"; option.UsePkce = false; option.Scope.Add("openid"); option.Scope.Add("profile"); option.SaveTokens = true; option.ClientSecret = "secret"; //option.CallbackPath = new PathString("..."); }); services.AddControllers(); services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); }
public ApiController(IUserInterfaces userSevice, Logic.Options.JWTSettings jWTSettings, IHostingEnvironment env) { _userService = userSevice; _env = env; _jwtSttings = jWTSettings; }