Use Google OAuth2.0 from gmail email and password stored in the database - google-drive-api

I would like Google Drive to store document attachment to Google drive which I will do from a web application. These attachments can be done from a role of the users logged in using our local authentication system.
The problem is we don't want these users to know the email id and password associated with to log into this.
At the other end we don't want anonymous users to log in using oauth. I just have started learning Google Developer Tools so it would be nice if I get help.
Please find the diagram explaining about the problem:

Wait! You want your app to access the Drive of end users, by them giving you their Google password? Seriously? Not only is that madness, but I'm sure it is against the terms of use of their Google licence.

Related

How to select account in Google App Scripts for users with multiple accounts?

For users that are logged into multiple accounts, how can a script let the user pick an account? For example, Gmail, Google Drive, etc. provide a way for the user to select which account to use with a selectable option on the top-right of the page:
How can developers implement a similar mechanism?
There seems to be no way to do that with Google Apps Script libraries - GAS just uses the current primary account. Also, unfortunately, the API Client Library and thus Google Sign-In for websites don't work inside GAS web apps because of the sandbox frame. You could write your own or use some existing OAuth implementation to authenticate with Google but I found a much much simpler solution using Auth0 Lock with only a Google Connection (using the popup method because the redirect method doesn't work within the sandbox frame).
With Chrome Version 70.0.3538.102. You may resolve your issue (at least i did)
Now i make sure i ONLY signed in ONE account at a time. Then use "manage people"
if i have 3 google accounts, i will create 3 people and each time you only have 1 active google account session. With this setup, i ensured everytime my script only execute with my G Suite user instead of #gmail accounts
You can try using the Directory API to work with Apps Script. Retrieve the user using:
GET https://www.googleapis.com/admin/directory/v1/users/userKey.
You can then make an interface that displays the user accounts details(Name, email,etc).

Google Drive SDK authorization

I have been trying to follow the Quickstart: Run a Drive app in JavaScript sample in order to use Google Drive API and SDK. I went through the authentication and set up the Client ID and API key etc. I had assumed that the token can be created without the user being logged in to a Google Account, since the client has the Client ID that is connected to a Project on Google Developer Console. Am I missing something here?
Can a user use the JavaScript based Google Drive app without logging in to a Google Account?
no. From your question, it sounds like you've interpreted client ID as referring to the user. Client ID refers to the app. So separately, Google needs to confirm the user has given his permission, and that requires authentication, ie login

Google Apps Script UI: What to do if already logged into Gmail?

I'm using Google Apps Script UI to create forms for students at my school. I've restricted access to my domain for added security, and to capture users' email addresses.
The problem is that many of our students have separate Gmail accounts. If they are already logged into Gmail (not our domain), they don't get a log-in page, but something prompting them to request access.
Any suggestions for avoiding this?
Thought I saw a request in the issue tracker for an account choosing feature, but my guess is that you'll want to allow anyone to access your web app and show a custom prompt if their email is non-domain. I don't know how well this would work with shared computers, but creating separate Chrome user accounts for each of my Google accounts has solved all my multiple sign-in pain.

How to collect google site logged in username

I'm creating a simple Google Site that has nothing on it but a form to collect respondent's information. The reason I'm using Site instead of just a Google Drive form is because I need to offer respondents the ability to upload files. Couldn't figure out how to do it with Google Drive form.
The site (or form) will only be shared with users in my institution which uses GoogleApps and everyone will need to log in their GoogleApps account to view the site. I'd like to know how to capture or collect the logged in GoogleApps username viewing the site. Thanks.
If all your users are within a Google Apps domain, then collecting the username is rather straightforward. Use
var username = Session.getActiveUser().getUserLoginId();

about service accounts and unregistered users

I have a web app in php mysql, I want to use one google drive account for my app.
Can I use my app's accounts instead of google users for privilages.
I read in SDK I can use service account to login without promting user, but I don't know how to share or give permissions files for custom users.
In api reference I found this:
"The user is not necessarily yet a Google user (e.g. if a file or folder is shared with an email address that does not yet have an associated Google account). Example: 1111459233037698895607".
How a custom user in my app should get a token for own privilages.
I am not exactly sure what you want to achieve here, but if you want to use your own permission system, you can't. You can, however, apply read/write/owner permissions to files to mirror your own permissions.
If I have totally got the wrong idea, please explain.