Restructuring into packages.
This commit is contained in:
parent
4963e3ca71
commit
335d573d23
28 changed files with 2232 additions and 2108 deletions
44
auth/claims.go
Normal file
44
auth/claims.go
Normal file
|
@ -0,0 +1,44 @@
|
|||
package auth
|
||||
|
||||
import (
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/thermokarst/bactdb/Godeps/_workspace/src/github.com/thermokarst/jwt"
|
||||
"github.com/thermokarst/bactdb/models"
|
||||
)
|
||||
|
||||
var (
|
||||
Middleware *jwt.Middleware
|
||||
Config *jwt.Config = &jwt.Config{
|
||||
Secret: os.Getenv("SECRET"),
|
||||
Auth: models.DbAuthenticate,
|
||||
Claims: claimsFunc,
|
||||
}
|
||||
)
|
||||
|
||||
func claimsFunc(email string) (map[string]interface{}, error) {
|
||||
// TODO: use helper
|
||||
currentTime := time.Now()
|
||||
user, err := models.DbGetUserByEmail(email)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return map[string]interface{}{
|
||||
"name": user.Name,
|
||||
"iss": "bactdb",
|
||||
"sub": user.Id,
|
||||
"role": user.Role,
|
||||
"iat": currentTime.Unix(),
|
||||
"exp": currentTime.Add(time.Minute * 60).Unix(),
|
||||
"ref": "",
|
||||
}, nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
var err error
|
||||
Middleware, err = jwt.New(Config)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
Reference in a new issue