store hashed token base64 encoded

This commit is contained in:
Pascal Fischer
2023-03-29 15:21:53 +02:00
parent 726ffb5740
commit c5942e6b33
6 changed files with 43 additions and 22 deletions
+7 -5
View File
@@ -112,7 +112,7 @@ func restore(file string) (*FileStore, error) {
store.UserID2AccountID[user.Id] = accountID
for _, pat := range user.PATs {
store.TokenID2UserID[pat.ID] = user.Id
store.HashedPAT2TokenID[pat.HashedToken[:]] = pat.ID
store.HashedPAT2TokenID[pat.HashedToken] = pat.ID
}
}
@@ -268,7 +268,7 @@ func (s *FileStore) SaveAccount(account *Account) error {
s.UserID2AccountID[user.Id] = accountCopy.Id
for _, pat := range user.PATs {
s.TokenID2UserID[pat.ID] = user.Id
s.HashedPAT2TokenID[pat.HashedToken[:]] = pat.ID
s.HashedPAT2TokenID[pat.HashedToken] = pat.ID
}
}
@@ -349,11 +349,13 @@ func (s *FileStore) GetTokenIDByHashedToken(token string) (string, error) {
s.mux.Lock()
defer s.mux.Unlock()
log.Debugf("TOken still there: %v", token)
log.Debugf("TokenID2UserId %v", s.HashedPAT2TokenID)
tokenID, ok := s.HashedPAT2TokenID[token]
if !ok {
return "", status.Errorf(status.NotFound, "tokenID not found: provided token doesn't exists")
}
log.Debugf("TokenID for token %s is %s", token, tokenID)
return tokenID, nil
}
@@ -366,12 +368,12 @@ func (s *FileStore) GetUserByTokenID(tokenID string) (*User, error) {
if !ok {
return nil, status.Errorf(status.NotFound, "user not found: provided tokenID doesn't exists")
}
log.Debugf("UserID for tokenID %s is %s", tokenID, userID)
accountID, ok := s.UserID2AccountID[userID]
if !ok {
return nil, status.Errorf(status.NotFound, "accountID not found: provided userID doesn't exists")
}
log.Debugf("AccountID for userID %s is %s", userID, accountID)
account, err := s.getAccount(accountID)
if err != nil {
return nil, err