mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 14:55:16 +00:00
auth: store otp key url instead of just secret
This commit is contained in:
parent
6c7b6c6def
commit
63f525970f
|
@ -737,9 +737,9 @@ func getAuthStoreID() string {
|
|||
func (environ *Environment) setupInteraction(persistence service.PersistenceService) error {
|
||||
var otpQRCodeImagePath = fmt.Sprintf("otp.png")
|
||||
var key *otp.Key
|
||||
var keySecret string
|
||||
var keyURL string
|
||||
var authStore = environ.getAuthStore(persistence)
|
||||
if err := authStore.Load(&keySecret); err != nil {
|
||||
if err := authStore.Load(&keyURL); err != nil {
|
||||
log.Warnf("telegram session not found, generating new one-time password key for new telegram session...")
|
||||
|
||||
newKey, err := setupNewOTPKey(otpQRCodeImagePath)
|
||||
|
@ -748,22 +748,35 @@ func (environ *Environment) setupInteraction(persistence service.PersistenceServ
|
|||
}
|
||||
|
||||
key = newKey
|
||||
keySecret = key.Secret()
|
||||
if err := authStore.Save(keySecret); err != nil {
|
||||
keyURL = key.URL()
|
||||
if err := authStore.Save(keyURL); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
printOtpAuthGuide(otpQRCodeImagePath)
|
||||
|
||||
} else if keySecret != "" {
|
||||
key, err = otp.NewKeyFromURL(keySecret)
|
||||
} else if keyURL != "" {
|
||||
key, err = otp.NewKeyFromURL(keyURL)
|
||||
if err != nil {
|
||||
log.WithError(err).Errorf("can not load otp key from url: %s, generating new otp key", keyURL)
|
||||
|
||||
newKey, err := setupNewOTPKey(otpQRCodeImagePath)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to setup totp (time-based one time password) key")
|
||||
}
|
||||
|
||||
key = newKey
|
||||
keyURL = key.URL()
|
||||
if err := authStore.Save(keyURL); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
printOtpAuthGuide(otpQRCodeImagePath)
|
||||
} else {
|
||||
log.Infof("otp key loaded: %s", util.MaskKey(key.Secret()))
|
||||
printOtpAuthGuide(otpQRCodeImagePath)
|
||||
}
|
||||
}
|
||||
|
||||
authStrict := false
|
||||
authMode := interact.AuthModeToken
|
||||
|
|
|
@ -92,7 +92,7 @@ func (it *AuthInteract) Commands(interact *Interact) {
|
|||
reply.Message("Enter your one-time password")
|
||||
|
||||
default:
|
||||
log.Warn("unexpected auth mode: %s", it.Mode)
|
||||
log.Warnf("unexpected auth mode: %s", it.Mode)
|
||||
}
|
||||
return nil
|
||||
}).NamedNext(StateAuthenticated, func(code string, reply Reply, session Session) error {
|
||||
|
@ -116,7 +116,7 @@ func (it *AuthInteract) Commands(interact *Interact) {
|
|||
reply.Message("Incorrect one-time pass code")
|
||||
|
||||
default:
|
||||
log.Warn("unexpected auth mode: %s", it.Mode)
|
||||
log.Warnf("unexpected auth mode: %s", it.Mode)
|
||||
}
|
||||
|
||||
return ErrAuthenticationFailed
|
||||
|
|
Loading…
Reference in New Issue
Block a user