Skip to content

Commit

Permalink
remove front_oauth_client
Browse files Browse the repository at this point in the history
  • Loading branch information
devincowan committed Nov 15, 2023
1 parent a0008ba commit 0c33fd2
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 35 deletions.
30 changes: 0 additions & 30 deletions app/api/subsetter/app/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,35 +30,6 @@ async def get_id_email(self, token: str) -> Tuple[str, str]:
return data["sub"], data["email"]


class FrontOAuth2(CUAHSIOAuth2):
# https://github.com/frankie567/httpx-oauth/blob/v0.13.0/httpx_oauth/oauth2.py#L131
async def get_access_token(self, code: str, redirect_uri: str, code_verifier: Optional[str] = None):
async with self.get_httpx_client() as client:
data = {
"grant_type": "authorization_code",
"code": code,
"redirect_uri": f"{os.getenv('VITE_APP_URL')}/auth-redirect",
"client_id": self.client_id,
"client_secret": self.client_secret,
}

if code_verifier:
data.update({"code_verifier": code_verifier})

response = await client.post(
self.access_token_endpoint,
data=data,
headers=self.request_headers,
)

data = cast(Dict[str, Any], response.json())

if response.status_code >= 400:
raise GetAccessTokenError(data)

return OAuth2Token(data)


client_params = dict(
client_id=os.getenv("OAUTH2_CLIENT_ID"),
client_secret=os.getenv("OAUTH2_CLIENT_SECRET"),
Expand All @@ -69,7 +40,6 @@ async def get_access_token(self, code: str, redirect_uri: str, code_verifier: Op
base_scopes=["openid"],
)

front_oauth_client = FrontOAuth2(**client_params)
cuahsi_oauth_client = CUAHSIOAuth2(**client_params)


Expand Down
8 changes: 4 additions & 4 deletions app/api/subsetter/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from subsetter.app.routers.argo import router as argo_router
from subsetter.app.routers.storage import router as storage_router
from subsetter.app.schemas import UserRead, UserUpdate
from subsetter.app.users import SECRET, auth_backend, cookie_backend, cuahsi_oauth_client, front_oauth_client, fastapi_users
from subsetter.app.users import SECRET, auth_backend, cookie_backend, cuahsi_oauth_client, fastapi_users
from subsetter.config import get_settings

# TODO: get oauth working with swagger/redoc
Expand All @@ -21,8 +21,8 @@
# https://github.com/tiangolo/fastapi/pull/499
swagger_params = {
"withCredentials": True,
"oauth2RedirectUrl": front_oauth_client.authorize_endpoint,
"swagger_ui_client_id": front_oauth_client.client_id,
"oauth2RedirectUrl": cuahsi_oauth_client.authorize_endpoint,
"swagger_ui_client_id": cuahsi_oauth_client.client_id,
}

app = FastAPI(servers=[{"url": os.environ['VITE_APP_API_URL']}], swagger_ui_parameters=swagger_params)
Expand Down Expand Up @@ -65,7 +65,7 @@

app.include_router(
fastapi_users.get_oauth_router(
front_oauth_client,
cuahsi_oauth_client,
cookie_backend,
SECRET,
redirect_url=get_settings().oauth2_cookie_redirect_url
Expand Down
3 changes: 2 additions & 1 deletion app/env.template
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ ALLOW_ORIGINS='["http://localhost:*"]'
VITE_APP_NAME=subsetter
VITE_APP_API_HOST=localhost
VITE_APP_API_URL=https://${VITE_APP_API_HOST}/api
OAUTH2_REDIRECT_URl=${VITE_APP_API_URL}/auth/cuahsi/callback
OAUTH2_REDIRECT_URl=${VITE_APP_API_URL}/auth/cuahsi/callback
OAUTH2_COOKIE_REDIRECT_URl=${VITE_APP_URL}/auth-redirect

0 comments on commit 0c33fd2

Please sign in to comment.