Refresh tokens

This commit is contained in:
M66B
2018-09-21 13:09:22 +00:00
parent eddbf29175
commit 8dbf639a48
4 changed files with 40 additions and 5 deletions

View File

@@ -1261,7 +1261,16 @@ public class ServiceSynchronize extends LifecycleService {
try {
// Connect transport
db.identity().setIdentityState(ident.id, "connecting");
itransport.connect(ident.host, ident.port, ident.user, ident.password);
try {
itransport.connect(ident.host, ident.port, ident.user, ident.password);
} catch (AuthenticationFailedException ex) {
if (ident.auth_type == Helper.AUTH_TYPE_GMAIL) {
ident.password = Helper.refreshToken(this, "com.google", ident.user, ident.password);
DB.getInstance(this).identity().setIdentityPassword(ident.id, ident.password);
itransport.connect(ident.host, ident.port, ident.user, ident.password);
} else
throw ex;
}
db.identity().setIdentityState(ident.id, "connected");
db.identity().setIdentityError(ident.id, null);