micropython-firebase-auth
Firebase implementation based on REST API, based on micropython-firebase-realtime-database from ckoever.
Installation
You can use uPip to install library from PyPi
import upip
upip.install("micropython-firebase-auth")
or you can just upload firebase_auth/firebase_auth.py to your microcontroller:
python pyboard.py -d PORT -f cp firebase_auth.py :
Commands that are implemented
- sign_in
- sign_out
- sign_up
Required modules
ujson, urequests, time, sys
Connect to Wifi
import time
import network
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
if not wlan.isconnected():
wlan.connect("ssid", "pass")
print("Waiting for Wi-Fi connection", end="...")
while not wlan.isconnected():
print(".", end="")
time.sleep(1)
print()
Create a FirebaseAuth instance
from firebase_auth import FirebaseAuth
auth = FirebaseAuth("API_KEY")
The API key is required, read about it here
or you can find it at Project Settings > General in your project's console
Functions
sign_in
auth.sign_in(email, password)
Authenticate a user with email and password
sign_up
auth.sign_up(email=None, password=None)
Registers an account with the given email and password
-
leave
emailandpasswordempty to sign in anonymouslyauth.sign_up(None, None) # Sign in as guest
Example:
auth.sign_up("email", "password")
print("Hello, " + auth.user.display_name)
sign_out
auth.sign_out()
Clears authentication session and stored user data
Attributes
user
auth.user: dict()
Returns the user data for the currently authenticated user
session
auth.session: AuthSession
The AuthSession object used to handle requests to the backend
AuthSession
request
session.request(method, endpoint, data=None, method=None, **kwargs)
Make a request to an auth endpoint requiring an idToken (the accessToken) (if method is not None, else an endpoint that returns tokens)
access_token
session.access_token
Gets the access token for use within other Firebase services such as RTDB, Firestore, etc.
AuthSession.load_credentials
AuthSession.load_credentials()
Reads a stored version of session credentials from a credentials.json file
AuthSession.save_credentials
AuthSession.save_credentials(creds)
Stores a session credentials object into credentials.json file
Example:
# Storing data on system before going to sleep for 10s
import machine
creds = auth.session.credentials
AuthSession.save_credentials(creds)
machine.deepsleep(10000)
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file micropython-firebase-auth-1.0.6.tar.gz.
File metadata
- Download URL: micropython-firebase-auth-1.0.6.tar.gz
- Upload date:
- Size: 5.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.25.1 requests-toolbelt/0.9.1 urllib3/1.26.4 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c3f2787e38d193580e759f31044aa1dfc53a372ef71a38ce31ec3993839f6aa0
|
|
| MD5 |
8be38c1278db9b0a6686895310d3f7ba
|
|
| BLAKE2b-256 |
3f4d101b6d6b0713c314bd02a721e59cd164bf45dec2cb94ff0ea70ede7821bc
|