Skip to content

Commit

Permalink
rename JWT_SECRET_KEY to JHUB_APP_JWT_SECRET_KEY
Browse files Browse the repository at this point in the history
  • Loading branch information
aktech committed Jan 7, 2024
1 parent a5df67d commit 6b02254
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pip install -e .
Set the following environment variable:

```bash
export JWT_SECRET_KEY=$(openssl rand -hex 32)
export JHUB_APP_JWT_SECRET_KEY=$(openssl rand -hex 32)
```


Expand Down
2 changes: 1 addition & 1 deletion jhub_apps/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def install_jhub_apps(c, spawner_to_subclass):
"JHUB_APP_TITLE": c.JAppsConfig.app_title,
"JHUB_APP_ICON": c.JAppsConfig.app_icon,
"JHUB_JUPYTERHUB_CONFIG": c.JAppsConfig.jupyterhub_config_path,
"JWT_SECRET_KEY": _create_token_for_service(),
"JHUB_APP_JWT_SECRET_KEY": _create_token_for_service(),

# Temp environment variables for Nebari Deployment
"PROXY_API_SERVICE_PORT": "*",
Expand Down
6 changes: 3 additions & 3 deletions jhub_apps/service/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def create_access_token(data: dict, expires_delta: typing.Optional[timedelta] =
else:
expire = datetime.utcnow() + timedelta(minutes=15)
to_encode.update({"exp": expire})
secret_key = os.environ["JWT_SECRET_KEY"]
secret_key = os.environ["JHUB_APP_JWT_SECRET_KEY"]
logger.info(f"JWT secret key: {secret_key}")
encoded_jwt = jwt.encode(to_encode, secret_key, algorithm="HS256")
return encoded_jwt
Expand All @@ -33,12 +33,12 @@ def get_jhub_token_from_jwt_token(token):
headers={"WWW-Authenticate": "Bearer"},
)
try:
payload = jwt.decode(token, os.environ["JWT_SECRET_KEY"], algorithms=["HS256"])
payload = jwt.decode(token, os.environ["JHUB_APP_JWT_SECRET_KEY"], algorithms=["HS256"])
access_token_data: dict = payload.get("sub")
if access_token_data is None:
raise credentials_exception
except jwt.PyJWTError as e:
logger.warning(f"Authentication failed for token: {token}, JWT_SECRET_KEY: {os.environ['JWT_SECRET_KEY']}")
logger.warning(f"Authentication failed for token: {token}, JWT_SECRET_KEY: {os.environ['JHUB_APP_JWT_SECRET_KEY']}")
logger.exception(e)
raise credentials_exception
logger.info("Fetched access token from JWT Token")
Expand Down

0 comments on commit 6b02254

Please sign in to comment.