auth: Load JWT secret once
This commit is contained in:
@@ -2,6 +2,8 @@ package modules
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/gbrlsnchs/jwt/v3"
|
||||
"golang.org/x/xerrors"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/ipfs/go-bitswap"
|
||||
@@ -70,6 +72,18 @@ func KeyStore(lr repo.LockedRepo) (types.KeyStore, error) {
|
||||
return lr.KeyStore()
|
||||
}
|
||||
|
||||
const JWTSecretName = "auth-jwt-private"
|
||||
|
||||
type APIAlg jwt.HMACSHA
|
||||
|
||||
func APISecret(keystore types.KeyStore) (*APIAlg, error) {
|
||||
key, err := keystore.Get(JWTSecretName)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("couldn't get JWT secret: %w", err)
|
||||
}
|
||||
return (*APIAlg)(jwt.NewHS256(key.PrivateKey)), nil
|
||||
}
|
||||
|
||||
func Datastore(r repo.LockedRepo) (datastore.Batching, error) {
|
||||
return r.Datastore("/metadata")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user