// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddMvc(); services.AddCors(); services.AddMvcCore() .AddAuthorization() .AddJsonFormatters(); OidcConfiguration oidcConfiguration = IdentityServerConfiguration.GetOidcConfiguration(); services.AddAuthentication(Constant.AuthenticationHeaderPrefix) .AddIdentityServerAuthentication(opt => { opt.Authority = "http://localhost:5000"; opt.RequireHttpsMetadata = false; opt.RoleClaimType = "role"; opt.ApiName = "breadshop"; }); DbContextOptions <BreadShopDatabaseContext> options = new DbContextOptionsBuilder <BreadShopDatabaseContext>() .UseInMemoryDatabase(databaseName: "BreadShopDatabase") .Options; services.AddSingleton(options).AddScoped <BreadShopDatabaseContext>(); services.AddScoped <IProductRepository, ProductRepository>(); services.AddScoped <IProductApplicationService, ProductApplicationService>(); services.AddScoped <IStockRepository, StockRepository>(); services.AddScoped <IStockApplicationService, StockApplicationService>(); }
private static string[] GetAllowableDestinations(OidcConfiguration authConfig, ExternalLinks linksConfig) { var destinations = new List <string>(); if (!string.IsNullOrWhiteSpace(authConfig?.Authority)) { destinations.Add(new Uri(authConfig.Authority).GetLeftPart(UriPartial.Authority)); } if (!string.IsNullOrWhiteSpace(linksConfig?.AccountsHomePage)) { destinations.Add(new Uri(linksConfig.AccountsHomePage).GetLeftPart(UriPartial.Authority)); } if (!string.IsNullOrWhiteSpace(linksConfig?.AccountsDashboardPage)) { destinations.Add(new Uri(linksConfig.AccountsDashboardPage).GetLeftPart(UriPartial.Authority)); } if (!string.IsNullOrWhiteSpace(linksConfig?.AccountsRegistrationPage)) { destinations.Add(new Uri(linksConfig.AccountsRegistrationPage).GetLeftPart(UriPartial.Authority)); } return(destinations.ToArray()); }
private string GetTokenEndpoint(string authorityUrl) { try { string wkEndPointPath = "/.well-known/openid-configuration"; Task <string> task = Task.Run <string>(async() => await client.GetStringAsync(authorityUrl + wkEndPointPath)); OidcConfiguration config = JsonSerializer.Deserialize <OidcConfiguration>(task.Result); return(config.token_endpoint); } catch (HttpRequestException e) { Console.WriteLine("\nException Caught!"); Console.WriteLine("Message :{0} ", e.Message); return(""); } }
public Startup(IConfiguration configuration, IHostingEnvironment env) { Configuration = configuration; _hostingEnvironment = env; _authConfig = Configuration.GetSection("Oidc").Get <OidcConfiguration>(); }