/// <summary> /// Adds the Stormpath middleware to the pipeline. /// </summary> /// <remarks>You must call <see cref="AddStormpath(IServiceCollection, object)"/> before calling this method.</remarks> /// <param name="app">The <see cref="IApplicationBuilder" />.</param> /// <returns>A reference to this instance after the operation has completed.</returns> /// <exception cref="InvalidOperationException">The Stormpath services have not been added to the service collection.</exception> public static IApplicationBuilder UseStormpath(this IApplicationBuilder app) { if (app == null) { throw new ArgumentNullException(nameof(app)); } var suppliedConfiguration = app.ApplicationServices.GetRequiredService <UserConfigurationContainer>(); var logger = app.ApplicationServices.GetRequiredService <SDK.Logging.ILogger>(); var hostingAssembly = app.GetType().GetTypeInfo().Assembly; var viewRenderer = new CompositeViewRenderer(logger, new PrecompiledViewRenderer(logger), app.ApplicationServices.GetRequiredService <RazorViewRenderer>()); var stormpathMiddleware = StormpathMiddleware.Create(new StormpathOwinOptions() { LibraryUserAgent = GetLibraryUserAgent(hostingAssembly), Configuration = suppliedConfiguration.Configuration, ViewRenderer = viewRenderer, Logger = logger }); app.UseOwin(addToPipeline => { addToPipeline(next => { stormpathMiddleware.Initialize(next); return(stormpathMiddleware.Invoke); }); }); app.UseMiddleware <StormpathAuthenticationMiddleware>(Options.Create(new StormpathAuthenticationOptions() { AuthenticationScheme = "Cookie" }), logger); app.UseMiddleware <StormpathAuthenticationMiddleware>(Options.Create(new StormpathAuthenticationOptions() { AuthenticationScheme = "Bearer" }), logger); return(app); }
/// <summary> /// Adds the Stormpath middleware to the pipeline. /// </summary> /// <remarks>You must call <c>AddStormpath</c> before calling this method.</remarks> /// <param name="app">The <see cref="IApplicationBuilder" />.</param> /// <returns>A reference to this instance after the operation has completed.</returns> /// <exception cref="InvalidOperationException">The Stormpath services have not been added to the service collection.</exception> public static IApplicationBuilder UseStormpath(this IApplicationBuilder app) { if (app == null) { throw new ArgumentNullException(nameof(app)); } var suppliedConfiguration = app.ApplicationServices.GetRequiredService<OptionsContainer>(); var logger = app.ApplicationServices.GetRequiredService<SDK.Logging.ILogger>(); var hostingAssembly = app.GetType().GetTypeInfo().Assembly; var viewRenderer = new CompositeViewRenderer(logger, new PrecompiledViewRenderer(logger), app.ApplicationServices.GetRequiredService<RazorViewRenderer>()); var options = suppliedConfiguration.Options; options.LibraryUserAgent = GetLibraryUserAgent(hostingAssembly); options.ViewRenderer = viewRenderer; options.Logger = logger; var stormpathMiddleware = StormpathMiddleware.Create(options); app.UseOwin(addToPipeline => { addToPipeline(next => { stormpathMiddleware.Initialize(next); return stormpathMiddleware.Invoke; }); }); app.UseMiddleware<StormpathAuthenticationMiddleware>( Options.Create(new StormpathAuthenticationOptions { AllowedAuthenticationSchemes = new [] { "Cookie", "Bearer" } }), stormpathMiddleware.GetClient(), stormpathMiddleware.Configuration, logger); return app; }