Skip to content

Commit

Permalink
Fix invalid token due to the cache race (netbirdio#1763)
Browse files Browse the repository at this point in the history
  • Loading branch information
braginini authored Mar 28, 2024
1 parent 2dfc899 commit 0cf2c3e
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions management/server/grpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,10 +343,18 @@ func (s *GRPCServer) Login(ctx context.Context, req *proto.EncryptedMessage) (*p
userID := ""
// JWT token is not always provided, it is fine for userID to be empty cuz it might be that peer is already registered,
// or it uses a setup key to register.

if loginReq.GetJwtToken() != "" {
userID, err = s.validateToken(loginReq.GetJwtToken())
for i := 0; i < 3; i++ {
userID, err = s.validateToken(loginReq.GetJwtToken())
if err == nil {
break
}
log.Warnf("failed validating JWT token sent from peer %s with error %v. "+
"Trying again as it may be due to the IdP cache issue", peerKey, err)
time.Sleep(200 * time.Millisecond)
}
if err != nil {
log.Warnf("failed validating JWT token sent from peer %s", peerKey)
return nil, err
}
}
Expand Down

0 comments on commit 0cf2c3e

Please sign in to comment.