Is it possible to mount my Google Drive in Colab and authenticate to Google with GSpread in one step? - google-colaboratory

I am trying to make in one step this two actions in my Google Colab: mount my drive and authorize with GSpread to use Google Sheets which are also in my drive.
I don't understand why it is necessary to authorize the access to my drive twice but I haven't found any other way to do it simpler
This is my approach to the problem but this makes my authorize twice
from google.colab import drive
import pandas as pd
import numpy as np
import requests
import json
import matplotlib.pyplot as plt
import numpy as np
from google.colab import auth
import gspread
from google.auth import default
drive.mount('/content/gdrive')
#autenticating to google
auth.authenticate_user()
creds, _ = default()
gc = gspread.authorize(creds)

Related

How can ı connect google cloud storage from Colab with different mail

I connect google cloud storage from Colab with this code
from google.colab import auth
auth.authenticate_user()
When I use it in this way, the mail I use Colab and the GCP mail must be the same. But I am connecting via a different email. And I am getting error like this.
How can I connect to Cloud Storage with Colab session not having same mail as GCP?

How to import exported auth data into Firebase emulators?

Can Firebase emulators import "exported Firebase auth data"?
Firebase emulators imports exported Firestore data, which is exported to gCloud then downloaded to my machine. The emulators can also import the auth data it exports, but I can't figure out how to import the data I've exported from Firebase.
firebaser here
There is currently no way to import the auth:export format back into the emulator in bulk. At the moment it only can read its own export format (which allows it to persist user accounts between runs of the emulator suite).
This is a feature we'd like to add to the emulator at some point, but for the moment you'd have to build it yourself by processing the export.

How to view and edit mounted gdrive files in gspread format without authentication on google colab?

I have mounted the google drive using the in-built function on google colab.
According to google, this means that the files should act as if they were accessible and editable from the local directory.
However, file = open("file path", "r+") leads to "AttributeError: module 'gspread' has no attribute 'open'".
How do you open and edit these gspread files without further authentication beyond the automatic authentication of mounting gspread (i.e, not using the gc.open_by_url() approach)?

AWS Cognito ERROR Authenticator - No userPool

I'm trying to set up User Sign-in with AWS Cognito on React Native. I've followed these instructions:
http://docs.aws.amazon.com/aws-mobile/latest/developerguide/react-native-add-user-sign-in.html
I'm able to post analytics about the app and see a chart with data on AWS Pinpoint, but Cognito does not seem to be working
Things I've tried:
redownloading aws-exports.js
awsmobile pull
I figured it out. You have to configure Amplify before calling withAuthenticator(App). I just put it up at the top with the imports. It would have been nice if the tutorial mentioned this...
import Amplify from 'aws-amplify-react-native';
import aws_exports from './aws-exports';
import { withAuthenticator, API } from 'aws-amplify-react-native';
Amplify.configure(aws_exports);

How to selenium test a website that uses Google OAuth

I'm building a website that uses Google OAuth to authenticate users and to perform actions in Google (sending emails, creating calendar events, etc.) on the user's behalf.
I want to use selenium to test that the website works as I expect. This includes website specific stuff (e.g. pressing this button causes this entry in the DB), but also Google specific stuff (e.g. pressing this button causes this exact email to be sent).
How do I reasonably test this using selenium? How can I log in automatically? Is there any way at all for me to test that user X can't perform these certain actions but user Y can?
Currently I save a JSONified user record (with Google credentials) in a file and load that file when the tests set up. If the file can't be found then it boots up a browser window and sleeps until I've manually signed in using that browser window. This feels hacky and fragile. It also prevents me from having CI testing because the user record file is only available on my machine.
You could create different accounts allowing different privileges. Then simply automate the login just like a real user would do.
This is a Python example to login to StackOverflow through GMail:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Firefox()
wait = WebDriverWait(driver, 10)
driver.get("https://stackoverflow.com/users/login")
# Click GMail login
driver.find_element_by_xpath("//span[.='Google']").click()
# type email
wait.until(EC.presence_of_element_located((By.ID, "Email"))).send_keys('...')
# click next
wait.until(EC.presence_of_element_located((By.ID, "next"))).click()
# type password
wait.until(EC.presence_of_element_located((By.ID, "Passwd"))).send_keys('...')
# click signin
wait.until(EC.presence_of_element_located((By.ID, "signIn"))).click()
# wait for the end of the redirection
wait.until(EC.presence_of_element_located((By.ID, "nav-questions")))