using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.AspNet.Authentication.OpenIdConnect; using Microsoft.AspNet.Authentication; using Microsoft.IdentityModel.Protocols.OpenIdConnect; using Microsoft.AspNet.Http; using Microsoft.AspNet.Authentication.Cookies; using Yavsc.Auth; using Microsoft.Extensions.WebEncoders; namespace testOauthClient { public class Startup { public Startup(IHostingEnvironment env) { // Set up configuration sources. var builder = new ConfigurationBuilder() .AddJsonFile("appsettings.json") .AddEnvironmentVariables(); Configuration = builder.Build(); } public IConfigurationRoot Configuration { get; set; } // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.Configure(options => { options.SignInScheme = "Bearer"; }); services.AddTransient(); services.AddAuthentication(); services.AddMvc(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseIISPlatformHandler(options => { options.AuthenticationDescriptions.Clear(); }); app.UseStaticFiles(); app.UseCookieAuthentication(new CookieAuthenticationOptions { AutomaticAuthenticate = true, AutomaticChallenge = true, AuthenticationScheme = "Bearer", CookieName = CookieAuthenticationDefaults.CookiePrefix + "Bearer", ExpireTimeSpan = TimeSpan.FromMinutes(5), LoginPath = new PathString("/signin"), LogoutPath = new PathString("/signout") }); app.UseOAuthAuthentication( options => {  options.AuthenticationScheme = "yavsc"; options.AuthorizationEndpoint="http://dev.pschneider.fr/authorize"; options.TokenEndpoint="http://dev.pschneider.fr/token"; options.AutomaticAuthenticate=true; options.AutomaticChallenge=true; options.CallbackPath=new PathString("/signin-yavsc"); options.ClaimsIssuer="http://dev.pschneider.fr"; options.ClientId="016c5ae4-f4cd-40e3-b250-13701c871ecd"; options.ClientSecret="blahblah"; options.SignInScheme="Bearer"; } ); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); } // Entry point for the application. public static void Main(string[] args) => Microsoft.AspNet.Hosting.WebApplication.Run(args); } }