public Task Invoke(HttpContext httpContext)
        {
            var userName = httpContext.User?.Identity.Name;

            if (string.IsNullOrEmpty(userName))
            {
                userName = "******";
            }

            httpContext.Response.ContentType = "text/html";
            httpContext.Response.WriteAsync(
                $@"<!DOCTYPE html>
                   <html>
                      <head>
                         <meta charset=""utf-8"">
                         <title>{ApiName}</title>
                      </head>
                      <body style=""font-family: Segoe UI"">
                        <div><strong>{ApiName}</strong></div>
                        <div>Hello {userName}, welcome. See the API documentation <a href=""/swagger"">here</a></div>");

            httpContext.Response.WriteAsync(_stuntmanOptions.UserPicker(httpContext.User ?? new ClaimsPrincipal()));
            httpContext.Response.WriteAsync(@"</body></html>");

            return(Task.FromResult(true));
        }
示例#2
0
        public void Configuration(IAppBuilder app)
        {
            StuntmanOptions
            .EnableServer()
            .AddUser(new StuntmanUser("user-1", "User 1")
                     .SetAccessToken("user-1-token")
                     .SetDescription("This is User 1.")
                     .AddClaim("given_name", "John")
                     .AddClaim("family_name", "Doe"))
            .AddUser(new StuntmanUser("user-2", "User 2")
                     .AddClaim("given_name", "Jane")
                     .AddClaim("family_name", "Doe"))
            .AddUser(new StuntmanUser("user-3", "User 3")
                     .AddClaim("given_name", "Sam")
                     .AddClaim("family_name", "Smith"))
            //.AddUsersFromJson("https://raw.githubusercontent.com/ritterim/stuntman/master/samples/UsageSample.AspNetCore/test-server-response-1.json")
            .AddUsersFromJson(Path.Combine(GetBinPath(), "test-server-response-2.json"));

            app.UseStuntman(StuntmanOptions);

            app.Map("/secure", secure =>
            {
                AuthenticateAllRequests(secure, new[] { "StuntmanAuthentication" });

                secure.Run(context =>
                {
                    var userName = context.Request.User.Identity.Name;

                    if (string.IsNullOrEmpty(userName))
                    {
                        userName = "******";
                    }

                    context.Response.ContentType = "text/html";
                    context.Response.WriteAsync(
                        $"Hello, {userName}. This is the /secure endpoint.");

                    context.Response.WriteAsync(
                        StuntmanOptions.UserPicker(context.Request.User));

                    return(Task.FromResult(true));
                });
            });

            app.Map("/secure-json", secure =>
            {
                AuthenticateAllRequests(secure, new[] { "StuntmanAuthentication" });

                secure.Run(context =>
                {
                    var userName = context.Request.User.Identity.Name;

                    if (string.IsNullOrEmpty(userName))
                    {
                        userName = "******";
                    }

                    context.Response.ContentType = "application/json";
                    context.Response.WriteAsync(
                        $@"{{""message"":""Hello, {userName}. This is the /secure-json endpoint.""}}");

                    return(Task.FromResult(true));
                });
            });

            app.Map("/logout", logout =>
            {
                logout.Run(context =>
                {
                    context.Authentication.SignOut();
                    return(Task.FromResult(true));
                });
            });

            app.Map("", nonSecure =>
            {
                nonSecure.Run(context =>
                {
                    var userName = context.Request.User?.Identity.Name;

                    if (string.IsNullOrEmpty(userName))
                    {
                        userName = "******";
                    }

                    context.Response.ContentType = "text/html";

                    context.Response.WriteAsync(
                        @"<!DOCTYPE html>
<html>
    <head>
        <meta charset=""utf-8"">
        <title>Stuntman - UsageSample</title>
    </head>
<body>");

                    context.Response.WriteAsync(
                        $@"Hello, {userName}. <a href=""/secure"">Secure page</a>");


                    context.Response.WriteAsync(
                        StuntmanOptions.UserPicker(context.Request.User ?? new ClaimsPrincipal()));

                    context.Response.WriteAsync(
                        @"</body>
</html>");

                    return(Task.FromResult(true));
                });
            });
        }
示例#3
0
        public void Configuration(IAppBuilder app)
        {
            StuntmanOptions
            .AddUser(new StuntmanUser("user-1", "User 1")
                     .SetAccessToken("user-1-token")
                     .AddClaim("given_name", "John")
                     .AddClaim("family_name", "Doe"))
            .AddUser(new StuntmanUser("user-2", "User 2")
                     .AddClaim("given_name", "Jane")
                     .AddClaim("family_name", "Doe"))
            .AddUser(new StuntmanUser("user-3", "User 3")
                     .AddClaim("given_name", "Sam")
                     .AddClaim("family_name", "Smith"))
            .AddUsersFromJson("https://raw.githubusercontent.com/ritterim/stuntman/master/samples/UsageSample/test-users-1.json")     // Tried this using OWIN locally, didn't get it working.
            .AddUsersFromJson(Path.Combine(GetBinPath(), "test-users-2.json"));

            if (System.Web.HttpContext.Current.IsDebuggingEnabled)
            {
                app.UseStuntman(StuntmanOptions);
            }

            app.Map("/secure", secure =>
            {
                AuthenticateAllRequests(secure, new[] { "StuntmanAuthentication" });

                secure.Run(context =>
                {
                    var userName = context.Request.User.Identity.Name;

                    if (string.IsNullOrEmpty(userName))
                    {
                        userName = "******";
                    }

                    context.Response.ContentType = "text/html";
                    context.Response.WriteAsync(
                        $"Hello, {userName}. This is the /secure endpoint.");

                    if (System.Web.HttpContext.Current.IsDebuggingEnabled)
                    {
                        context.Response.WriteAsync(
                            StuntmanOptions.UserPicker(context.Request.User));
                    }

                    return(Task.FromResult(true));
                });
            });

            app.Map("/logout", logout =>
            {
                logout.Run(context =>
                {
                    context.Authentication.SignOut();
                    return(Task.FromResult(true));
                });
            });

            app.Map("", nonSecure =>
            {
                nonSecure.Run(context =>
                {
                    var userName = context.Request.User.Identity.Name;

                    if (string.IsNullOrEmpty(userName))
                    {
                        userName = "******";
                    }

                    context.Response.ContentType = "text/html";

                    context.Response.WriteAsync(
                        @"<!DOCTYPE html>
<html>
    <head>
        <meta charset=""utf-8"">
        <title>Stuntman - UsageSample</title>
    </head>
<body>");

                    context.Response.WriteAsync(
                        $"Hello, {userName}.");

                    if (System.Web.HttpContext.Current.IsDebuggingEnabled)
                    {
                        context.Response.WriteAsync(
                            StuntmanOptions.UserPicker(context.Request.User));
                    }

                    context.Response.WriteAsync(
                        @"</body>
</html>");

                    return(Task.FromResult(true));
                });
            });
        }
示例#4
0
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseStuntman(StuntmanOptions);

            app.Map("/secure", secure =>
            {
                AuthenticateAllRequests(secure, new[] { "StuntmanAuthentication" });

                secure.Run(context =>
                {
                    var userName = context.User.Identity.Name;

                    if (string.IsNullOrEmpty(userName))
                    {
                        userName = "******";
                    }

                    context.Response.ContentType = "text/html";
                    context.Response.WriteAsync(
                        $"Hello, {userName}. This is the /secure endpoint.");

                    context.Response.WriteAsync(
                        StuntmanOptions.UserPicker(context.User));

                    return(Task.FromResult(true));
                });
            });

            app.Map("/secure-json", secure =>
            {
                AuthenticateAllRequests(secure, new[] { "StuntmanAuthentication" });

                secure.Run(context =>
                {
                    var userName = context.User.Identity.Name;

                    if (string.IsNullOrEmpty(userName))
                    {
                        userName = "******";
                    }

                    context.Response.ContentType = "application/json";
                    context.Response.WriteAsync(
                        $@"{{""message"":""Hello, {userName}. This is the /secure-json endpoint.""}}");

                    return(Task.FromResult(true));
                });
            });

            app.Map("/logout", logout =>
            {
                logout.Run(async context =>
                {
                    await context.SignOutAsync("StuntmanAuthentication");
                });
            });

            app.Map("", nonSecure =>
            {
                nonSecure.Run(context =>
                {
                    var userName = context.User?.Identity.Name;

                    if (string.IsNullOrEmpty(userName))
                    {
                        userName = "******";
                    }

                    context.Response.ContentType = "text/html";

                    context.Response.WriteAsync(
                        @"<!DOCTYPE html>
<html>
    <head>
        <meta charset=""utf-8"">
        <title>Stuntman - UsageSample.AspNetCore</title>
    </head>
<body>");

                    context.Response.WriteAsync(
                        $@"Hello, {userName}. <a href=""/secure"">Secure page</a>");

                    context.Response.WriteAsync(
                        StuntmanOptions.UserPicker(context.User ?? new ClaimsPrincipal()));

                    context.Response.WriteAsync(
                        @"</body>
</html>");

                    return(Task.FromResult(true));
                });
            });
        }