Skip to content

Commit

Permalink
Add jwt create with config.
Browse files Browse the repository at this point in the history
  • Loading branch information
flowerinthenight committed Jan 25, 2018
1 parent 794248f commit 269ab47
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
10 changes: 5 additions & 5 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions pkg/jwt/jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,35 @@ func NewCtx(pemdir ...string) (*jwtctx, error) {

return &ctx, nil
}

type Config struct {
PublicTokenFile string
PrivateTokenFile string
}

func NewCtxWithConfig(cnf *Config) (*jwtctx, error) {
if cnf == nil {
return nil, fmt.Errorf("config cannot be nil")
}

pubcache, err := ioutil.ReadFile(cnf.PublicTokenFile)
if err != nil {
debug.Error(err)
return nil, errors.Wrap(err, "pub readfile failed")
}

prvcache, err := ioutil.ReadFile(cnf.PrivateTokenFile)
if err != nil {
debug.Error(err)
return nil, errors.Wrap(err, "prv readfile failed")
}

ctx := jwtctx{
PemPub: cnf.PublicTokenFile,
PemPrv: cnf.PrivateTokenFile,
Pub: pubcache,
Prv: prvcache,
}

return &ctx, nil
}

0 comments on commit 269ab47

Please sign in to comment.