syncloud.google.docs.auth.PasswordTransportAuthenticator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of syncloud-google-docs Show documentation
Show all versions of syncloud-google-docs Show documentation
Google Docs Syncloud Starage Adapter
The newest version!
package syncloud.google.docs.auth;
import com.google.api.client.googleapis.auth.clientlogin.ClientLogin;
import com.google.api.client.http.javanet.NetHttpTransport;
import syncloud.core.log.Logger;
import java.io.IOException;
public class PasswordTransportAuthenticator implements TransportAuthenticator {
private static Logger logger = Logger.getLogger(PasswordTransportAuthenticator.class);
private static final String APP_NAME = "uCloud";
private static final String DOCUMENTS_TYPE_NAME = "writely";
private boolean authenticated = false;
private String auth;
@Override
public boolean authorize(String login, String password) {
ClientLogin authenticator = new ClientLogin();
authenticator.applicationName = APP_NAME;
authenticator.authTokenType = DOCUMENTS_TYPE_NAME;
authenticator.username = login;
authenticator.password = password;
authenticator.transport = new NetHttpTransport();
try {
ClientLogin.Response response = authenticator.authenticate();
auth = response.auth;
logger.debug("successfully authenticated: " + login);
authenticated = true;
} catch (IOException e) {
logger.error("unable to authenticate, " + e.getMessage());
authenticated = false;
}
return authenticated;
}
@Override
public String getAuth() {
return auth;
}
@Override
public boolean authenticated() {
return authenticated;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy