diff --git a/Microsoft.SCIM.Sample/App.config b/Microsoft.SCIM.Sample/App.config deleted file mode 100644 index dade2946..00000000 --- a/Microsoft.SCIM.Sample/App.config +++ /dev/null @@ -1,74 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Microsoft.SCIM.Sample/Startup.cs b/Microsoft.SCIM.Sample/Startup.cs deleted file mode 100644 index aba08a01..00000000 --- a/Microsoft.SCIM.Sample/Startup.cs +++ /dev/null @@ -1,37 +0,0 @@ -//------------------------------------------------------------ -// Copyright (c) Microsoft Corporation. All rights reserved. -//------------------------------------------------------------ - -#pragma warning disable IDE0065 // Misplaced using directive -#pragma warning restore IDE0065 // Misplaced using directive - -namespace Microsoft.SCIM.Sample -{ - using System; - using Microsoft.SCIM; - - public class Startup - { - private const string baseAddress = "http://localhost:20000"; - - static void Main() - { - Service service = new ServiceProvider(); - service.Start(new Uri(Startup.baseAddress)); - - Console.ReadKey(true); - } - } - - internal class ServiceProvider : Service - { - public override IMonitor MonitoringBehavior { get; set; } - public override IProvider ProviderBehavior { get; set; } - - public ServiceProvider() - { - this.MonitoringBehavior = new ConsoleMonitor(); - this.ProviderBehavior = new InMemoryProvider(); - } - } -} diff --git a/Microsoft.SCIM.WebHostSample/.config/dotnet-tools.json b/Microsoft.SCIM.WebHostSample/.config/dotnet-tools.json new file mode 100644 index 00000000..56e0950c --- /dev/null +++ b/Microsoft.SCIM.WebHostSample/.config/dotnet-tools.json @@ -0,0 +1,12 @@ +{ + "version": 1, + "isRoot": true, + "tools": { + "dotnet-ef": { + "version": "3.1.2", + "commands": [ + "dotnet-ef" + ] + } + } +} \ No newline at end of file diff --git a/Microsoft.SCIM.Sample/Microsoft.SCIM.Sample.csproj b/Microsoft.SCIM.WebHostSample/Microsoft.SCIM.WebHostSample.csproj similarity index 53% rename from Microsoft.SCIM.Sample/Microsoft.SCIM.Sample.csproj rename to Microsoft.SCIM.WebHostSample/Microsoft.SCIM.WebHostSample.csproj index 86f590d8..c279bee5 100644 --- a/Microsoft.SCIM.Sample/Microsoft.SCIM.Sample.csproj +++ b/Microsoft.SCIM.WebHostSample/Microsoft.SCIM.WebHostSample.csproj @@ -1,14 +1,9 @@ - + - Exe netcoreapp3.1 - - DEBUG - - diff --git a/Microsoft.SCIM.WebHostSample/Program.cs b/Microsoft.SCIM.WebHostSample/Program.cs new file mode 100644 index 00000000..aa45c28b --- /dev/null +++ b/Microsoft.SCIM.WebHostSample/Program.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; + +namespace Microsoft.SCIM.WebHostSample +{ + public class Program + { + public static void Main(string[] args) + { + CreateHostBuilder(args).Build().Run(); + } + + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + }); + } +} diff --git a/Microsoft.SCIM.Sample/InMemoryGroupProvider.cs b/Microsoft.SCIM.WebHostSample/Provider/InMemoryGroupProvider.cs similarity index 99% rename from Microsoft.SCIM.Sample/InMemoryGroupProvider.cs rename to Microsoft.SCIM.WebHostSample/Provider/InMemoryGroupProvider.cs index c80c1135..bf39fff2 100644 --- a/Microsoft.SCIM.Sample/InMemoryGroupProvider.cs +++ b/Microsoft.SCIM.WebHostSample/Provider/InMemoryGroupProvider.cs @@ -2,7 +2,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. //------------------------------------------------------------ -namespace Microsoft.SCIM.Sample +namespace Microsoft.SCIM.WebHostSample.Provider { using System; using System.Collections.Generic; @@ -11,7 +11,7 @@ namespace Microsoft.SCIM.Sample using System.Threading.Tasks; using System.Web.Http; using Microsoft.SCIM; - using Microsoft.SCIM.Sample.Properties; + using Microsoft.SCIM.WebHostSample.Resources; public class InMemoryGroupProvider : ProviderBase { diff --git a/Microsoft.SCIM.Sample/InMemoryProvider.cs b/Microsoft.SCIM.WebHostSample/Provider/InMemoryProvider.cs similarity index 98% rename from Microsoft.SCIM.Sample/InMemoryProvider.cs rename to Microsoft.SCIM.WebHostSample/Provider/InMemoryProvider.cs index 0ac17053..8ed0277a 100644 --- a/Microsoft.SCIM.Sample/InMemoryProvider.cs +++ b/Microsoft.SCIM.WebHostSample/Provider/InMemoryProvider.cs @@ -2,7 +2,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. //------------------------------------------------------------ -namespace Microsoft.SCIM.Sample +namespace Microsoft.SCIM.WebHostSample.Provider { using System; using System.Threading.Tasks; diff --git a/Microsoft.SCIM.Sample/InMemoryStorage.cs b/Microsoft.SCIM.WebHostSample/Provider/InMemoryStorage.cs similarity index 95% rename from Microsoft.SCIM.Sample/InMemoryStorage.cs rename to Microsoft.SCIM.WebHostSample/Provider/InMemoryStorage.cs index bde0e4f2..73096b0c 100644 --- a/Microsoft.SCIM.Sample/InMemoryStorage.cs +++ b/Microsoft.SCIM.WebHostSample/Provider/InMemoryStorage.cs @@ -2,7 +2,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. //------------------------------------------------------------ -namespace Microsoft.SCIM.Sample +namespace Microsoft.SCIM.WebHostSample.Provider { using System; using System.Collections.Generic; diff --git a/Microsoft.SCIM.Sample/InMemoryUserProvider.cs b/Microsoft.SCIM.WebHostSample/Provider/InMemoryUserProvider.cs similarity index 98% rename from Microsoft.SCIM.Sample/InMemoryUserProvider.cs rename to Microsoft.SCIM.WebHostSample/Provider/InMemoryUserProvider.cs index f8a58287..306158af 100644 --- a/Microsoft.SCIM.Sample/InMemoryUserProvider.cs +++ b/Microsoft.SCIM.WebHostSample/Provider/InMemoryUserProvider.cs @@ -2,7 +2,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. //------------------------------------------------------------ -namespace Microsoft.SCIM.Sample +namespace Microsoft.SCIM.WebHostSample.Provider { using System; using System.Collections.Generic; @@ -11,7 +11,7 @@ namespace Microsoft.SCIM.Sample using System.Threading.Tasks; using System.Web.Http; using Microsoft.SCIM; - using Microsoft.SCIM.Sample.Properties; + using Microsoft.SCIM.WebHostSample.Resources; public class InMemoryUserProvider : ProviderBase { diff --git a/Microsoft.SCIM.Sample/Properties/SampleServiceResources.Designer.cs b/Microsoft.SCIM.WebHostSample/Resources/SampleServiceResources.Designer.cs similarity index 98% rename from Microsoft.SCIM.Sample/Properties/SampleServiceResources.Designer.cs rename to Microsoft.SCIM.WebHostSample/Resources/SampleServiceResources.Designer.cs index 1e4ab2c1..ee68a48c 100644 --- a/Microsoft.SCIM.Sample/Properties/SampleServiceResources.Designer.cs +++ b/Microsoft.SCIM.WebHostSample/Resources/SampleServiceResources.Designer.cs @@ -8,7 +8,7 @@ // //------------------------------------------------------------------------------ -namespace Microsoft.SCIM.Sample.Properties { +namespace Microsoft.SCIM.WebHostSample.Resources { using System; diff --git a/Microsoft.SCIM.Sample/Properties/SampleServiceResources.resx b/Microsoft.SCIM.WebHostSample/Resources/SampleServiceResources.resx similarity index 100% rename from Microsoft.SCIM.Sample/Properties/SampleServiceResources.resx rename to Microsoft.SCIM.WebHostSample/Resources/SampleServiceResources.resx diff --git a/Microsoft.SCIM.WebHostSample/Startup.cs b/Microsoft.SCIM.WebHostSample/Startup.cs new file mode 100644 index 00000000..e816dc55 --- /dev/null +++ b/Microsoft.SCIM.WebHostSample/Startup.cs @@ -0,0 +1,82 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Authentication.JwtBearer; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Routing; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Microsoft.IdentityModel.Tokens; +using Microsoft.SCIM.WebHostSample.Provider; + +namespace Microsoft.SCIM.WebHostSample +{ + public class Startup + { + public IMonitor MonitoringBehavior { get; set; } + public IProvider ProviderBehavior { get; set; } + + public Startup() + { + this.MonitoringBehavior = new ConsoleMonitor(); + this.ProviderBehavior = new InMemoryProvider(); + } + + // 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.AddAuthentication(options => + { + options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; + options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; + options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; + }) + .AddJwtBearer(options => + { + options.TokenValidationParameters = + new TokenValidationParameters + { + ValidateIssuer = false, + ValidateAudience = false, + ValidateLifetime = false, + ValidateIssuerSigningKey = false, + ValidIssuer = ServiceConstants.TokenIssuer, + ValidAudience = ServiceConstants.TokenAudience, + IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(ServiceConstants.TokenIssuer)) + }; + }); + + services.AddControllers().AddNewtonsoftJson(); + + services.AddSingleton(typeof(IProvider), this.ProviderBehavior); + services.AddSingleton(typeof(IMonitor), this.MonitoringBehavior); + } + + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + { + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + } + + app.UseHsts(); + + app.UseRouting(); + app.UseHttpsRedirection(); + app.UseAuthentication(); + app.UseAuthorization(); + + app.UseEndpoints( + (IEndpointRouteBuilder endpoints) => + { + endpoints.MapDefaultControllerRoute(); + }); + } + } +} diff --git a/Microsoft.SCIM.WebHostSample/appsettings.Development.json b/Microsoft.SCIM.WebHostSample/appsettings.Development.json new file mode 100644 index 00000000..8983e0fc --- /dev/null +++ b/Microsoft.SCIM.WebHostSample/appsettings.Development.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git a/Microsoft.SCIM.WebHostSample/appsettings.json b/Microsoft.SCIM.WebHostSample/appsettings.json new file mode 100644 index 00000000..d9d9a9bf --- /dev/null +++ b/Microsoft.SCIM.WebHostSample/appsettings.json @@ -0,0 +1,10 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + }, + "AllowedHosts": "*" +} diff --git a/Microsoft.SCIM.sln b/Microsoft.SCIM.sln index b29370a0..fff9b0ca 100644 --- a/Microsoft.SCIM.sln +++ b/Microsoft.SCIM.sln @@ -5,7 +5,7 @@ VisualStudioVersion = 16.0.29709.97 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.SCIM", "Microsoft.SystemForCrossDomainIdentityManagement\Microsoft.SCIM.csproj", "{C9ED6410-1995-4B98-AD57-C02D5F16631C}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.SCIM.Sample", "Microsoft.SCIM.Sample\Microsoft.SCIM.Sample.csproj", "{06220587-471C-4AB0-BBB6-F1D9E35DBDDF}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.SCIM.WebHostSample", "Microsoft.SCIM.WebHostSample\Microsoft.SCIM.WebHostSample.csproj", "{238F1B05-D3EE-4AB4-871E-ADEA0A1665CF}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -17,10 +17,10 @@ Global {C9ED6410-1995-4B98-AD57-C02D5F16631C}.Debug|Any CPU.Build.0 = Debug|Any CPU {C9ED6410-1995-4B98-AD57-C02D5F16631C}.Release|Any CPU.ActiveCfg = Release|Any CPU {C9ED6410-1995-4B98-AD57-C02D5F16631C}.Release|Any CPU.Build.0 = Release|Any CPU - {06220587-471C-4AB0-BBB6-F1D9E35DBDDF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {06220587-471C-4AB0-BBB6-F1D9E35DBDDF}.Debug|Any CPU.Build.0 = Debug|Any CPU - {06220587-471C-4AB0-BBB6-F1D9E35DBDDF}.Release|Any CPU.ActiveCfg = Release|Any CPU - {06220587-471C-4AB0-BBB6-F1D9E35DBDDF}.Release|Any CPU.Build.0 = Release|Any CPU + {238F1B05-D3EE-4AB4-871E-ADEA0A1665CF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {238F1B05-D3EE-4AB4-871E-ADEA0A1665CF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {238F1B05-D3EE-4AB4-871E-ADEA0A1665CF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {238F1B05-D3EE-4AB4-871E-ADEA0A1665CF}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Microsoft.SystemForCrossDomainIdentityManagement/Service/Service.cs b/Microsoft.SystemForCrossDomainIdentityManagement/Service/Service.cs deleted file mode 100644 index 9d1c3632..00000000 --- a/Microsoft.SystemForCrossDomainIdentityManagement/Service/Service.cs +++ /dev/null @@ -1,76 +0,0 @@ -//------------------------------------------------------------ -// Copyright (c) Microsoft Corporation. All rights reserved. -//------------------------------------------------------------ - -namespace Microsoft.SCIM -{ - using System; - using System.IO; - using Microsoft.AspNetCore.Hosting; - using Microsoft.Extensions.DependencyInjection; - - public abstract class Service : IDisposable - { - private readonly object thisLock = new object(); - private IDisposable webHost; - - public abstract IMonitor MonitoringBehavior { get; set; } - public abstract IProvider ProviderBehavior { get; set; } - - public void Dispose() - { - this.Dispose(true); - GC.SuppressFinalize(this); - } - - protected virtual void Dispose(bool disposing) - { - if (this.webHost != null) - { - lock (this.thisLock) - { - if (this.webHost != null) - { - this.webHost.Dispose(); - this.webHost = null; - } - } - } - } - - public void Start(Uri baseAddress) - { - if (null == baseAddress) - { - throw new ArgumentNullException(nameof(baseAddress)); - } - - if (null == this.ProviderBehavior) - { - throw new InvalidOperationException(SystemForCrossDomainIdentityManagementServiceResources.ExceptionNotInitializedProviderBehavior); - } - - if (null == this.MonitoringBehavior) - { - throw new InvalidOperationException(SystemForCrossDomainIdentityManagementServiceResources.ExceptionNotInitializedMonitoringBehavior); - } - - lock (this.thisLock) - { - IWebHost host = - new WebHostBuilder() - .UseKestrel() - .UseContentRoot(Directory.GetCurrentDirectory()) - .ConfigureServices(services => - { - services.AddSingleton(typeof(IProvider), this.ProviderBehavior); - services.AddSingleton(typeof(IMonitor), this.MonitoringBehavior); - }) - .UseStartup() - .Build(); - - host.Run(); - } - } - } -} diff --git a/Microsoft.SystemForCrossDomainIdentityManagement/Service/ServiceConstants.cs b/Microsoft.SystemForCrossDomainIdentityManagement/Service/ServiceConstants.cs index 2fe8ac7b..44147915 100644 --- a/Microsoft.SystemForCrossDomainIdentityManagement/Service/ServiceConstants.cs +++ b/Microsoft.SystemForCrossDomainIdentityManagement/Service/ServiceConstants.cs @@ -20,7 +20,7 @@ public static class ServiceConstants public const string SeparatorSegments = "/"; - internal const string TokenAudience = "Microsoft.Security.Bearer"; - internal const string TokenIssuer = "Microsoft.Security.Bearer"; + public const string TokenAudience = "Microsoft.Security.Bearer"; + public const string TokenIssuer = "Microsoft.Security.Bearer"; } } \ No newline at end of file diff --git a/Microsoft.SystemForCrossDomainIdentityManagement/Service/WebApplicationStarter.cs b/Microsoft.SystemForCrossDomainIdentityManagement/Service/WebApplicationStarter.cs deleted file mode 100644 index 5bb4ff02..00000000 --- a/Microsoft.SystemForCrossDomainIdentityManagement/Service/WebApplicationStarter.cs +++ /dev/null @@ -1,67 +0,0 @@ -//---------------------------------------------------------------- -// Copyright (c) Microsoft Corporation. All rights reserved. -//---------------------------------------------------------------- - -namespace Microsoft.SCIM -{ - using System; - using System.Text; - using Microsoft.AspNetCore.Authentication.JwtBearer; - using Microsoft.AspNetCore.Builder; - using Microsoft.AspNetCore.Routing; - using Microsoft.Extensions.Configuration; - using Microsoft.Extensions.DependencyInjection; - using Microsoft.IdentityModel.Tokens; - - public class WebApplicationStarter - { - public WebApplicationStarter(IConfiguration configuration) - { - this.Configuration = configuration; - } - - public IConfiguration Configuration { get; } - - public static void ConfigureServices(IServiceCollection services) - { - services.AddAuthentication(options => - { - options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; - options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; - options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; - }) - .AddJwtBearer(options => - { - options.TokenValidationParameters = - new TokenValidationParameters - { - ValidateIssuer = false, - ValidateAudience = false, - ValidateLifetime = false, - ValidateIssuerSigningKey = false, - ValidIssuer = ServiceConstants.TokenIssuer, - ValidAudience = ServiceConstants.TokenAudience, - IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(ServiceConstants.TokenIssuer)) - }; - }); - - services.AddControllers().AddNewtonsoftJson(); - } - - public static void Configure(IApplicationBuilder applicationBuilder) - { - applicationBuilder.UseHsts(); - - applicationBuilder.UseRouting(); - //app.UseHttpsRedirection(); - //app.UseAuthentication(); - //app.UseAuthorization(); - - applicationBuilder.UseEndpoints( - (IEndpointRouteBuilder endpoints) => - { - endpoints.MapDefaultControllerRoute(); - }); - } - } -}