[GCP] Try a sample to authenticate users with Firebase

I whipped the old body and tried a sample that uses Firebase for user authentication. I've followed the Google Application Engine sample, so it's a memo. https://cloud.google.com/appengine/docs/standard/python3/building-app?hl=ja

The environment is ubuntu 18.04 of WSL1 (Windows Subsystem Linux).

Follow Python3 Standard environment application construction

First, a memo of the method for executing the sample. After that, a memorandum at the time of execution.

Preparing for Google Cloud

Switch accounts properly.

$ gcloud config set account [email protected]
$ gcloud config configurations list

Prepare the project.

$ gcloud projects list
$ gcloud projects create [YOUR_PROJECT_ID] --set-as-default
$ gcloud app create --project=[YOUR_PROJECT_ID]
$ gcloud projects describe [YOUR_PROJECT_ID]

Source code

git clone.

https://github.com/GoogleCloudPlatform/python-docs-samples

Use python-docs-samples/appengine/standard_python3/building-an-app /

Testing in a local environment

When running locally


$ python3 -m venv env
$ source env/bin/activate
(env)> pip install  -r requirements.txt

After

$ python3 main.py

It works normally. Return from the virtual environment with ``` deactivate``.

Deploy

Deploy.

$ gloucd app deploy

I made it because there is no .gcloudignore. If the files under ./env created at the time of the operation check earlier remain, all local files will be uploaded together at the time of deploy. So, as a quick and reliable way, I erased everything with `rm -rf ./env/``` and then `gcloud app deploy```. ^^;)

$ gloud app browse

View in your browser. You can also see the log. If the service name is default (unless you have changed the settings in app.yaml)

$ gcloud app logs tail -s default

Details

building-an-app-1

It worked normally. There was script.js in ./static/. I can understand flask and routing somehow. Do you put it in static? There is a setting in app.yaml to upload this.

building-an-app-2

pip install -r reqirements.txt gives an error ``` error: invalid command'bdist_wheel'` ``. So I dealt with it below, but I wonder if I skipped it after all.

pip install scrapy 
pip3 install wheel
pip3 install tornado

The deployment was fine. I don't know how to use Datasotre on GCP.

building-an-app-3

It's finally time to use Firebase.

Prepare Firebase. I was told as follows, but I'm not sure. I'm worried about the price, but I'm surprised that if you turn off firebase, his GCP project will also disappear.

Things to keep in mind when adding Firebase to your Google Cloud project --Google Cloud and Firebase billing for your project will be shared --Details: Because billing is enabled for your project, the Firebase Blaze plan will be applied and your Firebase items will be included in your Cloud billing every cycle. --User roles and permissions in the project are shared --Details Deleting a Firebase project also deletes the Google Cloud project and deletes all resources contained in the project. This operation is irreversible. However, many Firebase services can be manually disabled.

For more information, do I have to log in and read it carefully? I followed the instructions for the time being. https://console.firebase.google.com/

(1) Creating a Firebase project

--Created a project (though it wouldn't be a repetitive task) --Added mail, password, and Gmail in SIGN-IN METHOD of Authentication. --Added the domain name that was previously tested with gcloud app browse in the authenticated domain. PROJECT_ID. REGION_ID.r.appspot.com PROJECT_ID

(2) Creating an app

In the overview, select Web under "Add app". When registering the app, you will be asked for a name, so if you put it in properly, a code to paste it was generated.

<!-- The core Firebase JS SDK is always required and must be listed first -->
<script src="https://www.gstatic.com/firebasejs/8.2.1/firebase-app.js"></script>

<!-- TODO: Add SDKs for Firebase products that you want to use
     https://firebase.google.com/docs/web/setup#available-libraries -->
<script src="https://www.gstatic.com/firebasejs/8.2.1/firebase-analytics.js"></script>

<script>
  // Your web app's Firebase configuration
  // For Firebase JS SDK v7.20.0 and later, measurementId is optional
  var firebaseConfig = {
    apiKey: "",
    authDomain: "PROJECT_ID.firebaseapp.com",
    projectId: "PROJECT_ID",
    storageBucket: "PROJECT_ID.appspot.com",
    messagingSenderId: "691267092448",
    appId: "",
    measurementId: ""
  };
  // Initialize Firebase
  firebase.initializeApp(firebaseConfig);
  firebase.analytics();
</script>

I was advised to paste it at the bottom of the tag, so I did. However, when I actually run it and connect with a browser, I get angry to initialize Firebase.

If the URL is registered

  <!-- Initialize Firebase -->
  <script src="/__/firebase/init.js"></script>

It seemed that it should be done, but it didn't work. After all, I pasted it into the header of templates/index.html and it worked.

In the operation check, I was able to register my e-mail address and password normally. I don't know where the registration data is. Is it somewhere in the Firebase project? .. ..

For the time being, my memo

I learned later. If you read it carefully, it says various things, but for the time being

--Firebase rates. There is also a free tier instead of a pay-as-you-go system. There is a restriction that the project cannot be extended on Google Cloud Platform. You should consider whether you can use it in the free frame. --Check where the user data is. Is it Google Datastore? ――Assuming that you manage users with Firebase, I think it can be used from multiple apps. I have to study how to separate the user authentication part from the WEB page part. .. .. ――If you manage users with Firebase and put user data in Cloud Storage, what kind of configuration would you like? I also have to study DB. .. The destination is long, hey. ..

Summary

For the time being, I wrote a memo when I ran Google's tutorial. It was around this time that I wanted to make sure that I could use it properly and provide some services. (2021/01/03)

Recommended Posts

[GCP] Try a sample to authenticate users with Firebase
A sample to try Factorization Machines quickly with fastFM
Rails users try to create a simple blog engine with Django
Try to draw a life curve with python
Try to make a "cryptanalysis" cipher with Python
Try to make a dihedral group with Python
AWS Step Functions to learn with a sample
Try to make a command standby tool with python
Try to dynamically create a Checkbutton with Python's Tkinter
Try to factorial with recursion
Try programming with a shell!
Try to select a language
Try to build a deep learning / neural network with scratch
Try to bring up a subwindow with PyQt5 and Python
Try to draw a Bezier curve
Try to operate Facebook with Python
Try to create a python environment with Visual Studio Code & WSL
Try to extract a character string from an image with Python3
Try to profile with ONNX Runtime
Try to make a web service-like guy with 3D markup language
Try to output audio with M5STACK
Try adding a wall to your IFC file with IfcOpenShell python
Try to create a Qiita article with REST API [Environmental preparation]
How to authenticate with Django Part 2
How to authenticate with Django Part 3
[Cloudian # 3] Try to create a new object storage bucket with Python (boto3)
Gist repository to use when you want to try a little with ansible
Try to make a capture software with as high accuracy as possible with python (2)
Try to solve the traveling salesman problem with a genetic algorithm (Theory)
Try to solve a set problem of high school math with Python
Try to reproduce color film with Python
Try logging in to qiita with Python
How to add a package with PyCharm
Sample to comprehensively try OpenCV Optical Flow
Try to predict cherry blossoms with xgboost
Try converting to tidy data with pandas
Quickly try to visualize datasets with pandas
Try HTML scraping with a Python library
How to use CUT command (with sample)
First YDK to try with Cisco IOS-XE
Sample program to display video with PyQt
Try drawing a map with python + cartopy 0.18.0
Try to generate an image with aliasing
Try TensorFlow RNN with a basic model
Sample to convert image to Wavelet with Python
Try to solve the traveling salesman problem with a genetic algorithm (Python code)
Try to beautify with Talking Head Anime from a Single Image [python preparation]
Try to solve the traveling salesman problem with a genetic algorithm (execution result)
Try to create a Todo management site using WebSocket with Django (Swamp Dragon)
WEB scraping with python and try to make a word cloud from reviews
I tried to create a model with the sample of Amazon SageMaker Autopilot
Try to make your own AWS-SDK with bash
How to create sample CSV data with hypothesis
Try to solve the fizzbuzz problem with Keras
How to read a CSV file with Python 2/3
How to use GCP trace with open Telemetry
Send a message to LINE with Python (LINE Notify)
How to send a message to LINE with curl
A memorandum to make WebDAV only with nginx
Try to calculate a statistical problem in Python
Try to aggregate doujin music data with pandas