From 50e4a46394c122ca03ad5a8e2cc600c738628131 Mon Sep 17 00:00:00 2001 From: Sebastian Mancke Date: Fri, 5 May 2017 19:59:28 +0200 Subject: [PATCH] added caddy configuration demo --- caddy/README.md | 2 ++ caddy/demo/Caddyfile | 20 +++++++++++++++++++ caddy/demo/README.md | 10 ++++++++++ caddy/demo/main.go | 11 +++++++++++ caddy/demo/passwords | 1 + caddy/demo/webroot/index.html | 34 ++++++++++++++++++++++++++++++++ caddy/demo/webroot/private.html | 35 +++++++++++++++++++++++++++++++++ 7 files changed, 113 insertions(+) create mode 100644 caddy/demo/Caddyfile create mode 100644 caddy/demo/README.md create mode 100644 caddy/demo/main.go create mode 100644 caddy/demo/passwords create mode 100644 caddy/demo/webroot/index.html create mode 100644 caddy/demo/webroot/private.html diff --git a/caddy/README.md b/caddy/README.md index 5ea63de..1c95f9d 100644 --- a/caddy/README.md +++ b/caddy/README.md @@ -6,6 +6,8 @@ This middleware is designed to play together with the [caddy-jwt](https://github For a full documentation of loginsrv configuration and usage, visit the [loginsrv README.md](https://github.com/tarent/loginsrv). +A small demo can also be found in the [./demo](https://github.com/tarent/loginsrv/tree/master/caddy/demo) directory. + ## Configuration To be compatible with caddy-jwt, the jwt secret is taken from the enviroment variable `JWT_SECRET` if such a variable is set. Otherwise, a random token is generated and set as enviroment variable JWT_SECRET, diff --git a/caddy/demo/Caddyfile b/caddy/demo/Caddyfile new file mode 100644 index 0000000..18abd50 --- /dev/null +++ b/caddy/demo/Caddyfile @@ -0,0 +1,20 @@ + +http://localhost:8080 { + + log stdout + root {$PWD}/webroot + ext .html + header /private Cache-Control "no-cache, no-store, must-revalidate" + + jwt { + path /private + redirect /login + allow sub demo + } + + login { + success_url /private + htpasswd file=passwords + } + +} diff --git a/caddy/demo/README.md b/caddy/demo/README.md new file mode 100644 index 0000000..31b637a --- /dev/null +++ b/caddy/demo/README.md @@ -0,0 +1,10 @@ +# Caddy login demo + +This directory contains a small demo on how to secure a +directory or file by loginsrv and caddy. + +Please start it from this directory with + +` +go run main.go +` diff --git a/caddy/demo/main.go b/caddy/demo/main.go new file mode 100644 index 0000000..63d334f --- /dev/null +++ b/caddy/demo/main.go @@ -0,0 +1,11 @@ +package main + +import ( + _ "github.com/BTBurke/caddy-jwt" + "github.com/mholt/caddy/caddy/caddymain" + _ "github.com/tarent/loginsrv/caddy" +) + +func main() { + caddymain.Run() +} diff --git a/caddy/demo/passwords b/caddy/demo/passwords new file mode 100644 index 0000000..f9c20a7 --- /dev/null +++ b/caddy/demo/passwords @@ -0,0 +1 @@ +demo:$2y$10$B/lwbuYGkYDe6wYE4LpuE.DlFFEnM7mK4V7jXDTGJUVEtGZ2P63DK diff --git a/caddy/demo/webroot/index.html b/caddy/demo/webroot/index.html new file mode 100644 index 0000000..174ae33 --- /dev/null +++ b/caddy/demo/webroot/index.html @@ -0,0 +1,34 @@ + + + + + + Caddy-login Demo Application + + + + + + + +
+
+

Caddy Login Demo Application

+ Please login with demo/demo. +
+
+ + + diff --git a/caddy/demo/webroot/private.html b/caddy/demo/webroot/private.html new file mode 100644 index 0000000..0f55506 --- /dev/null +++ b/caddy/demo/webroot/private.html @@ -0,0 +1,35 @@ + + + + + + Caddy-login Demo Application + + + + + + + +
+
+

This is a private Site

+ You should only be able to see this, when logged in. +

Please Logout

+
+
+ + +