Skip to content

Commit

Permalink
Fixes #3: use symmetric key for JWT
Browse files Browse the repository at this point in the history
  • Loading branch information
qiangxue committed Feb 19, 2020
1 parent 5488727 commit 8e7306c
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 13 deletions.
13 changes: 5 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,18 @@ test-cover: test ## run unit tests and show test coverage information

.PHONY: run
run: ## run the API server
go run ${LDFLAGS} cmd/server/main.go & echo $$! > $(PID_FILE)

.PHONY: run-stop
run-stop: ## stop the API server
@pkill -P `cat $(PID_FILE)` || true
go run ${LDFLAGS} cmd/server/main.go

.PHONY: run-restart
run-restart: ## restart the API server
@make run-stop
@pkill -P `cat $(PID_FILE)` || true
@printf '%*s\n' "80" '' | tr ' ' -
@echo "Source file changed. Restarting server..."
@make run
@go run ${LDFLAGS} cmd/server/main.go & echo $$! > $(PID_FILE)
@printf '%*s\n' "80" '' | tr ' ' -

run-live: run ## run the API server with live reload support (requires fswatch)
run-live: ## run the API server with live reload support (requires fswatch)
@go run ${LDFLAGS} cmd/server/main.go & echo $$! > $(PID_FILE)
@fswatch -x -o --event Created --event Updated --event Renamed -r internal pkg cmd config | xargs -n1 -I {} make run-restart

.PHONY: build
Expand Down
2 changes: 1 addition & 1 deletion cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func buildHandler(logger log.Logger, db *dbcontext.DB, cfg *config.Config) http.

rg := router.Group("/v1")

authHandler := auth.Handler(cfg.JWTVerificationKey)
authHandler := auth.Handler(cfg.JWTSigningKey)

album.RegisterHandlers(rg.Group(""),
album.NewService(album.NewRepository(db, logger), logger),
Expand Down
1 change: 0 additions & 1 deletion config/local.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
dsn: "postgres://127.0.0.1/go_restful?sslmode=disable&user=postgres&password=postgres"
jwt_signing_key: "LxsKJywDL5O5PvgODZhBH12KE6k2yL8E"
jwt_verification_key: "IuDQoh1QAIFwnKAydSntyJrTmOkct3wN"
3 changes: 0 additions & 3 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ type Config struct {
DSN string `yaml:"dsn" env:"DSN,secret"`
// JWT signing key. required.
JWTSigningKey string `yaml:"jwt_signing_key" env:"JWT_SIGNING_KEY,secret"`
// JWT verification key. required.
JWTVerificationKey string `yaml:"jwt_verification_key" env:"JWT_VERIFICATION_KEY,secret"`
// JWT expiration in hours. Defaults to 72 hours (3 days)
JWTExpiration int `yaml:"jwt_expiration" env:"JWT_EXPIRATION"`
}
Expand All @@ -32,7 +30,6 @@ func (c Config) Validate() error {
return validation.ValidateStruct(&c,
validation.Field(&c.DSN, validation.Required),
validation.Field(&c.JWTSigningKey, validation.Required),
validation.Field(&c.JWTVerificationKey, validation.Required),
)
}

Expand Down

0 comments on commit 8e7306c

Please sign in to comment.