mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-22 10:06:44 +00:00
GODT-1524: Logout issues with macOS.
This commit is contained in:
@ -250,3 +250,10 @@ func (ctl *Controller) RemoveUserMessageWithoutEvent(username string, messageID
|
||||
|
||||
return errors.New("message not found")
|
||||
}
|
||||
|
||||
func (ctl *Controller) RevokeSession(username string) error {
|
||||
for _, session := range ctl.sessionsByUID {
|
||||
session.uid = "revoked"
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -74,12 +74,12 @@ func (ctl *Controller) createSession(username string, hasFullScope bool) *fakeSe
|
||||
|
||||
func (ctl *Controller) refreshSessionIfAuthorized(uid, ref string) (*fakeSession, error) {
|
||||
session, ok := ctl.sessionsByUID[uid]
|
||||
if !ok {
|
||||
return nil, pmapi.ErrUnauthorized
|
||||
if !ok || session.uid != uid {
|
||||
return nil, pmapi.ErrAuthFailed{OriginalError: errors.New("bad uid")}
|
||||
}
|
||||
|
||||
if ref != session.ref {
|
||||
return nil, pmapi.ErrUnauthorized
|
||||
return nil, pmapi.ErrAuthFailed{OriginalError: errors.New("bad refresh token")}
|
||||
}
|
||||
|
||||
session.ref = ctl.tokenGenerator.next("ref")
|
||||
|
||||
@ -133,14 +133,32 @@ func (api *FakePMAPI) authRefresh() error {
|
||||
|
||||
session, err := api.controller.refreshSessionIfAuthorized(api.uid, api.ref)
|
||||
if err != nil {
|
||||
if pmapi.IsFailedAuth(err) {
|
||||
go api.handleAuth(nil)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
api.ref = session.ref
|
||||
api.acc = session.acc
|
||||
|
||||
go api.handleAuth(&pmapi.AuthRefresh{
|
||||
UID: api.uid,
|
||||
AccessToken: api.acc,
|
||||
RefreshToken: api.ref,
|
||||
ExpiresIn: 7200,
|
||||
Scopes: []string{"full", "self", "user", "mail"},
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (api *FakePMAPI) handleAuth(auth *pmapi.AuthRefresh) {
|
||||
for _, handle := range api.authHandlers {
|
||||
handle(auth)
|
||||
}
|
||||
}
|
||||
|
||||
func (api *FakePMAPI) setUser(username string) error {
|
||||
api.username = username
|
||||
api.log = api.log.WithField("username", username)
|
||||
|
||||
@ -69,7 +69,7 @@ func (m *fakePMAPIManager) NewClientWithRefresh(_ context.Context, uid, ref stri
|
||||
|
||||
session, err := m.controller.refreshSessionIfAuthorized(uid, ref)
|
||||
if err != nil {
|
||||
return nil, nil, pmapi.ErrUnauthorized
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
user, ok := m.controller.usersByUsername[session.username]
|
||||
|
||||
@ -82,6 +82,10 @@ func (api *FakePMAPI) UpdateUser(context.Context) (*pmapi.User, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := api.checkAndRecordCall(GET, "/addresses", nil); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return api.user, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user