refactor: create and export GenerateTokenWithDuration and GenerateToken
This commit is contained in:
parent
8c86ecc5b7
commit
4378da70da
|
@ -88,7 +88,7 @@ func (s AccountServiceImpl) LoginPassword(email string, password string) (string
|
|||
return "", err
|
||||
}
|
||||
|
||||
token, err := generateToken(s.portal.Identity(), user.ID)
|
||||
token, err := GenerateToken(s.portal.Identity(), user.ID)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
@ -105,7 +105,7 @@ func (s AccountServiceImpl) LoginPubkey(pubkey string) (string, error) {
|
|||
return "", result.Error
|
||||
}
|
||||
|
||||
token, err := generateToken(s.portal.Identity(), model.UserID)
|
||||
token, err := GenerateToken(s.portal.Identity(), model.UserID)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
|
|
@ -6,12 +6,15 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
func generateToken(privateKey ed25519.PrivateKey, userID uint) (string, error) {
|
||||
func GenerateToken(privateKey ed25519.PrivateKey, userID uint) (string, error) {
|
||||
return GenerateTokenWithDuration(privateKey, userID, time.Hour*24)
|
||||
}
|
||||
func GenerateTokenWithDuration(privateKey ed25519.PrivateKey, userID uint, duration time.Duration) (string, error) {
|
||||
// Define the claims
|
||||
claims := jwt.MapClaims{
|
||||
"iss": "portal",
|
||||
"sub": userID,
|
||||
"exp": time.Now().Add(time.Hour * 24).Unix(),
|
||||
"exp": time.Now().Add(duration).Unix(),
|
||||
}
|
||||
|
||||
// Create the token
|
||||
|
|
Loading…
Reference in New Issue