Skip to content

Remove secrets #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 11 additions & 15 deletions examples/oauth2_simpletest.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
# SPDX-FileCopyrightText: 2020 Brent Rubell, written for Adafruit Industries
#
# SPDX-License-Identifier: Unlicense

from os import getenv
import ssl
import wifi
import socketpool
import adafruit_requests
from adafruit_oauth2 import OAuth2

# Add a secrets.py to your filesystem that has a dictionary called secrets with "ssid" and
# "password" keys with your WiFi credentials. DO NOT share that file or commit it into Git or other
# source control.
# pylint: disable=no-name-in-module,wrong-import-order
try:
from secrets import secrets
except ImportError:
print("Credentials and tokens are kept in secrets.py, please add them there!")
raise
# Get WiFi details and Google keys, ensure these are setup in settings.toml
ssid = getenv("CIRCUITPY_WIFI_SSID")
password = getenv("CIRCUITPY_WIFI_PASSWORD")
google_client_id = getenv("google_client_id")
google_client_secret = getenv("google_client_secret")

print("Connecting to %s" % secrets["ssid"])
wifi.radio.connect(secrets["ssid"], secrets["password"])
print("Connected to %s!" % secrets["ssid"])
print(f"Connecting to {ssid}")
wifi.radio.connect(ssid, password)
print(f"Connected to {ssid}")

pool = socketpool.SocketPool(wifi.radio)
requests = adafruit_requests.Session(pool, ssl.create_default_context())
Expand All @@ -29,9 +27,7 @@
scopes = ["email"]

# Initialize an OAuth2 object
google_auth = OAuth2(
requests, secrets["google_client_id"], secrets["google_client_secret"], scopes
)
google_auth = OAuth2(requests, google_client_id, google_client_secret, scopes)

# Request device and user codes
# https://developers.google.com/identity/protocols/oauth2/limited-input-device#step-1:-request-device-and-user-codes
Expand Down
18 changes: 6 additions & 12 deletions examples/oauth2_simpletest_cpython.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,24 @@
# SPDX-FileCopyrightText: 2020 Brent Rubell, written for Adafruit Industries
#
# SPDX-License-Identifier: Unlicense

from os import getenv
import socket
import ssl
import adafruit_requests
from adafruit_oauth2 import OAuth2

# Add a secrets.py to your filesystem that has a dictionary called secrets with Google
# application tokens. DO NOT share that file or commit it into Git or other
# source control.
# pylint: disable=no-name-in-module,wrong-import-order
try:
from secrets import secrets
except ImportError:
print("Credentials and tokens are kept in secrets.py, please add them there!")
raise
# Get Google keys, ensure these are setup in settings.toml
google_client_id = getenv("google_client_id")
google_client_secret = getenv("google_client_secret")

requests = adafruit_requests.Session(socket, ssl.create_default_context())

# Set scope(s) of access required by the API you're using
scopes = ["email"]

# Initialize an OAuth2 object
google_auth = OAuth2(
requests, secrets["google_client_id"], secrets["google_client_secret"], scopes
)
google_auth = OAuth2(requests, google_client_id, google_client_secret, scopes)

# Request device and user codes
# https://developers.google.com/identity/protocols/oauth2/limited-input-device#step-1:-request-device-and-user-codes
Expand Down
22 changes: 9 additions & 13 deletions examples/oauth2_simpletest_esp32spi.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# SPDX-FileCopyrightText: 2020 Brent Rubell, written for Adafruit Industries
#
# SPDX-License-Identifier: Unlicense

from os import getenv
import board
import busio
from digitalio import DigitalInOut
Expand All @@ -10,15 +12,11 @@
import adafruit_requests
from adafruit_oauth2 import OAuth2

# Add a secrets.py to your filesystem that has a dictionary called secrets with "ssid" and
# "password" keys with your WiFi credentials. DO NOT share that file or commit it into Git or other
# source control.
# pylint: disable=no-name-in-module,wrong-import-order
try:
from secrets import secrets
except ImportError:
print("Credentials and tokens are kept in secrets.py, please add them there!")
raise
# Get WiFi details and Google keys, ensure these are setup in settings.toml
ssid = getenv("CIRCUITPY_WIFI_SSID")
password = getenv("CIRCUITPY_WIFI_PASSWORD")
google_client_id = getenv("google_client_id")
google_client_secret = getenv("google_client_secret")

esp32_cs = DigitalInOut(board.ESP_CS)
esp32_ready = DigitalInOut(board.ESP_BUSY)
Expand All @@ -30,7 +28,7 @@
print("Connecting to AP...")
while not esp.is_connected:
try:
esp.connect_AP(secrets["ssid"], secrets["password"])
esp.connect_AP(ssid, password)
except RuntimeError as e:
print("could not connect to AP, retrying: ", e)
continue
Expand All @@ -45,9 +43,7 @@
scopes = ["email"]

# Initialize an OAuth2 object
google_auth = OAuth2(
requests, secrets["google_client_id"], secrets["google_client_secret"], scopes
)
google_auth = OAuth2(requests, google_client_id, google_client_secret, scopes)

# Request device and user codes
# https://developers.google.com/identity/protocols/oauth2/limited-input-device#step-1:-request-device-and-user-codes
Expand Down