Skip to content

Commit

Permalink
HOTFIX : Fixes oauth section not found error when supplied through re…
Browse files Browse the repository at this point in the history
…mote_oauth
  • Loading branch information
kshitijrajsharma committed Mar 6, 2024
1 parent 0011b55 commit a1d7ac7
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,33 +411,36 @@ def get_oauth_credentials() -> tuple:
secret, client ID, and redirect URL.
"""

client_id = os.environ.get("OSM_CLIENT_ID") or config.get("OAUTH", "OSM_CLIENT_ID")
client_secret = os.environ.get("OSM_CLIENT_SECRET") or config.get(
"OAUTH", "OSM_CLIENT_SECRET"
)
login_redirect_uri = os.environ.get("LOGIN_REDIRECT_URI") or config.get(
"OAUTH", "LOGIN_REDIRECT_URI", fallback="http://127.0.0.1:8000/v1/auth/callback"
)
scope = os.environ.get("OSM_PERMISSION_SCOPE") or config.get(
"OAUTH", "OSM_PERMISSION_SCOPE", fallback="read_prefs"
)
# This block fetches OSM OAuth2 app credentials passed as
# environment variables as a JSON object, from AWS Secrets Manager or
# Azure Key Vault.
osm_url = os.environ.get("OSM_URL") or config.get(
"OAUTH", "OSM_URL", fallback="https://www.openstreetmap.org"
)
secret_key = os.environ.get("APP_SECRET_KEY") or config.get(
"OAUTH", "APP_SECRET_KEY"
)

# This block fetches OSM OAuth2 app credentials passed as
# environment variables as a JSON object, from AWS Secrets Manager or
# Azure Key Vault.
try:
oauth2_credentials = os.environ["REMOTE_OAUTH"]

except KeyError:
logger.debug("EnvVar: REMOTE_OAUTH not supplied; Falling back to other means")

client_id = os.environ.get("OSM_CLIENT_ID") or config.get(
"OAUTH", "OSM_CLIENT_ID"
)
client_secret = os.environ.get("OSM_CLIENT_SECRET") or config.get(
"OAUTH", "OSM_CLIENT_SECRET"
)
login_redirect_uri = os.environ.get("LOGIN_REDIRECT_URI") or config.get(
"OAUTH",
"LOGIN_REDIRECT_URI",
fallback="http://127.0.0.1:8000/v1/auth/callback",
)
scope = os.environ.get("OSM_PERMISSION_SCOPE") or config.get(
"OAUTH", "OSM_PERMISSION_SCOPE", fallback="read_prefs"
)

else:
import json

Expand All @@ -459,6 +462,5 @@ def get_oauth_credentials() -> tuple:

if None in oauth_cred:
raise ValueError("Oauth Credentials can't be loaded")
logging.error("Malformed OSM OAuth2 App credentials")

return oauth_cred

0 comments on commit a1d7ac7

Please sign in to comment.