diff --git a/README.md b/README.md index 35a7a91af..c5479873c 100644 --- a/README.md +++ b/README.md @@ -62,4 +62,20 @@ git push upstream :review --force ``` The `main` branch only accepts commits through pull requests. -NB: Note that Radix will always use the `radixconfig.yml` as it is in `main` branch (unless changed in Radix UI). \ No newline at end of file +NB: Note that Radix will always use the `radixconfig.yml` as it is in `main` branch (unless changed in Radix UI). + +### Usage in GitHub codespaces + +Using the standard GitHub codespace image, you can easily start up the application by running +the same command as locally: +``` +docker-compose up +``` +in the terminal. When using GitHub codespaces you do not have to create the `.env` file since +environment variables are automatically set up for you at startup through repository settings. +Note that you need to have at least "collaborator" role in the repository in order to have +environment variables automatically set up. + +When you start up the docker containers, GitHub codespace will automatically make a link where +you can access the application in development mode (i.e. changes you do the code will automatically +be reflected in the application). diff --git a/backend/src/backend/auth/auth_helper.py b/backend/src/backend/auth/auth_helper.py index 041e4be4a..eecb7761b 100644 --- a/backend/src/backend/auth/auth_helper.py +++ b/backend/src/backend/auth/auth_helper.py @@ -1,3 +1,4 @@ +import os import base64 import time from typing import List, Optional @@ -33,11 +34,15 @@ async def _login_route(self, request: Request, redirect_url_after_login: Optiona for value in config.RESOURCE_SCOPES_DICT.values(): all_scopes_list.extend(value) + if "CODESPACE_NAME" in os.environ: + # Developer is using GitHub codespace, so we use the GitHub codespace provided URL instead of localhost. + redirect_uri = f"https://{os.environ['CODESPACE_NAME']}-8080.app.github.dev/api/auth-callback" + print("You are using GitHub codespace. Remember to allo app registration redirect URI {redirect_uri}") + else: + redirect_uri = str(request.url_for("_authorized_callback_route")) + cca = _create_msal_confidential_client_app(token_cache=None) - flow_dict = cca.initiate_auth_code_flow( - scopes=all_scopes_list, - redirect_uri=str(request.url_for("_authorized_callback_route")), - ) + flow_dict = cca.initiate_auth_code_flow(scopes=all_scopes_list, redirect_uri=redirect_uri) request.session["flow"] = flow_dict diff --git a/docker-compose.yml b/docker-compose.yml index dda1034d3..f6e4e1c56 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -31,6 +31,7 @@ services: - WEBVIZ_SMDA_RESOURCE_SCOPE - WEBVIZ_SMDA_SUBSCRIPTION_KEY - WEBVIZ_SUMO_ENV + - CODESPACE_NAME # Automatically set env. variable by GitHub codespace volumes: - ./backend/src:/home/appuser/backend/src