loginsrv

Unnamed repository; edit this file 'description' to name the repository.
git clone git@jamesshield.xyz:repos/loginsrv.git
Log | Files | Refs | README | LICENSE

commit 40a03158100dc3f5f740974a8e845c59a7c46681
parent 7d5e2257f5f67ed4dec5b49e47be5f30432cd010
Author: Sebastian Mancke <s.mancke@tarent.de>
Date:   Fri,  5 May 2017 19:52:10 +0200

Merge pull request #5 from tarent/consistent-config-handling

Consistent config handling
Diffstat:
Mcaddy/README.md | 8+++++---
Mcaddy/setup.go | 6+++++-
Mcaddy/setup_test.go | 22+++++++++++-----------
3 files changed, 21 insertions(+), 15 deletions(-)

diff --git a/caddy/README.md b/caddy/README.md @@ -4,6 +4,8 @@ Login plugin for caddy, based on [tarent/loginsrv](https://github.com/tarent/log The login is checked against a backend and then returned as JWT token. This middleware is designed to play together with the [caddy-jwt](https://github.com/BTBurke/caddy-jwt) plugin. +For a full documentation of loginsrv configuration and usage, visit the [loginsrv README.md](https://github.com/tarent/loginsrv). + ## 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, @@ -20,9 +22,9 @@ login / { ### Full configuration example ``` login / { - success-url /after/login - cookie-name alternativeName - cookie-http-only true + success_url /after/login + cookie_name alternativeName + cookie_http_only true simple bob=secret osiam endpoint=http://localhost:8080,client_id=example-client,client_secret=secret htpasswd file=users diff --git a/caddy/setup.go b/caddy/setup.go @@ -11,6 +11,7 @@ import ( _ "github.com/tarent/loginsrv/oauth2" _ "github.com/tarent/loginsrv/osiam" "os" + "strings" ) func init() { @@ -69,7 +70,10 @@ func parseConfig(c *caddy.Controller) (*login.Config, error) { cfg.ConfigureFlagSet(fs) for c.NextBlock() { - name := c.Val() + // caddy preferes '_' in parameter names, + // so we map them to the '-' from the command line flags + // the replacement supports both, for backwards compatibility + name := strings.Replace(c.Val(), "_", "-", -1) args := c.RemainingArgs() if len(args) != 1 { return cfg, fmt.Errorf("Wrong number of arguments for %v: %v (%v:%v)", name, args, c.File(), c.Line()) diff --git a/caddy/setup_test.go b/caddy/setup_test.go @@ -21,7 +21,7 @@ func TestSetup(t *testing.T) { }{ { //defaults input: `loginsrv / { - backend provider=simple,bob=secret + simple bob=secret }`, shouldErr: false, path: "/", @@ -39,11 +39,11 @@ func TestSetup(t *testing.T) { }}, { input: `loginsrv / { - success-url successurl - cookie-name cookiename - cookie-http-only false - backend provider=simple,bob=secret - backend provider=osiam,endpoint=http://localhost:8080,clientId=example-client,clientSecret=secret + success_url successurl + cookie_name cookiename + cookie_http_only false + simple bob=secret + osiam endpoint=http://localhost:8080,client_id=example-client,client_secret=secret }`, shouldErr: false, path: "/", @@ -57,9 +57,9 @@ func TestSetup(t *testing.T) { "bob": "secret", }, "osiam": map[string]string{ - "endpoint": "http://localhost:8080", - "clientId": "example-client", - "clientSecret": "secret", + "endpoint": "http://localhost:8080", + "client_id": "example-client", + "client_secret": "secret", }, }, Oauth: login.Options{}, @@ -67,8 +67,8 @@ func TestSetup(t *testing.T) { // error cases {input: "loginsrv {\n}", shouldErr: true}, {input: "loginsrv xx yy {\n}", shouldErr: true}, - {input: "loginsrv / {\n cookie-http-only 42 \n backend provider=simple,bob=secret \n}", shouldErr: true}, - {input: "loginsrv / {\n unknown property \n backend provider=simple,bob=secret \n}", shouldErr: true}, + {input: "loginsrv / {\n cookie_http_only 42 \n simple bob=secret \n}", shouldErr: true}, + {input: "loginsrv / {\n unknown property \n simple bob=secret \n}", shouldErr: true}, {input: "loginsrv / {\n backend \n}", shouldErr: true}, {input: "loginsrv / {\n backend provider=foo\n}", shouldErr: true}, {input: "loginsrv / {\n backend kk\n}", shouldErr: true},