Repeated authentication screen when using username and password

Viewed 104

I'm writing a connector to Datastudio and I decided to go for username and password authentication. My isAuthValid, setCredentials and getAuthType functions:

var cc = DataStudioApp.createCommunityConnector();

function isAuthValid() {
  const properties = PropertiesService.getUserProperties();
  const username = properties.getProperty('dscc.username');
  const password = properties.getProperty('dscc.password');
  console.log(username);
  console.log(password);
  return !!(username && password);
}

function setCredentials(request) {
  const isCredentialsValid = !!(request.userPass.username && request.userPass.password);
  console.log('username: ' + request.userPass.username);
  console.log('password: ' + request.userPass.password);
  if (!isCredentialsValid) {
    return {
      errorCode: "INVALID_CREDENTIALS"
    };
  }
  PropertiesService.getUserProperties()
    .setProperty('dscc.username', request.userPass.username)
    .setProperty('dscc.password', request.userPass.password);
  return {
    errorCode: "NONE"
  };
};

function getAuthType() {
  return cc.newAuthTypeResponse()
    .setAuthType(cc.AuthType.USER_PASS)
    .build();
}

function resetAuth() {
  const userProperties = PropertiesService.getUserProperties();
  userProperties.deleteProperty('dscc.username');
  userProperties.deleteProperty('dscc.password');
}

It works, but almost always after the first attempt the login password screen reappears.

In the logs I can see that setCredentials is called with proper arguments and then isAuthValid with username and password equal to null. After the second attempt isAuthValid is called properly with expected arguments.

Does anyone have an idea why does it behave like this?

0 Answers
Related