@@ -81,7 +81,7 @@ func (s *Service) RegisterBySignature(publicKey, signature string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Service) CreateChallenge(publicKey string) (string, error) {
|
||||
func (s *Service) CreateChallenge(publicKey, clientIP string) (string, error) {
|
||||
if publicKey == "" {
|
||||
return "", fmt.Errorf("%w: missing public key", ErrBadRequest)
|
||||
}
|
||||
@@ -93,6 +93,7 @@ func (s *Service) CreateChallenge(publicKey string) (string, error) {
|
||||
err = s.store.CreateChallenge(store.Challenge{
|
||||
Nonce: nonce,
|
||||
PublicKey: publicKey,
|
||||
IP: clientIP,
|
||||
ExpiresAt: time.Now().UTC().Add(s.config.ChallengeTTL),
|
||||
Used: false,
|
||||
})
|
||||
@@ -102,7 +103,7 @@ func (s *Service) CreateChallenge(publicKey string) (string, error) {
|
||||
return nonce, nil
|
||||
}
|
||||
|
||||
func (s *Service) Login(publicKey, nonce, signature string) (string, error) {
|
||||
func (s *Service) Login(publicKey, nonce, signature, clientIP string) (string, error) {
|
||||
ch, err := s.store.GetChallenge(nonce)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("%w: challenge not found", ErrUnauthorized)
|
||||
@@ -132,6 +133,11 @@ func (s *Service) Login(publicKey, nonce, signature string) (string, error) {
|
||||
PublicKey: publicKey,
|
||||
ExpiresAt: time.Now().UTC().Add(s.config.SessionTTL),
|
||||
})
|
||||
s.store.SaveUserLogin(store.UserLogin{
|
||||
PublicKey: publicKey,
|
||||
IP: clientIP,
|
||||
CreatedAt: time.Now().UTC(),
|
||||
})
|
||||
return token, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user