-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from nebari-dev/misc-fixes
Misc fixes for Nebari Integration
- Loading branch information
Showing
21 changed files
with
178 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,5 +19,6 @@ dependencies: | |
- streamlit | ||
- tornado>=5.1 | ||
- traitlets | ||
- python-slugify | ||
- pip: | ||
- gradio |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,44 @@ | ||
import logging | ||
import os | ||
import typing | ||
from datetime import timedelta, datetime | ||
|
||
import jwt | ||
from fastapi import HTTPException, status | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def create_access_token(data: dict, expires_delta: typing.Optional[timedelta] = None): | ||
logger.info("Creating access token") | ||
to_encode = data.copy() | ||
if expires_delta: | ||
expire = datetime.utcnow() + expires_delta | ||
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"] | ||
encoded_jwt = jwt.encode(to_encode, secret_key, algorithm="HS256") | ||
return encoded_jwt | ||
|
||
|
||
def get_jhub_token_from_jwt_token(token): | ||
logger.info("Trying to get JHub Apps token from JWT Token") | ||
credentials_exception = HTTPException( | ||
status_code=status.HTTP_401_UNAUTHORIZED, | ||
detail="Could not validate credentials", | ||
detail={ | ||
"msg": "Could not validate credentials" | ||
}, | ||
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: | ||
except jwt.PyJWTError as e: | ||
logger.warning("Authentication failed for token") | ||
logger.exception(e) | ||
raise credentials_exception | ||
logger.info("Fetched access token from JWT Token") | ||
return access_token_data["access_token"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.