private static void ConfigureApplication <TOptions>(IApplicationBuilder app, OAuthTests <TOptions> tests) where TOptions : OAuthOptions { // Configure a single HTTP resource that challenges the client if unauthenticated // or returns the logged in user's claims as XML if the request is authenticated. tests.ConfigureApplication(app); app.UseAuthentication(); app.Map("/me", childApp => childApp.Run( async context => { if (context.User.Identity.IsAuthenticated) { string xml = IdentityToXmlString(context.User); byte[] buffer = Encoding.UTF8.GetBytes(xml.ToString()); context.Response.StatusCode = 200; context.Response.ContentType = "text/xml"; await context.Response.Body.WriteAsync(buffer, 0, buffer.Length); } else { await context.ChallengeAsync(); } })); }
private static void ConfigureApplication <TOptions>(IApplicationBuilder app, OAuthTests <TOptions> tests) where TOptions : OAuthOptions { tests.ConfigureApplication(app); // Configure a single HTTP resource that challenges the client if unauthenticated // or returns the logged in user's claims as XML if the request is authenticated. app.UseRouting(); app.UseAuthentication() .UseAuthorization() .UseEndpoints(endpoints => { endpoints.MapGet( "/me", async context => { if (context.User.Identity?.IsAuthenticated == true) { string xml = IdentityToXmlString(context.User); byte[] buffer = Encoding.UTF8.GetBytes(xml); context.Response.StatusCode = 200; context.Response.ContentType = "text/xml"; await context.Response.Body.WriteAsync(buffer, context.RequestAborted); } else { await tests.ChallengeAsync(context); } }); }); }