mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-15 14:56:42 +00:00
feat: implement token expiration watcher
This commit is contained in:
@ -181,10 +181,11 @@ func (b *Bridge) watchBridgeOutdated() {
|
||||
// watchUserAuths receives auths from the client manager and sends them to the appropriate user.
|
||||
func (b *Bridge) watchUserAuths() {
|
||||
for auth := range b.clientManager.GetBridgeAuthChannel() {
|
||||
logrus.WithField("token", auth.Auth.GenToken()).WithField("userID", auth.UserID).Info("Received auth from bridge auth channel")
|
||||
logrus.Debug("Bridge received auth from ClientManager")
|
||||
|
||||
if user, ok := b.hasUser(auth.UserID); ok {
|
||||
user.ReceiveAPIAuth(auth.Auth)
|
||||
logrus.Debug("Bridge is forwarding auth to user")
|
||||
user.AuthorizeWithAPIAuth(auth.Auth)
|
||||
} else {
|
||||
logrus.Info("User is not added to bridge yet")
|
||||
}
|
||||
@ -494,11 +495,7 @@ func (b *Bridge) updateCurrentUserAgent() {
|
||||
|
||||
// hasUser returns whether the bridge currently has a user with ID `id`.
|
||||
func (b *Bridge) hasUser(id string) (user *User, ok bool) {
|
||||
logrus.WithField("id", id).Info("Checking whether bridge has given user")
|
||||
|
||||
for _, u := range b.users {
|
||||
logrus.WithField("id", u.ID()).Info("Found potential user")
|
||||
|
||||
if u.ID() == id {
|
||||
user, ok = u, true
|
||||
return
|
||||
|
||||
@ -243,10 +243,12 @@ func (u *User) authorizeAndUnlock() (err error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *User) ReceiveAPIAuth(auth *pmapi.Auth) {
|
||||
func (u *User) AuthorizeWithAPIAuth(auth *pmapi.Auth) {
|
||||
u.lock.Lock()
|
||||
defer u.lock.Unlock()
|
||||
|
||||
u.log.Debug("User received auth from bridge")
|
||||
|
||||
if auth == nil {
|
||||
if err := u.logout(); err != nil {
|
||||
u.log.WithError(err).Error("Failed to logout user after receiving empty auth from API")
|
||||
|
||||
Reference in New Issue
Block a user