0
votes

I'm building an application in Google Apps Script. I'm authenticating the domain users by checking if their logonid is permitted to use the application. I developed it and when I entered the testing phase, I was the only user that could actually use the application. Although I had set the "Who has Access" combobox on the web-app publish wizard to "anyone".

When a user executes the application he will get an exception saying he has no access when executing the first function after doGet(). Did I overlook some settings or did I do something wrong?

I use the following classes:

UserManager
Session
Jdbc
Utilities
Logger

This is the function that is called after the doGet() function:

function authenticateUser() {
  try {
    var user = UserManager.getUser(Session.getActiveUser());
    Logger.log('User: ' + user.getEmail());
    if (user == undefined || user == null) {
      return {authenticated: false};
    } else {
      var auth = _getAuth();
      if (!auth.isAuthorized(user.getEmail())) {
        Logger.log('Not authorized in database.');
        return {authenticated: false};
      } else {
        var profile = auth.getProfile(user.getEmail());
        authenticated = true;
        auth.setLogin(user.getEmail());
        if(!profile.firstLogin) {
          activeProfile = profile;
        }
        activeUser = user;
        return {profile: profile, authenticated: true};
      }
    }
  } catch(ex) {
    Logger.log(ex);
    return {authenticated: false};
  }
}
1
so "anyone" can execute it, what did you set the "Execute App As" field? I imagine "user accessing the app". What does the first function after doGet() do? call a spreadsheet? - miturbe
Yes, per miturbe's note you are likely doing something in the code that the accessing user has no access to. They might be able to get to the web app, but not able to do anything with it as it might access resources (files, spreadsheets, etc) that the user can't access. - Arun Nagarajan
It Accesses a MySQL database and verifies if the user has access to the script. I also use the User class to access the users name. Indeed the field is set to "User accessing the app". - Feanaro

1 Answers

1
votes

Access to UserManager is the issue here. As the documentation states, UserManager is only accessible to administrators.

If the app is running as a normal user, it cannot access UserManager. You may need to rethnk the deployment/code to run it as yourselves (or admin).