添加配置加载和授权服务初始化,更新授权模型引用,重构授权文件生成和处理逻辑,优化 TOTP 密钥生成及错误处理
This commit is contained in:
@@ -3,8 +3,10 @@ package services
|
||||
import (
|
||||
"cmii-uav-watchdog/config"
|
||||
"errors"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
otp "cmii-uav-watchdog-otp"
|
||||
"cmii-uav-watchdog-otp/totp"
|
||||
)
|
||||
|
||||
@@ -41,3 +43,23 @@ func (ts *TOTPService) VerifyTOTP(code string) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// GenerateTOTPSecret 生成TOTP密钥
|
||||
func (ts *TOTPService) GenerateTOTPSecret() (string, error) {
|
||||
secret, err := totp.Generate(totp.GenerateOpts{
|
||||
SecretSize: 32,
|
||||
Issuer: "cmii-uav-watchdog",
|
||||
AccountName: "cmii-uav-watchdog",
|
||||
Period: 30,
|
||||
Secret: []byte{},
|
||||
Digits: otp.DigitsSix,
|
||||
Algorithm: otp.AlgorithmSHA1,
|
||||
Rand: nil,
|
||||
})
|
||||
if err != nil {
|
||||
log.Printf("生成TOTP密钥失败: %v", err)
|
||||
return "", err
|
||||
}
|
||||
|
||||
return secret.Secret(), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user