public string GetBaseURL(string apiType) { var panacheSoftwareConfiguration = new PanacheSoftwareConfiguration(); _configuration.Bind("PanacheSoftware", panacheSoftwareConfiguration); //If appsttings specifies we should use the API gateway force all API requests through their if (bool.Parse(panacheSoftwareConfiguration.CallMethod.UseAPIGateway)) { return(bool.Parse(panacheSoftwareConfiguration.CallMethod.APICallsSecure) ? panacheSoftwareConfiguration.Url.APIGatewayURLSecure : panacheSoftwareConfiguration.Url.APIGatewayURL); } //Otherwise return the URL specific to the APIType passed in switch (apiType) { case APITypes.CLIENT: return(bool.Parse(panacheSoftwareConfiguration.CallMethod.APICallsSecure) ? panacheSoftwareConfiguration.Url.ClientServiceURLSecure : panacheSoftwareConfiguration.Url.ClientServiceURL); case APITypes.FILE: return(bool.Parse(panacheSoftwareConfiguration.CallMethod.APICallsSecure) ? panacheSoftwareConfiguration.Url.FileServiceURLSecure : panacheSoftwareConfiguration.Url.FileServiceURL); case APITypes.FOUNDATION: return(bool.Parse(panacheSoftwareConfiguration.CallMethod.APICallsSecure) ? panacheSoftwareConfiguration.Url.FoundationServiceURLSecure : panacheSoftwareConfiguration.Url.FoundationServiceURL); case APITypes.GATEWAY: return(bool.Parse(panacheSoftwareConfiguration.CallMethod.APICallsSecure) ? panacheSoftwareConfiguration.Url.APIGatewayURLSecure : panacheSoftwareConfiguration.Url.APIGatewayURL); case APITypes.IDENTITY: return(bool.Parse(panacheSoftwareConfiguration.CallMethod.APICallsSecure) ? panacheSoftwareConfiguration.Url.IdentityServerURLSecure : panacheSoftwareConfiguration.Url.IdentityServerURL); case APITypes.TASK: return(bool.Parse(panacheSoftwareConfiguration.CallMethod.APICallsSecure) ? panacheSoftwareConfiguration.Url.TaskServiceURLSecure : panacheSoftwareConfiguration.Url.TaskServiceURL); case APITypes.TEAM: return(bool.Parse(panacheSoftwareConfiguration.CallMethod.APICallsSecure) ? panacheSoftwareConfiguration.Url.TeamServiceURLSecure : panacheSoftwareConfiguration.Url.TeamServiceURL); case APITypes.UICLIENT: return(bool.Parse(panacheSoftwareConfiguration.CallMethod.APICallsSecure) ? panacheSoftwareConfiguration.Url.UIClientURLSecure : panacheSoftwareConfiguration.Url.UIClientURL); } return(string.Empty); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { //services.AddAuthentication(IdentityServerAuthenticationDefaults.AuthenticationScheme) // .AddIdentityServerAuthentication(options => // { // // base-address of your identityserver // options.Authority = "https://localhost:44397/"; // // name of the API resource // options.ApiName = PanacheSoftwareScopeNames.APIGateway; // options.ApiSecret = "DDDCB193-213C-43FB-967A-5A911D2EFC04"; // options.RequireHttpsMetadata = false; // options.EnableCaching = true; // }); var panacheSoftwareConfiguration = new PanacheSoftwareConfiguration(); Configuration.Bind("PanacheSoftware", panacheSoftwareConfiguration); var authenticationProviderKey = "GatewayKey"; Action <IdentityServerAuthenticationOptions> options = o => { o.Authority = bool.Parse(panacheSoftwareConfiguration.CallMethod.UICallsSecure) ? panacheSoftwareConfiguration.Url.IdentityServerURLSecure : panacheSoftwareConfiguration.Url.IdentityServerURL; o.ApiName = PanacheSoftwareScopeNames.APIGateway; o.SupportedTokens = SupportedTokens.Both; o.ApiSecret = panacheSoftwareConfiguration.Secret.APIGatewaySecret; }; services.AddAuthentication() .AddIdentityServerAuthentication(authenticationProviderKey, options); services.AddControllers(); services.AddOcelot(Configuration); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { string connectionString = Configuration.GetConnectionString("DefaultConnection"); services.AddDbContext <PanacheSoftwareServiceTaskContext>(options => options.UseSqlServer(connectionString)); services.AddAuthorization(); var panacheSoftwareConfiguration = new PanacheSoftwareConfiguration(); Configuration.Bind("PanacheSoftware", panacheSoftwareConfiguration); services.AddAuthentication(IdentityServerAuthenticationDefaults.AuthenticationScheme) .AddIdentityServerAuthentication(options => { // base-address of your identityserver options.Authority = bool.Parse(panacheSoftwareConfiguration.CallMethod.UICallsSecure) ? panacheSoftwareConfiguration.Url.IdentityServerURLSecure : panacheSoftwareConfiguration.Url.IdentityServerURL; // name of the API resource options.ApiName = PanacheSoftwareScopeNames.TaskService; options.ApiSecret = panacheSoftwareConfiguration.Secret.TaskServiceSecret; options.RequireHttpsMetadata = false; //options.EnableCaching = true; }); //services.AddAuthentication("Bearer") // .AddJwtBearer("Bearer", options => // { // options.Authority = "https://localhost:44397/"; // options.RequireHttpsMetadata = false; // options.Audience = PanacheSoftwareScopeNames.FolderService; // }); services.AddMvc(options => { options.EnableEndpointRouting = false; }) .SetCompatibilityVersion(CompatibilityVersion.Version_3_0); services.AddTransient <IUnitOfWork, UnitOfWork>(); services.AddTransient <ITaskGroupDetailRepository, TaskGroupDetailRepository>(); services.AddTransient <ITaskGroupHeaderRepository, TaskGroupHeaderRepository>(); services.AddTransient <ITaskHeaderRepository, TaskHeaderRepository>(); services.AddTransient <ITaskDetailRepository, TaskDetailRepository>(); services.AddTransient <ITaskManager, TaskManager>(); services.AddTransient <IUserProvider, UserProvider>(); services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); services.AddSingleton <IAPIHelper, APIHelper>(); services.AddHostedService <MigrationHostedService>(); services.AddAutoMapper(System.Reflection.Assembly.Load("PanacheSoftware.Core")); services.AddControllersWithViews().AddNewtonsoftJson(); }
public async Task <IdentityResult> CheckSeed() { var panacheSoftwareConfiguration = new PanacheSoftwareConfiguration(); _configuration.Bind("PanacheSoftware", panacheSoftwareConfiguration); var admin = _userManager.FindByNameAsync($"admin@{panacheSoftwareConfiguration.StartDomain}").Result; if (admin == null) { var adminUser = new UserModel() { Id = Guid.Empty, FirstName = "Admin", Surname = "User", FullName = "Admin User", Email = $"admin@{panacheSoftwareConfiguration.StartDomain}", Status = StatusTypes.Open, DateFrom = DateTime.Now, DateTo = DateTime.Now.AddYears(99), Description = "Admin User", Base64ProfileImage = Base64Images.PanacheSoftwareDot }; var identityTenant = new IdentityTenant() { Domain = panacheSoftwareConfiguration.StartDomain, CreatedByEmail = $"admin@{panacheSoftwareConfiguration.StartDomain}", Description = "Default tenant" }; if (CreateTenant(identityTenant) != null) { return(await CreateUserAsync(adminUser, new ModelStateDictionary(), "Passw0rd123!", "Passw0rd123!", identityTenant.Id)); } IdentityErrorDescriber identityError = new IdentityErrorDescriber(); return(IdentityResult.Failed(identityError.InvalidUserName($"admin@{panacheSoftwareConfiguration.StartDomain}"))); } return(IdentityResult.Success); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { string connectionString = Configuration.GetConnectionString("DefaultConnection"); services.AddDbContext <PanacheSoftwareServiceFoundationContext>(options => options.UseSqlServer(connectionString)); services.AddMvc(options => { options.EnableEndpointRouting = false; }) .SetCompatibilityVersion(CompatibilityVersion.Version_3_0); services.AddAuthorization(); var panacheSoftwareConfiguration = new PanacheSoftwareConfiguration(); Configuration.Bind("PanacheSoftware", panacheSoftwareConfiguration); //JwtSecurityTokenHandler.DefaultMapInboundClaimTypes = true; //JwtSecurityTokenHandler.DefaultMapInboundClaims = true; //JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear(); services.AddAuthentication(IdentityServerAuthenticationDefaults.AuthenticationScheme) .AddIdentityServerAuthentication(options => { // base-address of your identityserver options.Authority = bool.Parse(panacheSoftwareConfiguration.CallMethod.UICallsSecure) ? panacheSoftwareConfiguration.Url.IdentityServerURLSecure : panacheSoftwareConfiguration.Url.IdentityServerURL; // name of the API resource options.ApiName = PanacheSoftwareScopeNames.FoundationService; options.ApiSecret = panacheSoftwareConfiguration.Secret.FoundationServiceSecret; options.RequireHttpsMetadata = false; //options.EnableCaching = true; }); //services.AddAuthentication("Bearer") // .AddJwtBearer("Bearer", options => // { // options.Authority = "https://localhost:44397/"; // options.RequireHttpsMetadata = false; // options.Audience = PanacheSoftwareScopeNames.FoundationService; // }); //services.AddDbContext<PanacheSoftwareServiceClientContext>(options => // options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); services.AddTransient <IUnitOfWork, UnitOfWork>(); services.AddTransient <ILanguageHeaderRepository, LanguageHeaderRepository>(); services.AddTransient <ILanguageCodeRepository, LanguageCodeRepository>(); services.AddTransient <ILanguageItemRepository, LanguageItemRepository>(); services.AddTransient <ISettingHeaderRepository, SettingHeaderRepository>(); services.AddTransient <IUserSettingRepository, UserSettingRepository>(); services.AddTransient <IUserProvider, UserProvider>(); services.AddTransient <IStaticFileReader, StaticFileReader>(); services.AddTransient <IHttpContextAccessor, HttpContextAccessor>(); services.AddHostedService <MigrationHostedService>(); services.AddAutoMapper(System.Reflection.Assembly.Load("PanacheSoftware.Core")); services.AddControllersWithViews().AddNewtonsoftJson(); services.AddSwaggerGen(c => { //c.SwaggerDoc("v1", new OpenApiInfo { Title = "Panache Software Foundation API", Version = "v1" }); //var filePath = Path.Combine(System.AppContext.BaseDirectory, "PanacheSoftware.Service.Foundation.xml"); //c.IncludeXmlComments(filePath); c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme { Description = "JWT Authorization header using the Bearer scheme. \r\n\r\n Enter 'Bearer' [space] and then your token in the text input below.\r\n\r\nExample: \"Bearer 12345abcdef\"", Name = "Authorization", In = ParameterLocation.Header, Type = SecuritySchemeType.ApiKey, Scheme = "Bearer" }); c.AddSecurityRequirement(new OpenApiSecurityRequirement() { { new OpenApiSecurityScheme { Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = "Bearer" }, Scheme = "oauth2", Name = "Bearer", In = ParameterLocation.Header, }, new List <string>() } }); }); }
// This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { services.Configure <CookiePolicyOptions>(options => { // This lambda determines whether user consent for non-essential cookies is needed for a given request. options.CheckConsentNeeded = context => true; options.MinimumSameSitePolicy = SameSiteMode.None; }); services.AddMvc(options => { options.EnableEndpointRouting = false; }) .SetCompatibilityVersion(CompatibilityVersion.Version_3_0) //.AddRazorPagesOptions(options => //{ // options.AllowAreas = false; //}) .ConfigureApiBehaviorOptions(options => { options.SuppressModelStateInvalidFilter = true; //options.SuppressUseValidationProblemDetailsForInvalidModelStateResponses = true; }); JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear(); var panacheSoftwareConfiguration = new PanacheSoftwareConfiguration(); Configuration.Bind("PanacheSoftware", panacheSoftwareConfiguration); services.AddAuthentication(options => { options.DefaultScheme = "Cookies"; options.DefaultChallengeScheme = "oidc"; }) .AddCookie("Cookies") .AddOpenIdConnect("oidc", options => { options.SignInScheme = "Cookies"; options.Authority = bool.Parse(panacheSoftwareConfiguration.CallMethod.UICallsSecure) ? panacheSoftwareConfiguration.Url.IdentityServerURLSecure : panacheSoftwareConfiguration.Url.IdentityServerURL; options.RequireHttpsMetadata = false; options.ClientId = PanacheSoftwareScopeNames.ClientUI; options.ClientSecret = panacheSoftwareConfiguration.Secret.UIClientSecret; //options.ResponseType = "code id_token"; options.ResponseType = "code"; options.UsePkce = true; options.SaveTokens = true; options.GetClaimsFromUserInfoEndpoint = true; options.Scope.Add("openid"); options.Scope.Add("offline_access"); options.Scope.Add("email"); options.Scope.Add("IdentityServerApi"); options.Scope.Add(PanacheSoftwareScopeNames.IdentityResourceProfile); options.Scope.Add(PanacheSoftwareScopeNames.ClientService); options.Scope.Add(PanacheSoftwareScopeNames.TeamService); options.Scope.Add(PanacheSoftwareScopeNames.FoundationService); options.Scope.Add(PanacheSoftwareScopeNames.TaskService); options.Scope.Add(PanacheSoftwareScopeNames.FileService); options.Scope.Add(PanacheSoftwareScopeNames.APIGateway); options.ClaimActions.MapUniqueJsonKey("tenantid", "tenantid"); }); services.AddSingleton <IAPIHelper, APIHelper>(); services.AddTransient <IRazorPartialToStringRenderer, RazorPartialToStringRenderer>(); services.AddTransient <IModelHelper, ModelHelper>(); services.AddAutoMapper(System.Reflection.Assembly.Load("PanacheSoftware.Core")); }
public Config(PanacheSoftwareConfiguration panacheSoftwareConfiguration) { _panacheSoftwareConfiguration = panacheSoftwareConfiguration; }
public async Task <IdentityResult> CreateUserAsync(UserModel userModel, ModelStateDictionary modelState, string password, string passwordConfirm, Guid tenantId) { var passwordsMatch = ValidatePasswordsMatch(password, passwordConfirm); IdentityErrorDescriber identityError = new IdentityErrorDescriber(); if (!passwordsMatch.Succeeded) { modelState.AddModelError("password", passwordsMatch.Errors.First().Description); modelState.AddModelError("passwordConfirm", passwordsMatch.Errors.First().Description); return(IdentityResult.Failed(identityError.PasswordMismatch())); } var newUser = _mapper.Map <ApplicationUser>(userModel); var identityTenant = GetTenant(tenantId, string.Empty); if (identityTenant != null) { MailAddress foundEmail = new MailAddress(newUser.Email); if (foundEmail != null) { if (identityTenant.Domain == foundEmail.Host) { var result = await _userManager.CreateAsync(newUser, password); if (!result.Succeeded) { AddErrorsToModel(result, modelState); } else { var panacheSoftwareConfiguration = new PanacheSoftwareConfiguration(); _configuration.Bind("PanacheSoftware", panacheSoftwareConfiguration); var UIClientURL = bool.Parse(panacheSoftwareConfiguration.CallMethod.UICallsSecure) ? panacheSoftwareConfiguration.Url.UIClientURLSecure : panacheSoftwareConfiguration.Url.UIClientURL; result = _userManager.AddClaimsAsync(newUser, new Claim[] { new Claim(JwtClaimTypes.Name, newUser.FullName), new Claim(JwtClaimTypes.GivenName, newUser.FirstName), new Claim(JwtClaimTypes.FamilyName, newUser.Surname), new Claim(JwtClaimTypes.Email, newUser.Email), new Claim(JwtClaimTypes.WebSite, $"{UIClientURL}/User/{newUser.Id}"), new Claim(JwtClaimTypes.Picture, $"{UIClientURL}/User/{newUser.Id}/ProfileImage"), new Claim(PanacheSoftwareClaims.TenantId, identityTenant.Id.ToString()) }).Result; if (!result.Succeeded) { throw new Exception(result.Errors.First().Description); } else { userModel.Id = newUser.Id; } } return(result); } } } return(IdentityResult.Failed(identityError.InvalidUserName(newUser.Email))); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { //Connect to the Database services.AddDbContext <ApplicationDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")) ); services.AddIdentity <ApplicationUser, ApplicationRole>() .AddEntityFrameworkStores <ApplicationDbContext>() .AddDefaultTokenProviders(); services.AddMvc(options => { options.EnableEndpointRouting = false; }) .SetCompatibilityVersion(CompatibilityVersion.Version_3_0) //.AddRazorPagesOptions(options => //{ // options.AllowAreas = false; //}) .ConfigureApiBehaviorOptions(options => { options.SuppressModelStateInvalidFilter = true; //options.SuppressUseValidationProblemDetailsForInvalidModelStateResponses = true; }); var panacheSoftwareConfiguration = new PanacheSoftwareConfiguration(); Configuration.Bind("PanacheSoftware", panacheSoftwareConfiguration); var identityServerConfig = new Config(panacheSoftwareConfiguration); var builder = services.AddIdentityServer(options => { options.Events.RaiseErrorEvents = true; options.Events.RaiseInformationEvents = true; options.Events.RaiseFailureEvents = true; options.Events.RaiseSuccessEvents = true; }) .AddInMemoryIdentityResources(identityServerConfig.GetIdentityResources()) .AddInMemoryApiScopes(identityServerConfig.GetApiScopes()) .AddInMemoryApiResources(identityServerConfig.GetApis()) .AddInMemoryClients(identityServerConfig.GetClients()) .AddAspNetIdentity <ApplicationUser>() .AddInMemoryPersistedGrants() .AddInMemoryCaching(); services.Configure <CookiePolicyOptions>(options => { // This lambda determines whether user consent for non-essential cookies is needed for a given request. options.CheckConsentNeeded = context => true; options.MinimumSameSitePolicy = SameSiteMode.None; }); services.AddAutoMapper(System.Reflection.Assembly.Load("PanacheSoftware.Core")); if (Environment.IsDevelopment()) { builder.AddDeveloperSigningCredential(); } else { throw new Exception("need to configure key material"); } services.AddAuthentication(); services.AddLocalApiAuthentication(); services.AddTransient <IApplicationUserManager, ApplicationUserManager>(); services.AddTransient <IUserProvider, UserProvider>(); services.AddTransient <IAPIHelper, APIHelper>(); //services.AddScoped<APIModelValidate>(); services.AddHostedService <MigrationHostedService>(); services.AddControllersWithViews().AddNewtonsoftJson(); //services.AddScoped<IProfileService, ProfileService>(); }