diff --git a/Microsoft.SCIM.WebHostSample/Controllers/TokenController.cs b/Microsoft.SCIM.WebHostSample/Controllers/TokenController.cs index c51f8f80..e5109702 100644 --- a/Microsoft.SCIM.WebHostSample/Controllers/TokenController.cs +++ b/Microsoft.SCIM.WebHostSample/Controllers/TokenController.cs @@ -7,22 +7,29 @@ namespace Microsoft.SCIM.WebHostSample.Controllers using System; using System.IdentityModel.Tokens.Jwt; using System.Text; + using Microsoft.AspNetCore.Hosting; + using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Configuration; + using Microsoft.Extensions.Hosting; using Microsoft.IdentityModel.Tokens; // Controller for generating a bearer token for authorization during testing. // This is not meant to replace proper Oauth for authentication purposes. + [Produces("application/json")] [Route("scim/token")] [ApiController] public class TokenController : ControllerBase { - private readonly IConfiguration configuration; + private readonly IWebHostEnvironment environment; + private readonly IConfiguration configuration; + private const int defaultTokenExpirationTimeInMins = 120; - public TokenController(IConfiguration Configuration) + public TokenController(IWebHostEnvironment env, IConfiguration configuration) { - this.configuration = Configuration; + this.configuration = configuration; + this.environment = env; } private string GenerateJSONWebToken() @@ -52,11 +59,22 @@ private string GenerateJSONWebToken() return result; } + /// + /// Generate a self-signed token for endpoint testing purposes + /// (this method is only available when running in development environment). + /// + /// A self-signed token + /// Returns the self-signed token [HttpGet] + [ProducesResponseType(StatusCodes.Status200OK)] public ActionResult Get() { - string tokenString = this.GenerateJSONWebToken(); - return this.Ok(new { token = tokenString }); + if (this.environment.IsDevelopment()) + { + string tokenString = this.GenerateJSONWebToken(); + return this.Ok(new { token = tokenString }); + } + return new NotFoundResult(); } } diff --git a/Microsoft.SCIM.WebHostSample/Microsoft.SCIM.WebHostSample.csproj b/Microsoft.SCIM.WebHostSample/Microsoft.SCIM.WebHostSample.csproj index 15a8edcb..3823d777 100644 --- a/Microsoft.SCIM.WebHostSample/Microsoft.SCIM.WebHostSample.csproj +++ b/Microsoft.SCIM.WebHostSample/Microsoft.SCIM.WebHostSample.csproj @@ -4,6 +4,15 @@ netcoreapp3.1 + + true + $(NoWarn);1591 + + + + + + diff --git a/Microsoft.SCIM.WebHostSample/Startup.cs b/Microsoft.SCIM.WebHostSample/Startup.cs index 11531c3a..28754feb 100644 --- a/Microsoft.SCIM.WebHostSample/Startup.cs +++ b/Microsoft.SCIM.WebHostSample/Startup.cs @@ -4,6 +4,8 @@ namespace Microsoft.SCIM.WebHostSample { + using System; + using System.Reflection; using System.Text; using System.Threading.Tasks; using Microsoft.AspNetCore.Authentication; @@ -16,6 +18,7 @@ namespace Microsoft.SCIM.WebHostSample using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.IdentityModel.Tokens; + using Microsoft.OpenApi.Models; using Microsoft.SCIM.WebHostSample.Provider; using Newtonsoft.Json; @@ -83,6 +86,33 @@ void ConfigureJwtBearerOptons( JwtBearerOptions options) services.AddAuthentication(ConfigureAuthenticationOptions).AddJwtBearer(ConfigureJwtBearerOptons); services.AddControllers().AddNewtonsoftJson(ConfigureMvcNewtonsoftJsonOptions); + // Register the Swagger generator, defining 1 or more Swagger documents + services.AddSwaggerGen(c => + { + c.SwaggerDoc("v1", new OpenApiInfo + { + Version = "v1", + Title = "SCIM Reference Code", + Description = "The reference code provided in this repository will help you get started building a SCIM endpoint. It contains guidance on how to implement basic requirements for CRUD operations on a user and group object (also known as resources in SCIM) and optional features of the standard such as filtering and pagination.", + Contact = new OpenApiContact + { + Name = "SCIM Reference Code on GitHub", + Email = string.Empty, + Url = new Uri("https://github.com/AzureAD/SCIMReferenceCode/wiki"), + }, + License = new OpenApiLicense + { + Name = "AzureAD/SCIMReferenceCode is licensed under the MIT License", + Url = new Uri("https://github.com/AzureAD/SCIMReferenceCode/blob/master/LICENSE"), + } + }); + + // Set the comments path for the Swagger JSON and UI. + var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; + var xmlPath = System.IO.Path.Combine(AppContext.BaseDirectory, xmlFile); + c.IncludeXmlComments(xmlPath); + }); + services.AddSingleton(typeof(IProvider), this.ProviderBehavior); services.AddSingleton(typeof(IMonitor), this.MonitoringBehavior); } @@ -96,6 +126,21 @@ public void Configure(IApplicationBuilder app) } app.UseHsts(); + + // Enable middleware to serve generated Swagger as a JSON endpoint. + app.UseSwagger(); + + // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.), + // specifying the Swagger JSON endpoint. + app.UseSwaggerUI(c => + { + c.SwaggerEndpoint("/swagger/v1/swagger.json", "SCIM Reference Code V1"); + c.RoutePrefix = string.Empty; + + // Remove "Try it out" button + c.SupportedSubmitMethods(); + }); + app.UseRouting(); app.UseHttpsRedirection(); app.UseAuthentication(); diff --git a/Microsoft.SystemForCrossDomainIdentityManagement/Service/Controllers/RootController.cs b/Microsoft.SystemForCrossDomainIdentityManagement/Service/Controllers/RootController.cs index b5d0320c..e4a1f617 100644 --- a/Microsoft.SystemForCrossDomainIdentityManagement/Service/Controllers/RootController.cs +++ b/Microsoft.SystemForCrossDomainIdentityManagement/Service/Controllers/RootController.cs @@ -4,7 +4,7 @@ namespace Microsoft.SCIM { using System; - public sealed class RootController : ControllerTemplate + internal sealed class RootController : ControllerTemplate { public RootController(IProvider provider, IMonitor monitor) : base(provider, monitor) diff --git a/Microsoft.SystemForCrossDomainIdentityManagement/Service/Controllers/ServiceProviderConfigurationController.cs b/Microsoft.SystemForCrossDomainIdentityManagement/Service/Controllers/ServiceProviderConfigurationController.cs index eb803f24..b50bb45e 100644 --- a/Microsoft.SystemForCrossDomainIdentityManagement/Service/Controllers/ServiceProviderConfigurationController.cs +++ b/Microsoft.SystemForCrossDomainIdentityManagement/Service/Controllers/ServiceProviderConfigurationController.cs @@ -19,6 +19,7 @@ public ServiceProviderConfigurationController(IProvider provider, IMonitor monit { } + [HttpGet] public ServiceConfigurationBase Get() { string correlationIdentifier = null;