Web App Development with Google Apps Script/authentication

Why authenticate?
Quite often you'll want to protect your web app to ensure only certain people can use it. When you publish your page you have a few options in two major categories:
 * 1) Who has access (who can get to the page)?
 * 2) Just you
 * 3) Anyone in your domain (hamline.edu for me)
 * 4) Anyone
 * 5) Which account is being used to run the script?
 * 6) Yours (even when other people access)
 * 7) Theirs (won't work with "anyone" above)

Those are useful but they're a little coarse grained. Sometimes you'll want only certain people to either have access and/or be able to do certain things.

Who is accessing?
For this section we'll assume you've set "who has access" to "anyone in your domain." If you do then you can determine who is accessing like this:

Are they allowed?
Once you have the user's email, you can check it against a sheet in your spreadsheet that has allowed users and perhaps other information about them, like what things they're allowed to do. Let's assume you have a sheet that looks like this: Then we could authenticate the user like this: