Example #1
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);
            }

            var userPicker = new UserPicker(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(
                            userPicker.GetHtml(context.Request.User, context.Request.Uri.AbsoluteUri));
                    }

                    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(
                            userPicker.GetHtml(context.Request.User, context.Request.Uri.AbsoluteUri));
                    }

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

                    return Task.FromResult(true);
                });
            });
        }
Example #2
0
        public void Configuration(IAppBuilder app)
        {
            var options = new 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"));

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

            var userPicker = new UserPicker(options);

            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(string.Format(
                        "Hello, {0}. This is the /secure endpoint.",
                        userName));

                    if (System.Web.HttpContext.Current.IsDebuggingEnabled)
                    {
                        context.Response.WriteAsync(
                            userPicker.GetHtml(context.Request.User, context.Request.Uri.AbsoluteUri));
                    }

                    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(string.Format(
                        "Hello, {0}.",
                        userName));

                    if (System.Web.HttpContext.Current.IsDebuggingEnabled)
                    {
                        context.Response.WriteAsync(
                            userPicker.GetHtml(context.Request.User, context.Request.Uri.AbsoluteUri));
                    }

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