-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also update CONTRIBUTING.md to reflect adjusted Vite env var
- Loading branch information
1 parent
328105b
commit 19fcd71
Showing
12 changed files
with
201 additions
and
25 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,2 +1,3 @@ | ||
export const BACKEND_URL = | ||
import.meta.env.VITE_APP_BACKEND_URL || "http://127.0.0.1:8080"; | ||
export const GOOGLE_CLIENT_ID = import.meta.env.VITE_GOOGLE_CLIENT_ID || ""; |
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 |
---|---|---|
|
@@ -85,8 +85,8 @@ async def get_user_from_github_token(self, token: str, email: str) -> User: | |
async def delete_github_token(self, github_id: str) -> None: | ||
await self._delete_item(await self._get_oauth_key(github_auth_key(github_id), throw_if_missing=True)) | ||
|
||
async def get_user_from_google_token(self, token: str, email: str) -> User | None: | ||
auth_key = google_auth_key(token) | ||
async def get_user_from_google_token(self, email: str) -> User: | ||
auth_key = google_auth_key(email) | ||
user = await self._get_user_from_auth_key(auth_key) | ||
if user is not None: | ||
return user | ||
|
@@ -139,7 +139,7 @@ async def test_adhoc() -> None: | |
|
||
await crud.get_user_from_github_token(token="gh_token_example", email="[email protected]") | ||
|
||
await crud.get_user_from_google_token(token="google_token_example", email="[email protected]") | ||
await crud.get_user_from_google_token(email="[email protected]") | ||
|
||
|
||
if __name__ == "__main__": | ||
|
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
"""Defines the API endpoint for creating, deleting and updating user information.""" | ||
|
||
import logging | ||
from typing import Annotated | ||
|
||
import aiohttp | ||
from fastapi import APIRouter, Depends, HTTPException, status | ||
from pydantic.main import BaseModel | ||
|
||
from store.app.db import Crud | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
google_auth_router = APIRouter() | ||
|
||
|
||
class GoogleLogin(BaseModel): | ||
token: str | ||
|
||
|
||
async def get_google_user_email(token: str) -> str: | ||
async with aiohttp.ClientSession() as session: | ||
response = await session.get( | ||
"https://www.googleapis.com/oauth2/v3/userinfo", | ||
params={"access_token": token}, | ||
) | ||
if response.status != 200: | ||
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail="Invalid Google token") | ||
return (await response.json())["email"] | ||
|
||
|
||
class AuthResponse(BaseModel): | ||
api_key: str | ||
|
||
|
||
@google_auth_router.post("/login") | ||
async def google_login_endpoint( | ||
data: GoogleLogin, | ||
crud: Annotated[Crud, Depends(Crud.get)], | ||
) -> AuthResponse: | ||
email = await get_google_user_email(data.token) | ||
user = await crud.get_user_from_google_token(email) | ||
|
||
api_key = await crud.add_api_key( | ||
user_id=user.id, | ||
source="oauth", | ||
permissions="full", # OAuth tokens have full permissions. | ||
) | ||
|
||
return AuthResponse(api_key=api_key.id) |
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